| author | veltr |
| Tue, 01 Oct 2013 15:41:46 +0200 | |
| changeset 1013 | 392ddcd212d7 |
| parent 1001 | 3210bf928a11 |
| child 1033 | c20df1c080e6 |
| permissions | -rw-r--r-- |
| 998 | 1 |
/* widgetsDefinition of an ancestor for the Widget classes */ |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
2 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
3 |
if (typeof IriSP.Widgets === "undefined") { |
| 998 | 4 |
IriSP.Widgets = {}; |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
5 |
} |
|
66
13013b9452af
Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff
changeset
|
6 |
|
|
520
fe008e95a716
added jsdoc support, and a script to generate the docs.
hamidouk
parents:
287
diff
changeset
|
7 |
/** |
| 868 | 8 |
* @class IriSP.Widget is an "abstract" class. It's mostly used to define some properties common to every widget. |
9 |
* |
|
10 |
* Note that widget constructors are never called directly by the user. Instead, the widgets are instantiated by functions |
|
11 |
* defined in init.js |
|
12 |
* |
|
13 |
* @constructor |
|
14 |
* @param player - a reference to the player widget |
|
15 |
* @param config - configuration options for the widget |
|
16 |
*/ |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
17 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
18 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
19 |
IriSP.Widgets.Widget = function(player, config) { |
| 984 | 20 |
|
| 868 | 21 |
if( typeof player === "undefined") { |
22 |
/* Probably an abstract call of the class when |
|
23 |
* individual widgets set their prototype */ |
|
24 |
return; |
|
25 |
} |
|
26 |
|
|
| 984 | 27 |
this.__subwidgets = []; |
28 |
|
|
| 868 | 29 |
/* Setting all the configuration options */ |
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
30 |
var _type = config.type || "(unknown)", |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
31 |
_config = IriSP._.defaults({}, config, (player && player.config ? player.config.default_options : {}), this.defaults), |
| 868 | 32 |
_this = this; |
33 |
|
|
34 |
IriSP._(_config).forEach(function(_value, _key) { |
|
35 |
_this[_key] = _value; |
|
36 |
}); |
|
37 |
|
|
|
988
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
986
diff
changeset
|
38 |
this.$ = IriSP.jQuery('#' + this.container); |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
986
diff
changeset
|
39 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
40 |
if (typeof this.width === "undefined") { |
|
988
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
986
diff
changeset
|
41 |
this.width = this.$.width(); |
| 992 | 42 |
} else { |
43 |
this.$.css("width", this.width); |
|
44 |
} |
|
45 |
|
|
46 |
if (typeof this.height !== "undefined") { |
|
47 |
this.$.css("height", this.height); |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
48 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
49 |
|
| 868 | 50 |
/* Setting this.player at the end in case it's been overriden |
51 |
* by a configuration option of the same name :-( |
|
52 |
*/ |
|
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
53 |
this.player = player || new IriSP.FakeClass(["on","trigger","off","loadWidget","loadMetadata"]); |
| 868 | 54 |
|
55 |
/* Adding classes and html attributes */ |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
56 |
this.$.addClass("Ldt-TraceMe Ldt-Widget").attr("widget-type", _type); |
| 868 | 57 |
|
| 916 | 58 |
this.l10n = ( |
59 |
typeof this.messages[IriSP.language] !== "undefined" |
|
60 |
? this.messages[IriSP.language] |
|
61 |
: ( |
|
62 |
IriSP.language.length > 2 && typeof this.messages[IriSP.language.substr(0,2)] !== "undefined" |
|
63 |
? this.messages[IriSP.language.substr(0,2)] |
|
64 |
: this.messages["en"] |
|
65 |
) |
|
66 |
); |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
67 |
|
| 986 | 68 |
/* Loading Metadata if required */ |
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
69 |
|
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
70 |
function onsourceloaded() { |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
71 |
if (_this.media_id) { |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
72 |
_this.media = this.getElement(_this.media_id); |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
73 |
} else { |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
74 |
var _mediaopts = { |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
75 |
is_mashup: _this.is_mashup || false |
| 1013 | 76 |
}; |
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
77 |
_this.media = _this.source.getCurrentMedia(_mediaopts); |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
78 |
} |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
79 |
|
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
80 |
_this.draw(); |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
81 |
_this.player.trigger("widget-loaded"); |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
82 |
} |
| 986 | 83 |
|
84 |
if (this.metadata) { |
|
85 |
/* Getting metadata */ |
|
86 |
this.source = player.loadMetadata(this.metadata); |
|
87 |
|
|
88 |
/* Call draw when loaded */ |
|
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
89 |
this.source.onLoad(onsourceloaded); |
| 986 | 90 |
} else { |
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
91 |
if (this.source) { |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
92 |
onsourceloaded(); |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
93 |
} |
| 986 | 94 |
} |
95 |
|
|
96 |
|
|
|
66
13013b9452af
Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff
changeset
|
97 |
}; |
| 74 | 98 |
|
| 998 | 99 |
IriSP.Widgets.Widget.prototype.defaults = {}; |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
100 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
101 |
IriSP.Widgets.Widget.prototype.template = ''; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
102 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
103 |
IriSP.Widgets.Widget.prototype.messages = {"en":{}}; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
104 |
|
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
105 |
IriSP.Widgets.Widget.prototype.toString = function() { |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
106 |
return "Widget " + this.type; |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
107 |
}; |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
108 |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
109 |
IriSP.Widgets.Widget.prototype.templateToHtml = function(_template) { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
110 |
return Mustache.to_html(_template, this); |
| 998 | 111 |
}; |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
112 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
113 |
IriSP.Widgets.Widget.prototype.renderTemplate = function() { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
114 |
this.$.append(this.templateToHtml(this.template)); |
| 998 | 115 |
}; |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
116 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
117 |
IriSP.Widgets.Widget.prototype.functionWrapper = function(_name) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
118 |
var _this = this, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
119 |
_function = this[_name]; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
120 |
if (typeof _function !== "undefined") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
121 |
return function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
122 |
return _function.apply(_this, Array.prototype.slice.call(arguments, 0)); |
| 1013 | 123 |
}; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
124 |
} else { |
| 1013 | 125 |
console.log("Error, Unknown function IriSP.Widgets." + this.type + "." + _name); |
| 957 | 126 |
} |
| 998 | 127 |
}; |
| 957 | 128 |
|
129 |
IriSP.Widgets.Widget.prototype.getFunctionOrName = function(_functionOrName) { |
|
130 |
switch (typeof _functionOrName) { |
|
131 |
case "function": |
|
132 |
return _functionOrName; |
|
133 |
case "string": |
|
134 |
return this.functionWrapper(_functionOrName); |
|
135 |
default: |
|
136 |
return undefined; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
137 |
} |
| 998 | 138 |
}; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
139 |
|
| 957 | 140 |
IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) { |
141 |
this.player.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
| 998 | 142 |
}; |
| 957 | 143 |
|
144 |
IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) { |
|
145 |
this.media.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
| 998 | 146 |
}; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
147 |
|
| 876 | 148 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { |
| 982 | 149 |
if (typeof this.annotation_type === "undefined") { |
150 |
return this.media.getAnnotations(); |
|
151 |
} |
|
152 |
if (this.annotation_type.elementType === "annotationType") { |
|
153 |
return this.annotation_type.getAnnotations(); |
|
154 |
} |
|
155 |
return this.media.getAnnotationsByTypeTitle(this.annotation_type); |
|
| 998 | 156 |
}; |
| 876 | 157 |
|
| 922 | 158 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() { |
| 957 | 159 |
var _time = this.media.getCurrentTime(); |
| 922 | 160 |
return this.getWidgetAnnotations().filter(function(_annotation) { |
161 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
162 |
}); |
|
| 998 | 163 |
}; |
| 922 | 164 |
|
| 984 | 165 |
IriSP.Widgets.Widget.prototype.isLoaded = function() { |
166 |
var isloaded = !IriSP._(this.__subwidgets).any(function(w) { |
|
167 |
return !(w && w.isLoaded()); |
|
168 |
}); |
|
169 |
return isloaded; |
|
| 998 | 170 |
}; |
| 984 | 171 |
|
| 959 | 172 |
IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _widgetoptions, _propname) { |
| 924 | 173 |
var _id = _selector.attr("id"), |
| 927 | 174 |
_this = this, |
175 |
_type = _widgetoptions.type, |
|
| 984 | 176 |
$L = $LAB, |
177 |
key = this.__subwidgets.length; |
|
178 |
this.__subwidgets.push(null); |
|
| 924 | 179 |
if (typeof _id == "undefined") { |
180 |
_id = IriSP._.uniqueId(this.container + '_sub_widget_' + _widgetoptions.type); |
|
181 |
_selector.attr("id", _id); |
|
182 |
} |
|
183 |
_widgetoptions.container = _id; |
|
| 927 | 184 |
if (typeof IriSP.widgetsRequirements[_type] !== "undefined" && typeof IriSP.widgetsRequirements[_type].requires !== "undefined" ) { |
185 |
for (var _j = 0; _j < IriSP.widgetsRequirements[_type].requires.length; _j++) { |
|
186 |
$L.script(IriSP.getLib(IriSP.widgetsRequirements[_type].requires[_j])); |
|
187 |
} |
|
188 |
} |
|
189 |
$L.wait(function() { |
|
190 |
_this.player.loadWidget(_widgetoptions, function(_widget) { |
|
| 959 | 191 |
if (_propname) { |
192 |
_this[_propname] = _widget; |
|
193 |
} |
|
| 984 | 194 |
_this.__subwidgets[key] = _widget; |
| 927 | 195 |
}); |
| 924 | 196 |
}); |
| 998 | 197 |
}; |
| 924 | 198 |
|
|
520
fe008e95a716
added jsdoc support, and a script to generate the docs.
hamidouk
parents:
287
diff
changeset
|
199 |
/** |
| 868 | 200 |
* This method responsible of drawing a widget on screen. |
201 |
*/ |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
202 |
IriSP.Widgets.Widget.prototype.draw = function() { |
| 868 | 203 |
/* implemented by "sub-classes" */ |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
900
diff
changeset
|
204 |
}; |