| author | veltr |
| Tue, 17 Apr 2012 15:03:40 +0200 | |
| branch | new-model |
| changeset 866 | 3bf7aa8216e5 |
| parent 842 | 4ae2247a59f4 |
| child 868 | a525cc2214e7 |
| permissions | -rw-r--r-- |
| 123 | 1 |
/* init.js - initialization and configuration of Popcorn and the widgets |
2 |
exemple json configuration: |
|
3 |
||
| 531 | 4 |
*/ |
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
5 |
|
| 531 | 6 |
/** do some magic to configure popcorn according to the options object passed. |
| 866 | 7 |
Works for html5, jwplayer and youtube videos |
8 |
*/ |
|
9 |
IriSP.configurePopcorn = function(layoutManager, options) { |
|
| 123 | 10 |
var pop; |
| 866 | 11 |
var ret = layoutManager.createDiv(); |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
12 |
var containerDiv = ret[0]; |
|
767
645d06da3d5b
automatically insert 1px of margin between the video and the first widget.
hamidouk
parents:
743
diff
changeset
|
13 |
var spacerDiv = ret[1]; |
| 866 | 14 |
|
15 |
/* insert one pixel of margin between the video and the first widget, using the |
|
16 |
spacer. |
|
17 |
*/ |
|
|
767
645d06da3d5b
automatically insert 1px of margin between the video and the first widget.
hamidouk
parents:
743
diff
changeset
|
18 |
IriSP.jQuery("#" + spacerDiv).css("height", "1px"); |
| 866 | 19 |
|
| 127 | 20 |
switch(options.type) { |
| 866 | 21 |
/* |
22 |
todo : dynamically create the div/video tag which |
|
23 |
will contain the video. |
|
24 |
*/ |
|
25 |
case "html5": |
|
26 |
var tmpId = Popcorn.guid("video"); |
|
27 |
IriSP.jQuery("#" + containerDiv).append("<video src='" + options.video + "' id='" + tmpId + "'></video>"); |
|
|
402
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
28 |
|
| 866 | 29 |
if(options.hasOwnProperty("width")) |
30 |
IriSP.jQuery("#" + containerDiv).css("width", options.width); |
|
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
31 |
|
| 866 | 32 |
if(options.hasOwnProperty("height")) |
33 |
IriSP.jQuery("#" + containerDiv).css("height", options.height); |
|
34 |
pop = Popcorn("#" + tmpId); |
|
35 |
break; |
|
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
36 |
|
| 866 | 37 |
case "jwplayer": |
38 |
var opts = IriSP.jQuery.extend({}, options); |
|
39 |
delete opts.container; |
|
40 |
delete opts.type; |
|
41 |
opts.file = opts.video; |
|
42 |
delete opts.video; |
|
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
43 |
|
| 866 | 44 |
if(!options.hasOwnProperty("flashplayer")) { |
45 |
opts.flashplayer = IriSP.jwplayer_swf_path; |
|
|
816
e97e22801146
use href or url indiscriminately to get the source of the rtmp.
hamidouk
parents:
811
diff
changeset
|
46 |
} |
| 866 | 47 |
|
48 |
if(!options.hasOwnProperty("controlbar.position")) { |
|
49 |
opts["controlbar.position"] = "none"; |
|
50 |
} |
|
51 |
pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts); |
|
52 |
break; |
|
|
456
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
53 |
|
| 866 | 54 |
case "youtube": |
55 |
var opts = IriSP.jQuery.extend({}, options); |
|
56 |
delete opts.container; |
|
57 |
opts.controls = 0; |
|
58 |
opts.autostart = false; |
|
59 |
// Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div. |
|
60 |
IriSP.jQuery("#" + containerDiv).css({ |
|
61 |
width : opts.width + "px", |
|
62 |
height : opts.height + "px" |
|
63 |
}) |
|
64 |
pop = Popcorn.youtube("#" + containerDiv, opts.video, opts); |
|
65 |
break; |
|
|
558
29a370694c53
delete type variable which seemed to sometimes (but not always) confuse the jwplayer,
hamidouk
parents:
557
diff
changeset
|
66 |
|
| 866 | 67 |
case "dailymotion": |
68 |
pop = new IriSP.PopcornReplacement.dailymotion("#" + containerDiv, options); |
|
69 |
break; |
|
70 |
||
71 |
case "allocine": |
|
72 |
/* pass the options as-is to the allocine player and let it handle everything */ |
|
73 |
pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, options); |
|
74 |
break; |
|
75 |
||
76 |
default: |
|
77 |
pop = undefined; |
|
| 123 | 78 |
}; |
| 866 | 79 |
|
| 127 | 80 |
return pop; |
| 123 | 81 |
}; |
| 531 | 82 |
/** Configure the gui and instantiate the widgets passed as parameters |
| 866 | 83 |
@param guiOptions the gui object as seen in the examples. |
| 531 | 84 |
*/ |
| 866 | 85 |
IriSP.configureWidgets = function(popcornInstance, layoutManager, guiOptions) { |
86 |
||
87 |
var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader); |
|
88 |
var params = { |
|
89 |
width : guiOptions.width, |
|
90 |
height : guiOptions.height |
|
91 |
}; |
|
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
92 |
|
| 866 | 93 |
var default_options = guiOptions.default_options; |
94 |
if(IriSP.null_or_undefined(default_options)) |
|
95 |
default_options = {}; |
|
96 |
||
97 |
var ret_widgets = []; |
|
98 |
var index; |
|
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
99 |
|
| 866 | 100 |
for( index = 0; index < guiOptions.widgets.length; index++) { |
101 |
var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, guiOptions.widgets[index], default_options); |
|
102 |
||
103 |
ret_widgets.push(widget); |
|
104 |
}; |
|
105 |
||
106 |
return ret_widgets; |
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
107 |
}; |
| 531 | 108 |
/** configure modules. @see configureWidgets */ |
| 866 | 109 |
IriSP.configureModules = function(popcornInstance, modulesList) { |
110 |
/* if(IriSP.null_or_undefined(modulesList)) |
|
111 |
return; |
|
112 |
||
113 |
var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader); |
|
114 |
var ret_modules = []; |
|
115 |
var index; |
|
116 |
||
117 |
for( index = 0; index < modulesList.length; index++) { |
|
118 |
var moduleConfig = modulesList[index]; |
|
| 461 | 119 |
|
| 866 | 120 |
var serializer = serialFactory.getSerializer(moduleConfig.metadata); |
121 |
var module = new IriSP[moduleConfig.type](popcornInstance, moduleConfig, serializer); |
|
122 |
ret_modules.push(module); |
|
123 |
}; |
|
| 461 | 124 |
|
| 866 | 125 |
return ret_modules; */ |
126 |
}; |
|
127 |
/** instantiate a widget - only called by configureWidgets, never by the user. Handles widget |
|
128 |
dependencies. |
|
129 |
@param popcornInstance popcorn instance the widget will user |
|
130 |
@param serialFactory serializer factory to instantiate the widget with |
|
131 |
@param layoutManager layout manager |
|
132 |
@param widgetConfig configuration options for the widget |
|
133 |
@param defaultOptions a dictionnary with some options defined for every widget. |
|
| 531 | 134 |
*/ |
|
811
b9dd62e35e30
less useless code - required widgets now support defaultOptions too.
hamidouk
parents:
810
diff
changeset
|
135 |
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig, defaultOptions) { |
|
b9dd62e35e30
less useless code - required widgets now support defaultOptions too.
hamidouk
parents:
810
diff
changeset
|
136 |
|
| 866 | 137 |
if(IriSP.null_or_undefined(defaultOptions)) |
138 |
defaultOptions = {}; |
|
|
811
b9dd62e35e30
less useless code - required widgets now support defaultOptions too.
hamidouk
parents:
810
diff
changeset
|
139 |
widgetConfig = IriSP.underscore.defaults(widgetConfig, defaultOptions); |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
140 |
|
| 175 | 141 |
var arr = IriSP.jQuery.extend({}, widgetConfig); |
| 866 | 142 |
|
|
582
1bca6b7f56e1
give the possibility to specify containers for widgets.
hamidouk
parents:
577
diff
changeset
|
143 |
/* create a div for those widgets who didn't already specify a container; */ |
| 866 | 144 |
if(!arr.hasOwnProperty("container")) { |
145 |
/* create div returns us a container for the widget and a spacer */ |
|
146 |
var ret = layoutManager.createDiv(widgetConfig.type); |
|
147 |
var container = ret[0]; |
|
148 |
var spacer = ret[1]; |
|
149 |
arr.container = container; |
|
150 |
arr.spacer = spacer; |
|
151 |
arr.layoutManager = layoutManager; |
|
|
582
1bca6b7f56e1
give the possibility to specify containers for widgets.
hamidouk
parents:
577
diff
changeset
|
152 |
} |
| 866 | 153 |
var serializer = serialFactory.getSerializer(widgetConfig.metadata); |
154 |
||
155 |
if( typeof serializer == "undefined") |
|
156 |
debugger; |
|
157 |
||
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
158 |
// instantiate the object passed as a string |
| 866 | 159 |
var widget = new IriSP[widgetConfig.type](popcornInstance, arr, serializer); |
160 |
||
161 |
if(widgetConfig.hasOwnProperty("requires")) { |
|
162 |
// also create the widgets this one depends on. |
|
163 |
// the dependency widget is available in the parent widget context as |
|
164 |
// this.WidgetName (for instance, this.TipWidget); |
|
165 |
||
166 |
var i = 0; |
|
167 |
for( i = 0; i < widgetConfig.requires.length; i++) { |
|
168 |
var widgetName = widgetConfig.requires[i]["type"], _configobj = IriSP.jQuery.extend({}, widgetConfig.requires[i]), _div = document.createElement('div'), _container = IriSP.guid(arr.container + '_' + widgetName + '_'); |
|
169 |
_configobj.container = _container; |
|
170 |
_div.id = _container; |
|
171 |
widget.selector.append(_div); |
|
172 |
widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, _configobj, defaultOptions); |
|
173 |
} |
|
174 |
} |
|
175 |
||
176 |
serializer.sync(IriSP.wrap(widget, function() { |
|
177 |
this.draw(); |
|
178 |
})); |
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
179 |
return widget; |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
180 |
}; |
|
743
69a9969daa41
better defaults - paths are now computed at run-time.
hamidouk
parents:
707
diff
changeset
|
181 |
/** single point of entry for the metadataplayer */ |
| 866 | 182 |
IriSP.initPlayer = function(config, metadata_url, format) { |
| 840 | 183 |
document.getElementById(config.gui.container).innerHTML = IriSP.templToHTML(IriSP.loading_template, config.gui); |
| 866 | 184 |
IriSP.loadLibs(config, metadata_url, format, function() { |
|
743
69a9969daa41
better defaults - paths are now computed at run-time.
hamidouk
parents:
707
diff
changeset
|
185 |
|
| 866 | 186 |
var layoutManager = new IriSP.LayoutManager(config.gui); |
187 |
|
|
188 |
if (typeof IriSP._videoData !== "undefined" && typeof config.player.video === "undefined") { |
|
189 |
var _media = IriSP._videoData.currentMedia; |
|
190 |
if (typeof _media !== "undefined") { |
|
191 |
config.player.video = _media.video; |
|
192 |
if (typeof _media.streamer !== "undefined") { |
|
193 |
config.player.streamer = _media.streamer; |
|
194 |
config.player.video = _media.video.replace(_media.streamer,''); |
|
195 |
} |
|
196 |
} |
|
197 |
|
|
198 |
} |
|
199 |
|
|
200 |
var pop = IriSP.configurePopcorn(layoutManager, config.player); |
|
201 |
||
202 |
IriSP._widgets = IriSP.configureWidgets(pop, layoutManager, config.gui); |
|
203 |
IriSP.jQuery('#Ldt-loader').detach(); |
|
204 |
}); |
|
205 |
}; |