1 /* init.js - initialization and configuration of Popcorn and the widgets |
1 /* init.js - initialization and configuration of Popcorn and the widgets |
2 exemple json configuration: |
2 exemple json configuration: |
3 |
3 |
4 */ |
4 */ |
5 |
5 |
6 IriSP.configurePopcorn = function (layoutManager, options) { |
6 define(["IriSP"], function() { |
7 var pop; |
7 IriSP.configurePopcorn = function (layoutManager, options) { |
8 var containerDiv = layoutManager.createDiv(); |
8 var pop; |
9 |
9 var containerDiv = layoutManager.createDiv(); |
10 switch(options.type) { |
10 |
11 /* |
11 switch(options.type) { |
12 todo : dynamically create the div/video tag which |
12 /* |
13 will contain the video. |
13 todo : dynamically create the div/video tag which |
14 */ |
14 will contain the video. |
15 case "html5": |
15 */ |
16 var tmpId = Popcorn.guid("video"); |
16 case "html5": |
17 IriSP.jQuery("#" + containerDiv).append("<video src='" + options.file + "' id='" + tmpId + "'></video>"); |
17 var tmpId = Popcorn.guid("video"); |
18 pop = Popcorn("#" + tmpId).mediafragment({start : 0}); |
18 IriSP.jQuery("#" + containerDiv).append("<video src='" + options.file + "' id='" + tmpId + "'></video>"); |
19 break; |
19 pop = Popcorn("#" + tmpId).mediafragment({start : 0}); |
|
20 break; |
|
21 |
|
22 case "jwplayer": |
|
23 var opts = IriSP.jQuery.extend({}, options); |
|
24 delete opts.container; |
|
25 pop = Popcorn.jwplayer("#" + containerDiv, "", opts).mediafragment({start : 0}); |
|
26 break; |
20 |
27 |
21 case "jwplayer": |
28 case "youtube": |
22 var opts = IriSP.jQuery.extend({}, options); |
29 var opts = IriSP.jQuery.extend({}, options); |
23 delete opts.container; |
30 delete opts.container; |
24 pop = Popcorn.jwplayer("#" + containerDiv, "", opts).mediafragment({start : 0}); |
31 opts.controls = 0; |
25 break; |
32 opts.autostart = false; |
|
33 templ = "width: {{width}}px; height: {{height}}px;"; |
|
34 var str = Mustache.to_html(templ, {width: opts.width, height: opts.height}); |
|
35 // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div. |
|
36 IriSP.jQuery("#" + containerDiv).attr("style", str); |
|
37 |
|
38 pop = Popcorn.youtube("#" + containerDiv, opts.video, opts).mediafragment({start : 0}); |
|
39 break; |
|
40 |
|
41 default: |
|
42 pop = undefined; |
|
43 }; |
26 |
44 |
27 case "youtube": |
45 return pop; |
28 var opts = IriSP.jQuery.extend({}, options); |
|
29 delete opts.container; |
|
30 opts.controls = 0; |
|
31 opts.autostart = false; |
|
32 templ = "width: {{width}}px; height: {{height}}px;"; |
|
33 var str = Mustache.to_html(templ, {width: opts.width, height: opts.height}); |
|
34 // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div. |
|
35 IriSP.jQuery("#" + containerDiv).attr("style", str); |
|
36 |
|
37 pop = Popcorn.youtube("#" + containerDiv, opts.video, opts).mediafragment({start : 0}); |
|
38 break; |
|
39 |
|
40 default: |
|
41 pop = undefined; |
|
42 }; |
|
43 |
|
44 return pop; |
|
45 }; |
|
46 |
|
47 IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) { |
|
48 |
|
49 var dt = new IriSP.DataLoader(); |
|
50 var serialFactory = new IriSP.SerializerFactory(dt); |
|
51 |
|
52 var params = {width: guiOptions.width, height: guiOptions.height}; |
|
53 |
|
54 var ret_widgets = []; |
|
55 var index; |
|
56 |
|
57 for (index = 0; index < guiOptions.widgets.length; index++) { |
|
58 var widgetConfig = guiOptions.widgets[index]; |
|
59 var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig); |
|
60 ret_widgets.push(widget); |
|
61 |
|
62 }; |
46 }; |
63 |
47 |
64 return ret_widgets; |
48 IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) { |
65 }; |
|
66 |
49 |
67 IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) { |
50 var dt = new IriSP.DataLoader(); |
68 var container = layoutManager.createDiv(); |
51 var serialFactory = new IriSP.SerializerFactory(dt); |
69 var arr = IriSP.jQuery.extend({}, widgetConfig); |
|
70 arr.container = container; |
|
71 |
52 |
72 var serializer = serialFactory.getSerializer(widgetConfig.metadata); |
53 var params = {width: guiOptions.width, height: guiOptions.height}; |
|
54 |
|
55 var ret_widgets = []; |
|
56 var index; |
73 |
57 |
74 if (typeof serializer == "undefined") |
58 for (index = 0; index < guiOptions.widgets.length; index++) { |
75 debugger; |
59 var widgetConfig = guiOptions.widgets[index]; |
76 |
60 var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig); |
77 // instantiate the object passed as a string |
61 ret_widgets.push(widget); |
78 var widget = new IriSP[widgetConfig.type](popcornInstance, arr, serializer); |
62 |
79 |
63 }; |
80 if (widgetConfig.hasOwnProperty("requires")) { |
64 |
81 // also create the widgets this one depends on. |
65 return ret_widgets; |
82 // the dependency widget is available in the parent widget context as |
66 }; |
83 // this.WidgetName (for instance, this.TipWidget); |
67 |
|
68 IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) { |
|
69 var container = layoutManager.createDiv(); |
|
70 var arr = IriSP.jQuery.extend({}, widgetConfig); |
|
71 arr.container = container; |
84 |
72 |
85 var i = 0; |
73 var serializer = serialFactory.getSerializer(widgetConfig.metadata); |
86 for(i = 0; i < widgetConfig.requires.length; i++) { |
74 |
87 var widgetName = widgetConfig.requires[i]["type"]; |
75 if (typeof serializer == "undefined") |
88 widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig.requires[i]); |
76 debugger; |
89 } |
77 |
90 } |
78 // instantiate the object passed as a string |
91 |
79 var widget = new IriSP[widgetConfig.type](popcornInstance, arr, serializer); |
92 serializer.sync(IriSP.wrap(widget, function() { this.draw(); })); |
80 |
93 return widget; |
81 if (widgetConfig.hasOwnProperty("requires")) { |
94 }; |
82 // also create the widgets this one depends on. |
|
83 // the dependency widget is available in the parent widget context as |
|
84 // this.WidgetName (for instance, this.TipWidget); |
|
85 |
|
86 var i = 0; |
|
87 for(i = 0; i < widgetConfig.requires.length; i++) { |
|
88 var widgetName = widgetConfig.requires[i]["type"]; |
|
89 widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig.requires[i]); |
|
90 } |
|
91 } |
|
92 |
|
93 serializer.sync(IriSP.wrap(widget, function() { this.draw(); })); |
|
94 return widget; |
|
95 }; |
|
96 }); |