| author | hamidouk |
| Mon, 05 Dec 2011 14:37:05 +0100 | |
| branch | popcorn-port |
| changeset 402 | 6148fb647f46 |
| parent 315 | 4466bf448426 |
| child 404 | 6c4e5b2fee8c |
| child 418 | 06d2aa32c5f4 |
| permissions | -rw-r--r-- |
| 123 | 1 |
/* init.js - initialization and configuration of Popcorn and the widgets |
2 |
exemple json configuration: |
|
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
3 |
|
| 123 | 4 |
*/ |
5 |
||
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
6 |
IriSP.configurePopcorn = function (layoutManager, options) { |
| 123 | 7 |
var pop; |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
8 |
var ret = layoutManager.createDiv(); |
|
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
9 |
var containerDiv = ret[0]; |
| 123 | 10 |
|
| 127 | 11 |
switch(options.type) { |
| 123 | 12 |
/* |
13 |
todo : dynamically create the div/video tag which |
|
14 |
will contain the video. |
|
15 |
*/ |
|
16 |
case "html5": |
|
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
17 |
var tmpId = Popcorn.guid("video"); |
|
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
18 |
IriSP.jQuery("#" + containerDiv).append("<video src='" + options.file + "' id='" + tmpId + "'></video>"); |
|
402
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
19 |
|
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
20 |
if (options.hasOwnProperty("width")) |
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
21 |
IriSP.jQuery("#" + containerDiv).css("width", options.width); |
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
22 |
|
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
23 |
if (options.hasOwnProperty("height")) |
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
24 |
IriSP.jQuery("#" + containerDiv).css("height", options.height); |
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
25 |
|
| 216 | 26 |
pop = Popcorn("#" + tmpId).mediafragment({start : 0}); |
| 123 | 27 |
break; |
| 127 | 28 |
|
29 |
case "jwplayer": |
|
30 |
var opts = IriSP.jQuery.extend({}, options); |
|
31 |
delete opts.container; |
|
| 216 | 32 |
pop = Popcorn.jwplayer("#" + containerDiv, "", opts).mediafragment({start : 0}); |
| 127 | 33 |
break; |
| 198 | 34 |
|
35 |
case "youtube": |
|
36 |
var opts = IriSP.jQuery.extend({}, options); |
|
37 |
delete opts.container; |
|
38 |
opts.controls = 0; |
|
39 |
opts.autostart = false; |
|
| 204 | 40 |
templ = "width: {{width}}px; height: {{height}}px;"; |
| 198 | 41 |
var str = Mustache.to_html(templ, {width: opts.width, height: opts.height}); |
42 |
// Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div. |
|
43 |
IriSP.jQuery("#" + containerDiv).attr("style", str); |
|
44 |
|
|
| 216 | 45 |
pop = Popcorn.youtube("#" + containerDiv, opts.video, opts).mediafragment({start : 0}); |
| 198 | 46 |
break; |
| 127 | 47 |
|
48 |
default: |
|
49 |
pop = undefined; |
|
| 123 | 50 |
}; |
51 |
|
|
| 127 | 52 |
return pop; |
| 123 | 53 |
}; |
54 |
||
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
55 |
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) { |
| 123 | 56 |
|
| 127 | 57 |
var dt = new IriSP.DataLoader(); |
58 |
var serialFactory = new IriSP.SerializerFactory(dt); |
|
59 |
|
|
60 |
var params = {width: guiOptions.width, height: guiOptions.height}; |
|
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
61 |
|
| 127 | 62 |
var ret_widgets = []; |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
63 |
var index; |
| 127 | 64 |
|
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
65 |
for (index = 0; index < guiOptions.widgets.length; index++) { |
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
66 |
var widgetConfig = guiOptions.widgets[index]; |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
67 |
var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig); |
| 127 | 68 |
ret_widgets.push(widget); |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
69 |
|
| 127 | 70 |
}; |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
71 |
|
| 127 | 72 |
return ret_widgets; |
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
73 |
}; |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
74 |
|
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
75 |
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) { |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
76 |
/* create div returns us a container for the widget and a spacer */ |
|
315
4466bf448426
updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents:
287
diff
changeset
|
77 |
var ret = layoutManager.createDiv(widgetConfig.type); |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
78 |
var container = ret[0]; |
|
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
79 |
var spacer = ret[1]; |
|
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
80 |
|
| 175 | 81 |
var arr = IriSP.jQuery.extend({}, widgetConfig); |
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
82 |
arr.container = container; |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
83 |
arr.spacer = spacer; |
| 175 | 84 |
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
85 |
var serializer = serialFactory.getSerializer(widgetConfig.metadata); |
| 175 | 86 |
|
87 |
if (typeof serializer == "undefined") |
|
88 |
debugger; |
|
89 |
|
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
90 |
// instantiate the object passed as a string |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
91 |
var widget = new IriSP[widgetConfig.type](popcornInstance, arr, serializer); |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
92 |
|
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
93 |
if (widgetConfig.hasOwnProperty("requires")) { |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
94 |
// also create the widgets this one depends on. |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
95 |
// the dependency widget is available in the parent widget context as |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
96 |
// this.WidgetName (for instance, this.TipWidget); |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
97 |
|
| 175 | 98 |
var i = 0; |
99 |
for(i = 0; i < widgetConfig.requires.length; i++) { |
|
100 |
var widgetName = widgetConfig.requires[i]["type"]; |
|
101 |
widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig.requires[i]); |
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
102 |
} |
| 175 | 103 |
} |
104 |
|
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
105 |
serializer.sync(IriSP.wrap(widget, function() { this.draw(); })); |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
106 |
return widget; |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
107 |
}; |