| author | hamidouk |
| Mon, 14 Nov 2011 17:19:26 +0100 | |
| branch | require-js |
| changeset 238 | 6008172a0592 |
| parent 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 |
||
|
238
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
6 |
define(["IriSP"], function() { |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
7 |
IriSP.configurePopcorn = function (layoutManager, options) { |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
8 |
var pop; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
9 |
var containerDiv = layoutManager.createDiv(); |
| 198 | 10 |
|
|
238
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
11 |
switch(options.type) { |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
12 |
/* |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
13 |
todo : dynamically create the div/video tag which |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
14 |
will contain the video. |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
15 |
*/ |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
16 |
case "html5": |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
17 |
var tmpId = Popcorn.guid("video"); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
18 |
IriSP.jQuery("#" + containerDiv).append("<video src='" + options.file + "' id='" + tmpId + "'></video>"); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
19 |
pop = Popcorn("#" + tmpId).mediafragment({start : 0}); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
20 |
break; |
| 198 | 21 |
|
|
238
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
22 |
case "jwplayer": |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
23 |
var opts = IriSP.jQuery.extend({}, options); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
24 |
delete opts.container; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
25 |
pop = Popcorn.jwplayer("#" + containerDiv, "", opts).mediafragment({start : 0}); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
26 |
break; |
| 127 | 27 |
|
|
238
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
28 |
case "youtube": |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
29 |
var opts = IriSP.jQuery.extend({}, options); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
30 |
delete opts.container; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
31 |
opts.controls = 0; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
32 |
opts.autostart = false; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
33 |
templ = "width: {{width}}px; height: {{height}}px;"; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
34 |
var str = Mustache.to_html(templ, {width: opts.width, height: opts.height}); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
35 |
// Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div. |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
36 |
IriSP.jQuery("#" + containerDiv).attr("style", str); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
37 |
|
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
38 |
pop = Popcorn.youtube("#" + containerDiv, opts.video, opts).mediafragment({start : 0}); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
39 |
break; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
40 |
|
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
41 |
default: |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
42 |
pop = undefined; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
43 |
}; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
44 |
|
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
45 |
return pop; |
| 127 | 46 |
}; |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
47 |
|
|
238
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
48 |
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) { |
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
49 |
|
|
238
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
50 |
var dt = new IriSP.DataLoader(); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
51 |
var serialFactory = new IriSP.SerializerFactory(dt); |
| 175 | 52 |
|
|
238
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
53 |
var params = {width: guiOptions.width, height: guiOptions.height}; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
54 |
|
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
55 |
var ret_widgets = []; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
56 |
var index; |
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
57 |
|
|
238
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
58 |
for (index = 0; index < guiOptions.widgets.length; index++) { |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
59 |
var widgetConfig = guiOptions.widgets[index]; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
60 |
var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
61 |
ret_widgets.push(widget); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
62 |
|
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
63 |
}; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
64 |
|
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
65 |
return ret_widgets; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
66 |
}; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
67 |
|
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
68 |
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) { |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
69 |
var container = layoutManager.createDiv(); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
70 |
var arr = IriSP.jQuery.extend({}, widgetConfig); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
71 |
arr.container = container; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
72 |
|
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
73 |
var serializer = serialFactory.getSerializer(widgetConfig.metadata); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
74 |
|
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
75 |
if (typeof serializer == "undefined") |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
76 |
debugger; |
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
77 |
|
|
238
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
78 |
// instantiate the object passed as a string |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
79 |
var widget = new IriSP[widgetConfig.type](popcornInstance, arr, serializer); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
80 |
|
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
81 |
if (widgetConfig.hasOwnProperty("requires")) { |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
82 |
// also create the widgets this one depends on. |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
83 |
// the dependency widget is available in the parent widget context as |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
84 |
// this.WidgetName (for instance, this.TipWidget); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
85 |
|
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
86 |
var i = 0; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
87 |
for(i = 0; i < widgetConfig.requires.length; i++) { |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
88 |
var widgetName = widgetConfig.requires[i]["type"]; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
89 |
widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig.requires[i]); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
90 |
} |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
91 |
} |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
92 |
|
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
93 |
serializer.sync(IriSP.wrap(widget, function() { this.draw(); })); |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
94 |
return widget; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
95 |
}; |
|
6008172a0592
converted all the source files to use the require.js syntax.
hamidouk
parents:
216
diff
changeset
|
96 |
}); |