| author | hamidouk |
| Mon, 28 Nov 2011 12:14:31 +0100 | |
| branch | lazyload-js |
| changeset 341 | e9442357851b |
| 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 |
||
|
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>"); |
| 216 | 18 |
pop = Popcorn("#" + tmpId).mediafragment({start : 0}); |
| 123 | 19 |
break; |
| 127 | 20 |
|
21 |
case "jwplayer": |
|
22 |
var opts = IriSP.jQuery.extend({}, options); |
|
23 |
delete opts.container; |
|
| 216 | 24 |
pop = Popcorn.jwplayer("#" + containerDiv, "", opts).mediafragment({start : 0}); |
| 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 |
|
|
| 216 | 37 |
pop = Popcorn.youtube("#" + containerDiv, opts.video, opts).mediafragment({start : 0}); |
| 198 | 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; |
|
341
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
94 |
}; |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
95 |
|
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
96 |
IriSP.loadLibs = function( libs, cssPaths, customCssPath, callback ) { |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
97 |
// Localize jQuery variable |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
98 |
IriSP.jQuery = null; |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
99 |
var jsLibs = []; |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
100 |
for(var lib in libs) { |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
101 |
jsLibs.push(libs[lib]); |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
102 |
} |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
103 |
|
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
104 |
var libsCss = []; |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
105 |
for(var lib in cssPaths) { |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
106 |
libsCss.push(cssPaths[lib]); |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
107 |
} |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
108 |
|
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
109 |
|
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
110 |
libsCss.push(customCssPath); |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
111 |
|
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
112 |
LazyLoad.js(jsLibs, function() { |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
113 |
IriSP.jQuery = window.jQuery.noConflict( true ); |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
114 |
LazyLoad.css(libsCss); |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
115 |
callback(); |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
116 |
}); |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
117 |
}; |
|
e9442357851b
integrating LazyLoad. It replaces the old code in IriSP.loadLibs.
hamidouk
parents:
216
diff
changeset
|
118 |