| author | veltr |
| Fri, 21 Sep 2012 11:18:57 +0900 | |
| changeset 964 | d7d56ea2d0a6 |
| parent 959 | ee11ed1b739e |
| child 965 | eadb7290c325 |
| 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) { |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
170
diff
changeset
|
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 |
|
|
27 |
/* Setting all the configuration options */ |
|
28 |
var _type = config.type, |
|
| 958 | 29 |
_config = IriSP._.defaults({}, config, player.config.default_options, this.defaults), |
| 868 | 30 |
_this = this; |
31 |
|
|
32 |
IriSP._(_config).forEach(function(_value, _key) { |
|
33 |
_this[_key] = _value; |
|
34 |
}); |
|
35 |
|
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
36 |
if (typeof this.width === "undefined") { |
| 958 | 37 |
this.width = player.config.width; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
38 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
39 |
|
| 868 | 40 |
/* Setting this.player at the end in case it's been overriden |
41 |
* by a configuration option of the same name :-( |
|
42 |
*/ |
|
43 |
this.player = player; |
|
44 |
|
|
45 |
/* Getting metadata */ |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
46 |
this.source = player.loadMetadata(this.metadata); |
| 868 | 47 |
|
48 |
/* Call draw when loaded */ |
|
49 |
this.source.onLoad(function() { |
|
| 959 | 50 |
if (_this.media_id) { |
51 |
_this.media = this.getElement(_this.media_id); |
|
52 |
} else { |
|
53 |
var _mediaopts = { |
|
54 |
is_mashup: _this.is_mashup || false |
|
55 |
} |
|
56 |
_this.media = this.getCurrentMedia(_mediaopts); |
|
57 |
} |
|
58 |
|
|
| 868 | 59 |
_this.draw(); |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
60 |
}); |
| 868 | 61 |
|
62 |
/* Adding classes and html attributes */ |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
63 |
this.$ = IriSP.jQuery('#' + this.container); |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
64 |
this.$.addClass("Ldt-TraceMe Ldt-Widget").attr("widget-type", _type); |
| 868 | 65 |
|
| 916 | 66 |
this.l10n = ( |
67 |
typeof this.messages[IriSP.language] !== "undefined" |
|
68 |
? this.messages[IriSP.language] |
|
69 |
: ( |
|
70 |
IriSP.language.length > 2 && typeof this.messages[IriSP.language.substr(0,2)] !== "undefined" |
|
71 |
? this.messages[IriSP.language.substr(0,2)] |
|
72 |
: this.messages["en"] |
|
73 |
) |
|
74 |
); |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
75 |
|
|
66
13013b9452af
Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff
changeset
|
76 |
}; |
| 74 | 77 |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
78 |
IriSP.Widgets.Widget.prototype.defaults = {} |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
79 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
80 |
IriSP.Widgets.Widget.prototype.template = ''; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
81 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
82 |
IriSP.Widgets.Widget.prototype.messages = {"en":{}}; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
83 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
84 |
IriSP.Widgets.Widget.prototype.templateToHtml = function(_template) { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
85 |
return Mustache.to_html(_template, this); |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
86 |
} |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
87 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
88 |
IriSP.Widgets.Widget.prototype.renderTemplate = function() { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
89 |
this.$.append(this.templateToHtml(this.template)); |
|
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 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
92 |
IriSP.Widgets.Widget.prototype.functionWrapper = function(_name) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
93 |
var _this = this, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
94 |
_function = this[_name]; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
95 |
if (typeof _function !== "undefined") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
96 |
return function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
97 |
return _function.apply(_this, Array.prototype.slice.call(arguments, 0)); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
98 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
99 |
} else { |
| 957 | 100 |
console.log("Error, Unknown function IriSP.Widgets" + this.type + "." + _name) |
101 |
} |
|
102 |
} |
|
103 |
||
104 |
IriSP.Widgets.Widget.prototype.getFunctionOrName = function(_functionOrName) { |
|
105 |
switch (typeof _functionOrName) { |
|
106 |
case "function": |
|
107 |
return _functionOrName; |
|
108 |
case "string": |
|
109 |
return this.functionWrapper(_functionOrName); |
|
110 |
default: |
|
111 |
return undefined; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
112 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
113 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
114 |
|
| 957 | 115 |
IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) { |
116 |
this.player.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
117 |
} |
|
118 |
||
119 |
IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) { |
|
120 |
this.media.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
121 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
122 |
|
| 876 | 123 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { |
| 957 | 124 |
return typeof this.annotation_type !== "undefined" && this.annotation_type ? this.media.getAnnotationsByTypeTitle(this.annotation_type) : this.media.getAnnotations(); |
| 876 | 125 |
} |
126 |
||
| 922 | 127 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() { |
| 957 | 128 |
var _time = this.media.getCurrentTime(); |
| 922 | 129 |
return this.getWidgetAnnotations().filter(function(_annotation) { |
130 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
131 |
}); |
|
132 |
} |
|
133 |
||
| 959 | 134 |
IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _widgetoptions, _propname) { |
| 924 | 135 |
var _id = _selector.attr("id"), |
| 927 | 136 |
_this = this, |
137 |
_type = _widgetoptions.type, |
|
138 |
$L = $LAB; |
|
| 924 | 139 |
if (typeof _id == "undefined") { |
140 |
_id = IriSP._.uniqueId(this.container + '_sub_widget_' + _widgetoptions.type); |
|
141 |
_selector.attr("id", _id); |
|
142 |
} |
|
143 |
_widgetoptions.container = _id; |
|
| 927 | 144 |
if (typeof IriSP.widgetsRequirements[_type] !== "undefined" && typeof IriSP.widgetsRequirements[_type].requires !== "undefined" ) { |
145 |
for (var _j = 0; _j < IriSP.widgetsRequirements[_type].requires.length; _j++) { |
|
146 |
$L.script(IriSP.getLib(IriSP.widgetsRequirements[_type].requires[_j])); |
|
147 |
} |
|
148 |
} |
|
149 |
$L.wait(function() { |
|
150 |
_this.player.loadWidget(_widgetoptions, function(_widget) { |
|
| 959 | 151 |
if (_propname) { |
152 |
_this[_propname] = _widget; |
|
153 |
} |
|
| 927 | 154 |
}); |
| 924 | 155 |
}); |
156 |
} |
|
157 |
||
|
520
fe008e95a716
added jsdoc support, and a script to generate the docs.
hamidouk
parents:
287
diff
changeset
|
158 |
/** |
| 868 | 159 |
* This method responsible of drawing a widget on screen. |
160 |
*/ |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
161 |
IriSP.Widgets.Widget.prototype.draw = function() { |
| 868 | 162 |
/* implemented by "sub-classes" */ |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
900
diff
changeset
|
163 |
}; |