| author | hamidouk |
| Fri, 02 Dec 2011 15:42:06 +0100 | |
| branch | no-popcorn |
| changeset 394 | 89a79a2c6014 |
| parent 389 | 2f855c3efd48 |
| 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>"); |
| 216 | 19 |
pop = Popcorn("#" + tmpId).mediafragment({start : 0}); |
| 123 | 20 |
break; |
| 127 | 21 |
|
22 |
case "jwplayer": |
|
23 |
var opts = IriSP.jQuery.extend({}, options); |
|
24 |
delete opts.container; |
|
|
389
2f855c3efd48
changed init to accomodate the popcorn replacement.
hamidouk
parents:
315
diff
changeset
|
25 |
pop = Popcorn.jwplayer("#" + containerDiv, opts); |
| 127 | 26 |
break; |
| 198 | 27 |
|
28 |
case "youtube": |
|
29 |
var opts = IriSP.jQuery.extend({}, options); |
|
30 |
delete opts.container; |
|
31 |
opts.controls = 0; |
|
32 |
opts.autostart = false; |
|
| 204 | 33 |
templ = "width: {{width}}px; height: {{height}}px;"; |
| 198 | 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 |
|
|
| 216 | 38 |
pop = Popcorn.youtube("#" + containerDiv, opts.video, opts).mediafragment({start : 0}); |
| 198 | 39 |
break; |
| 127 | 40 |
|
41 |
default: |
|
42 |
pop = undefined; |
|
| 123 | 43 |
}; |
44 |
|
|
| 127 | 45 |
return pop; |
| 123 | 46 |
}; |
47 |
||
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
48 |
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) { |
| 123 | 49 |
|
| 127 | 50 |
var dt = new IriSP.DataLoader(); |
51 |
var serialFactory = new IriSP.SerializerFactory(dt); |
|
52 |
|
|
53 |
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
|
54 |
|
| 127 | 55 |
var ret_widgets = []; |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
56 |
var index; |
| 127 | 57 |
|
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
58 |
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
|
59 |
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
|
60 |
var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig); |
| 127 | 61 |
ret_widgets.push(widget); |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
62 |
|
| 127 | 63 |
}; |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
64 |
|
| 127 | 65 |
return ret_widgets; |
|
171
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 |
|
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
68 |
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) { |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
69 |
/* 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
|
70 |
var ret = layoutManager.createDiv(widgetConfig.type); |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
71 |
var container = ret[0]; |
|
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
72 |
var spacer = ret[1]; |
|
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
73 |
|
| 175 | 74 |
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
|
75 |
arr.container = container; |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
76 |
arr.spacer = spacer; |
| 175 | 77 |
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
78 |
var serializer = serialFactory.getSerializer(widgetConfig.metadata); |
| 175 | 79 |
|
80 |
if (typeof serializer == "undefined") |
|
81 |
debugger; |
|
82 |
|
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
83 |
// 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
|
84 |
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
|
85 |
|
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
86 |
if (widgetConfig.hasOwnProperty("requires")) { |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
87 |
// 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
|
88 |
// 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
|
89 |
// 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
|
90 |
|
| 175 | 91 |
var i = 0; |
92 |
for(i = 0; i < widgetConfig.requires.length; i++) { |
|
93 |
var widgetName = widgetConfig.requires[i]["type"]; |
|
94 |
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
|
95 |
} |
| 175 | 96 |
} |
97 |
|
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
98 |
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
|
99 |
return widget; |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
100 |
}; |