| author | hamidouk |
| Tue, 08 Nov 2011 10:36:48 +0100 | |
| branch | popcorn-port |
| changeset 204 | a5e807f33a67 |
| parent 198 | 8ffb1b7a9c6b |
| child 216 | d1e891627286 |
| 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; |
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
8 |
var containerDiv = layoutManager.createDiv(); |
| 123 | 9 |
|
| 127 | 10 |
switch(options.type) { |
| 123 | 11 |
/* |
12 |
todo : dynamically create the div/video tag which |
|
13 |
will contain the video. |
|
14 |
*/ |
|
15 |
case "html5": |
|
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
16 |
var tmpId = Popcorn.guid("video"); |
|
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
17 |
IriSP.jQuery("#" + containerDiv).append("<video src='" + options.file + "' id='" + tmpId + "'></video>"); |
|
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
18 |
pop = Popcorn("#" + tmpId); |
| 123 | 19 |
break; |
| 127 | 20 |
|
21 |
case "jwplayer": |
|
22 |
var opts = IriSP.jQuery.extend({}, options); |
|
23 |
delete opts.container; |
|
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
24 |
pop = Popcorn.jwplayer("#" + containerDiv, "", opts); |
| 127 | 25 |
break; |
| 198 | 26 |
|
27 |
case "youtube": |
|
28 |
var opts = IriSP.jQuery.extend({}, options); |
|
29 |
delete opts.container; |
|
30 |
opts.controls = 0; |
|
31 |
opts.autostart = false; |
|
| 204 | 32 |
templ = "width: {{width}}px; height: {{height}}px;"; |
| 198 | 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); |
|
38 |
break; |
|
| 127 | 39 |
|
40 |
default: |
|
41 |
pop = undefined; |
|
| 123 | 42 |
}; |
43 |
|
|
| 127 | 44 |
return pop; |
| 123 | 45 |
}; |
46 |
||
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
47 |
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) { |
| 123 | 48 |
|
| 127 | 49 |
var dt = new IriSP.DataLoader(); |
50 |
var serialFactory = new IriSP.SerializerFactory(dt); |
|
51 |
|
|
52 |
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
|
53 |
|
| 127 | 54 |
var ret_widgets = []; |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
55 |
var index; |
| 127 | 56 |
|
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
57 |
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
|
58 |
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
|
59 |
var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig); |
| 127 | 60 |
ret_widgets.push(widget); |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
61 |
|
| 127 | 62 |
}; |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
63 |
|
| 127 | 64 |
return ret_widgets; |
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
65 |
}; |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
66 |
|
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
67 |
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) { |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
68 |
var container = layoutManager.createDiv(); |
| 175 | 69 |
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
|
70 |
arr.container = container; |
| 175 | 71 |
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
72 |
var serializer = serialFactory.getSerializer(widgetConfig.metadata); |
| 175 | 73 |
|
74 |
if (typeof serializer == "undefined") |
|
75 |
debugger; |
|
76 |
|
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
77 |
// 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
|
78 |
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
|
79 |
|
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
80 |
if (widgetConfig.hasOwnProperty("requires")) { |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
81 |
// 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
|
82 |
// 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
|
83 |
// 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
|
84 |
|
| 175 | 85 |
var i = 0; |
86 |
for(i = 0; i < widgetConfig.requires.length; i++) { |
|
87 |
var widgetName = widgetConfig.requires[i]["type"]; |
|
88 |
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
|
89 |
} |
| 175 | 90 |
} |
91 |
|
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
92 |
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
|
93 |
return widget; |
| 123 | 94 |
}; |