| author | veltr |
| Fri, 25 Jan 2013 18:16:29 +0100 | |
| changeset 988 | eefd336335f9 |
| parent 986 | f9d51dd4a3fe |
| child 992 | 566b590aaf8f |
| permissions | -rw-r--r-- |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
1 |
/* Definition of an ancestor for the Widget classes */ |
|
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") { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
4 |
IriSP.Widgets = {} |
|
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 */ |
30 |
var _type = config.type, |
|
| 958 | 31 |
_config = IriSP._.defaults({}, 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(); |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
42 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
43 |
|
| 868 | 44 |
/* Setting this.player at the end in case it's been overriden |
45 |
* by a configuration option of the same name :-( |
|
46 |
*/ |
|
47 |
this.player = player; |
|
48 |
|
|
49 |
/* Adding classes and html attributes */ |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
50 |
this.$.addClass("Ldt-TraceMe Ldt-Widget").attr("widget-type", _type); |
| 868 | 51 |
|
| 916 | 52 |
this.l10n = ( |
53 |
typeof this.messages[IriSP.language] !== "undefined" |
|
54 |
? this.messages[IriSP.language] |
|
55 |
: ( |
|
56 |
IriSP.language.length > 2 && typeof this.messages[IriSP.language.substr(0,2)] !== "undefined" |
|
57 |
? this.messages[IriSP.language.substr(0,2)] |
|
58 |
: this.messages["en"] |
|
59 |
) |
|
60 |
); |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
61 |
|
| 986 | 62 |
/* Loading Metadata if required */ |
63 |
|
|
64 |
if (this.metadata) { |
|
65 |
/* Getting metadata */ |
|
66 |
this.source = player.loadMetadata(this.metadata); |
|
67 |
|
|
68 |
/* Call draw when loaded */ |
|
69 |
this.source.onLoad(function() { |
|
70 |
if (_this.media_id) { |
|
71 |
_this.media = this.getElement(_this.media_id); |
|
72 |
} else { |
|
73 |
var _mediaopts = { |
|
74 |
is_mashup: _this.is_mashup || false |
|
75 |
} |
|
76 |
_this.media = this.getCurrentMedia(_mediaopts); |
|
77 |
} |
|
78 |
|
|
79 |
_this.draw(); |
|
80 |
player.trigger("widget-loaded"); |
|
81 |
}); |
|
82 |
} else { |
|
83 |
this.draw(); |
|
84 |
} |
|
85 |
|
|
86 |
|
|
|
66
13013b9452af
Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff
changeset
|
87 |
}; |
| 74 | 88 |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
89 |
IriSP.Widgets.Widget.prototype.defaults = {} |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
90 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
91 |
IriSP.Widgets.Widget.prototype.template = ''; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
92 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
93 |
IriSP.Widgets.Widget.prototype.messages = {"en":{}}; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
94 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
95 |
IriSP.Widgets.Widget.prototype.templateToHtml = function(_template) { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
96 |
return Mustache.to_html(_template, this); |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
97 |
} |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
98 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
99 |
IriSP.Widgets.Widget.prototype.renderTemplate = function() { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
100 |
this.$.append(this.templateToHtml(this.template)); |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
101 |
} |
|
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.functionWrapper = function(_name) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
104 |
var _this = this, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
105 |
_function = this[_name]; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
106 |
if (typeof _function !== "undefined") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
107 |
return function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
108 |
return _function.apply(_this, Array.prototype.slice.call(arguments, 0)); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
109 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
110 |
} else { |
| 965 | 111 |
console.log("Error, Unknown function IriSP.Widgets." + this.type + "." + _name) |
| 957 | 112 |
} |
113 |
} |
|
114 |
||
115 |
IriSP.Widgets.Widget.prototype.getFunctionOrName = function(_functionOrName) { |
|
116 |
switch (typeof _functionOrName) { |
|
117 |
case "function": |
|
118 |
return _functionOrName; |
|
119 |
case "string": |
|
120 |
return this.functionWrapper(_functionOrName); |
|
121 |
default: |
|
122 |
return undefined; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
123 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
124 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
125 |
|
| 957 | 126 |
IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) { |
127 |
this.player.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
128 |
} |
|
129 |
||
130 |
IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) { |
|
131 |
this.media.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
132 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
133 |
|
| 876 | 134 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { |
| 982 | 135 |
if (typeof this.annotation_type === "undefined") { |
136 |
return this.media.getAnnotations(); |
|
137 |
} |
|
138 |
if (this.annotation_type.elementType === "annotationType") { |
|
139 |
return this.annotation_type.getAnnotations(); |
|
140 |
} |
|
141 |
return this.media.getAnnotationsByTypeTitle(this.annotation_type); |
|
| 876 | 142 |
} |
143 |
||
| 922 | 144 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() { |
| 957 | 145 |
var _time = this.media.getCurrentTime(); |
| 922 | 146 |
return this.getWidgetAnnotations().filter(function(_annotation) { |
147 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
148 |
}); |
|
149 |
} |
|
150 |
||
| 984 | 151 |
IriSP.Widgets.Widget.prototype.isLoaded = function() { |
152 |
var isloaded = !IriSP._(this.__subwidgets).any(function(w) { |
|
153 |
return !(w && w.isLoaded()); |
|
154 |
}); |
|
155 |
return isloaded; |
|
156 |
} |
|
157 |
||
| 959 | 158 |
IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _widgetoptions, _propname) { |
| 924 | 159 |
var _id = _selector.attr("id"), |
| 927 | 160 |
_this = this, |
161 |
_type = _widgetoptions.type, |
|
| 984 | 162 |
$L = $LAB, |
163 |
key = this.__subwidgets.length; |
|
164 |
this.__subwidgets.push(null); |
|
| 924 | 165 |
if (typeof _id == "undefined") { |
166 |
_id = IriSP._.uniqueId(this.container + '_sub_widget_' + _widgetoptions.type); |
|
167 |
_selector.attr("id", _id); |
|
168 |
} |
|
169 |
_widgetoptions.container = _id; |
|
| 927 | 170 |
if (typeof IriSP.widgetsRequirements[_type] !== "undefined" && typeof IriSP.widgetsRequirements[_type].requires !== "undefined" ) { |
171 |
for (var _j = 0; _j < IriSP.widgetsRequirements[_type].requires.length; _j++) { |
|
172 |
$L.script(IriSP.getLib(IriSP.widgetsRequirements[_type].requires[_j])); |
|
173 |
} |
|
174 |
} |
|
175 |
$L.wait(function() { |
|
176 |
_this.player.loadWidget(_widgetoptions, function(_widget) { |
|
| 959 | 177 |
if (_propname) { |
178 |
_this[_propname] = _widget; |
|
179 |
} |
|
| 984 | 180 |
_this.__subwidgets[key] = _widget; |
| 927 | 181 |
}); |
| 924 | 182 |
}); |
183 |
} |
|
184 |
||
|
520
fe008e95a716
added jsdoc support, and a script to generate the docs.
hamidouk
parents:
287
diff
changeset
|
185 |
/** |
| 868 | 186 |
* This method responsible of drawing a widget on screen. |
187 |
*/ |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
188 |
IriSP.Widgets.Widget.prototype.draw = function() { |
| 868 | 189 |
/* implemented by "sub-classes" */ |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
900
diff
changeset
|
190 |
}; |