| author | veltr |
| Mon, 17 Sep 2012 22:44:59 +0900 | |
| branch | players-as-widgets |
| changeset 958 | 2aa7fdb0762a |
| parent 957 | 4da0a5740b6c |
| child 959 | ee11ed1b739e |
| 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() { |
|
| 957 | 50 |
_this.media = this.getCurrentMedia(); |
| 868 | 51 |
_this.draw(); |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
52 |
}); |
| 868 | 53 |
|
54 |
/* Adding classes and html attributes */ |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
55 |
this.$ = IriSP.jQuery('#' + this.container); |
|
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 |
|
|
66
13013b9452af
Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff
changeset
|
68 |
}; |
| 74 | 69 |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
70 |
IriSP.Widgets.Widget.prototype.defaults = {} |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
71 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
72 |
IriSP.Widgets.Widget.prototype.template = ''; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
73 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
74 |
IriSP.Widgets.Widget.prototype.messages = {"en":{}}; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
75 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
76 |
IriSP.Widgets.Widget.prototype.templateToHtml = function(_template) { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
77 |
return Mustache.to_html(_template, this); |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
78 |
} |
|
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.renderTemplate = function() { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
81 |
this.$.append(this.templateToHtml(this.template)); |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
82 |
} |
|
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.functionWrapper = function(_name) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
85 |
var _this = this, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
86 |
_function = this[_name]; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
87 |
if (typeof _function !== "undefined") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
88 |
return function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
89 |
return _function.apply(_this, Array.prototype.slice.call(arguments, 0)); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
90 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
91 |
} else { |
| 957 | 92 |
console.log("Error, Unknown function IriSP.Widgets" + this.type + "." + _name) |
93 |
} |
|
94 |
} |
|
95 |
||
96 |
IriSP.Widgets.Widget.prototype.getFunctionOrName = function(_functionOrName) { |
|
97 |
switch (typeof _functionOrName) { |
|
98 |
case "function": |
|
99 |
return _functionOrName; |
|
100 |
case "string": |
|
101 |
return this.functionWrapper(_functionOrName); |
|
102 |
default: |
|
103 |
return undefined; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
104 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
105 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
106 |
|
| 957 | 107 |
IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) { |
108 |
this.player.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
109 |
} |
|
110 |
||
111 |
IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) { |
|
112 |
if (typeof this.media === "undefined" || typeof this.media.on === "undefined") { |
|
113 |
console.log("Error on widget "+this.type, this.media); |
|
114 |
} |
|
115 |
this.media.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
116 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
117 |
|
| 876 | 118 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { |
| 957 | 119 |
return typeof this.annotation_type !== "undefined" && this.annotation_type ? this.media.getAnnotationsByTypeTitle(this.annotation_type) : this.media.getAnnotations(); |
| 876 | 120 |
} |
121 |
||
| 922 | 122 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() { |
| 957 | 123 |
var _time = this.media.getCurrentTime(); |
| 922 | 124 |
return this.getWidgetAnnotations().filter(function(_annotation) { |
125 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
126 |
}); |
|
127 |
} |
|
128 |
||
| 924 | 129 |
IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _propname, _widgetoptions) { |
130 |
var _id = _selector.attr("id"), |
|
| 927 | 131 |
_this = this, |
132 |
_type = _widgetoptions.type, |
|
133 |
$L = $LAB; |
|
| 924 | 134 |
if (typeof _id == "undefined") { |
135 |
_id = IriSP._.uniqueId(this.container + '_sub_widget_' + _widgetoptions.type); |
|
136 |
_selector.attr("id", _id); |
|
137 |
} |
|
138 |
_widgetoptions.container = _id; |
|
| 927 | 139 |
if (typeof IriSP.widgetsRequirements[_type] !== "undefined" && typeof IriSP.widgetsRequirements[_type].requires !== "undefined" ) { |
140 |
for (var _j = 0; _j < IriSP.widgetsRequirements[_type].requires.length; _j++) { |
|
141 |
$L.script(IriSP.getLib(IriSP.widgetsRequirements[_type].requires[_j])); |
|
142 |
} |
|
143 |
} |
|
144 |
$L.wait(function() { |
|
145 |
_this.player.loadWidget(_widgetoptions, function(_widget) { |
|
146 |
_this[_propname] = _widget; |
|
147 |
}); |
|
| 924 | 148 |
}); |
149 |
} |
|
150 |
||
|
520
fe008e95a716
added jsdoc support, and a script to generate the docs.
hamidouk
parents:
287
diff
changeset
|
151 |
/** |
| 868 | 152 |
* This method responsible of drawing a widget on screen. |
153 |
*/ |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
154 |
IriSP.Widgets.Widget.prototype.draw = function() { |
| 868 | 155 |
/* implemented by "sub-classes" */ |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
900
diff
changeset
|
156 |
}; |