| author | ymh <ymh.work@gmail.com> |
| Fri, 02 Oct 2015 11:27:17 +0200 | |
| changeset 1068 | 7623f9af9272 |
| parent 1049 | 4e8b3df6e5be |
| child 1072 | ac1eacb3aa33 |
| 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) { |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
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 |
} |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
26 |
|
| 984 | 27 |
this.__subwidgets = []; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
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; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
33 |
|
| 868 | 34 |
IriSP._(_config).forEach(function(_value, _key) { |
35 |
_this[_key] = _value; |
|
36 |
}); |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
37 |
|
|
988
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
986
diff
changeset
|
38 |
this.$ = IriSP.jQuery('#' + this.container); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
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 |
} |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
45 |
|
| 992 | 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 |
} |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
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"]); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
54 |
|
| 868 | 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); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
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 |
); |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
67 |
|
| 986 | 68 |
/* Loading Metadata if required */ |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
69 |
|
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
70 |
function onsourceloaded() { |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
71 |
if (_this.localannotations) { |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
72 |
_this.localsource = player.loadLocalAnnotations(_this.localannotations); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
73 |
_this.source.merge(_this.localsource); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
74 |
} |
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
75 |
if (_this.media_id) { |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
76 |
_this.media = this.getElement(_this.media_id); |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
77 |
} else { |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
78 |
var _mediaopts = { |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
79 |
is_mashup: _this.is_mashup || false |
| 1013 | 80 |
}; |
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
81 |
_this.media = _this.source.getCurrentMedia(_mediaopts); |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
82 |
} |
|
1049
4e8b3df6e5be
Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents:
1033
diff
changeset
|
83 |
if (_this.pre_draw_callback){ |
|
4e8b3df6e5be
Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents:
1033
diff
changeset
|
84 |
IriSP.jQuery.when(_this.pre_draw_callback()).done(_this.draw()); |
|
4e8b3df6e5be
Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents:
1033
diff
changeset
|
85 |
} |
|
4e8b3df6e5be
Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents:
1033
diff
changeset
|
86 |
else { |
|
4e8b3df6e5be
Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents:
1033
diff
changeset
|
87 |
_this.draw(); |
|
4e8b3df6e5be
Added support for running a function before the draw() function of a widget, for example when a widget needs to fetch additional user informations that aren't provided by the metadatas
durandn
parents:
1033
diff
changeset
|
88 |
} |
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
89 |
_this.player.trigger("widget-loaded"); |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
90 |
} |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
91 |
|
| 986 | 92 |
if (this.metadata) { |
93 |
/* Getting metadata */ |
|
94 |
this.source = player.loadMetadata(this.metadata); |
|
95 |
/* Call draw when loaded */ |
|
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
96 |
this.source.onLoad(onsourceloaded); |
| 986 | 97 |
} else { |
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
98 |
if (this.source) { |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
99 |
onsourceloaded(); |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
100 |
} |
| 986 | 101 |
} |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
102 |
|
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
103 |
|
|
66
13013b9452af
Added a new file to the build, widgets.js, to contain widget classes.
hamidouk
parents:
diff
changeset
|
104 |
}; |
| 74 | 105 |
|
| 998 | 106 |
IriSP.Widgets.Widget.prototype.defaults = {}; |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
107 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
108 |
IriSP.Widgets.Widget.prototype.template = ''; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
109 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
110 |
IriSP.Widgets.Widget.prototype.messages = {"en":{}}; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
111 |
|
|
1001
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
112 |
IriSP.Widgets.Widget.prototype.toString = function() { |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
113 |
return "Widget " + this.type; |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
114 |
}; |
|
3210bf928a11
Enabled loading widgets without the widgeting framework
veltr
parents:
998
diff
changeset
|
115 |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
116 |
IriSP.Widgets.Widget.prototype.templateToHtml = function(_template) { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
117 |
return Mustache.to_html(_template, this); |
| 998 | 118 |
}; |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
119 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
120 |
IriSP.Widgets.Widget.prototype.renderTemplate = function() { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
121 |
this.$.append(this.templateToHtml(this.template)); |
| 998 | 122 |
}; |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
123 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
124 |
IriSP.Widgets.Widget.prototype.functionWrapper = function(_name) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
125 |
var _this = this, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
126 |
_function = this[_name]; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
127 |
if (typeof _function !== "undefined") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
128 |
return function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
129 |
return _function.apply(_this, Array.prototype.slice.call(arguments, 0)); |
| 1013 | 130 |
}; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
131 |
} else { |
| 1013 | 132 |
console.log("Error, Unknown function IriSP.Widgets." + this.type + "." + _name); |
| 957 | 133 |
} |
| 998 | 134 |
}; |
| 957 | 135 |
|
136 |
IriSP.Widgets.Widget.prototype.getFunctionOrName = function(_functionOrName) { |
|
137 |
switch (typeof _functionOrName) { |
|
138 |
case "function": |
|
139 |
return _functionOrName; |
|
140 |
case "string": |
|
141 |
return this.functionWrapper(_functionOrName); |
|
142 |
default: |
|
143 |
return undefined; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
144 |
} |
| 998 | 145 |
}; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
146 |
|
| 957 | 147 |
IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) { |
148 |
this.player.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
| 998 | 149 |
}; |
| 957 | 150 |
|
151 |
IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) { |
|
152 |
this.media.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
| 998 | 153 |
}; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
154 |
|
| 876 | 155 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { |
| 1033 | 156 |
var result = null; |
| 982 | 157 |
if (typeof this.annotation_type === "undefined") { |
| 1033 | 158 |
result = this.media.getAnnotations(); |
159 |
} else if (this.annotation_type.elementType === "annotationType") { |
|
160 |
result = this.annotation_type.getAnnotations(); |
|
161 |
} else { |
|
162 |
result = this.media.getAnnotationsByTypeTitle(this.annotation_type); |
|
| 982 | 163 |
} |
| 1033 | 164 |
if (typeof this.annotation_filter !== "undefined") { |
165 |
return this.annotation_filter(result); |
|
166 |
} else { |
|
167 |
return result; |
|
| 982 | 168 |
} |
| 998 | 169 |
}; |
| 876 | 170 |
|
| 922 | 171 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() { |
| 957 | 172 |
var _time = this.media.getCurrentTime(); |
| 922 | 173 |
return this.getWidgetAnnotations().filter(function(_annotation) { |
174 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
175 |
}); |
|
| 998 | 176 |
}; |
| 922 | 177 |
|
| 984 | 178 |
IriSP.Widgets.Widget.prototype.isLoaded = function() { |
179 |
var isloaded = !IriSP._(this.__subwidgets).any(function(w) { |
|
180 |
return !(w && w.isLoaded()); |
|
181 |
}); |
|
182 |
return isloaded; |
|
| 998 | 183 |
}; |
| 984 | 184 |
|
| 959 | 185 |
IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _widgetoptions, _propname) { |
| 924 | 186 |
var _id = _selector.attr("id"), |
| 927 | 187 |
_this = this, |
188 |
_type = _widgetoptions.type, |
|
| 984 | 189 |
$L = $LAB, |
190 |
key = this.__subwidgets.length; |
|
191 |
this.__subwidgets.push(null); |
|
| 924 | 192 |
if (typeof _id == "undefined") { |
193 |
_id = IriSP._.uniqueId(this.container + '_sub_widget_' + _widgetoptions.type); |
|
194 |
_selector.attr("id", _id); |
|
195 |
} |
|
196 |
_widgetoptions.container = _id; |
|
| 927 | 197 |
if (typeof IriSP.widgetsRequirements[_type] !== "undefined" && typeof IriSP.widgetsRequirements[_type].requires !== "undefined" ) { |
198 |
for (var _j = 0; _j < IriSP.widgetsRequirements[_type].requires.length; _j++) { |
|
199 |
$L.script(IriSP.getLib(IriSP.widgetsRequirements[_type].requires[_j])); |
|
200 |
} |
|
201 |
} |
|
202 |
$L.wait(function() { |
|
203 |
_this.player.loadWidget(_widgetoptions, function(_widget) { |
|
| 959 | 204 |
if (_propname) { |
205 |
_this[_propname] = _widget; |
|
206 |
} |
|
| 984 | 207 |
_this.__subwidgets[key] = _widget; |
| 927 | 208 |
}); |
| 924 | 209 |
}); |
| 998 | 210 |
}; |
| 924 | 211 |
|
| 1033 | 212 |
/* |
213 |
* Position the player to the next/previous annotations based on current player position |
|
214 |
* |
|
215 |
* Parameter: offset: -1 for previous annotation, +1 for next annotation |
|
216 |
*/ |
|
217 |
IriSP.Widgets.Widget.prototype.navigate = function(offset) { |
|
218 |
// offset is normally either -1 (previous slide) or +1 (next slide) |
|
219 |
var _this = this; |
|
220 |
var currentTime = _this.media.getCurrentTime(); |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
221 |
var annotations = _this.getWidgetAnnotations().sortBy(function(_annotation) { |
| 1033 | 222 |
return _annotation.begin; |
223 |
}); |
|
224 |
for (var i = 0; i < annotations.length; i++) { |
|
225 |
if (annotations[i].begin <= currentTime && currentTime < annotations[i].end) { |
|
226 |
// Found a current annotation - clamp i+offset value to [0, length - 1] |
|
227 |
i = Math.min(annotations.length - 1, Math.max(0, i + offset)); |
|
228 |
_this.media.setCurrentTime(annotations[i].begin); |
|
229 |
break; |
|
230 |
} |
|
231 |
}; |
|
232 |
}; |
|
233 |
||
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
234 |
/* |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
235 |
* Propose an export of the widget's annotations |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
236 |
* |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
237 |
* Parameter: a list of annotations. If not specified, the widget's annotations will be exported. |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
238 |
*/ |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
239 |
IriSP.Widgets.Widget.prototype.exportAnnotations = function(annotations) { |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
240 |
var widget = this; |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
241 |
if (annotations === undefined) |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
242 |
annotations = this.getWidgetAnnotations(); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
243 |
var $ = IriSP.jQuery; |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
244 |
|
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
245 |
// FIXME: this should belong to a proper serialize/deserialize component? |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
246 |
var content = Mustache.to_html("[video:{{url}}]\n", {url: widget.media.url}) + annotations.map( function(a) { return Mustache.to_html("[{{ a.begin }}]{{ a.title }} {{ a.description }}[{{ a.end }}]", { a: a }); }).join("\n"); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
247 |
|
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
248 |
var el = $("<pre>") |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
249 |
.addClass("exportContainer") |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
250 |
.text(content) |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
251 |
.dialog({ |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
252 |
title: "Annotation export", |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
253 |
open: function( event, ui ) { |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
254 |
// Select text |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
255 |
var range; |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
256 |
if (document.selection) { |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
257 |
range = document.body.createTextRange(); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
258 |
range.moveToElementText(this[0]); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
259 |
range.select(); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
260 |
} else if (window.getSelection) { |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
261 |
range = document.createRange(); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
262 |
range.selectNode(this[0]); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
263 |
window.getSelection().addRange(range); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
264 |
} |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
265 |
}, |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
266 |
autoOpen: true, |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
267 |
width: '80%', |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
268 |
minHeight: '400', |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
269 |
height: 400, |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
270 |
buttons: [ { text: "Close", click: function() { $( this ).dialog( "close" ); } }, |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
271 |
{ text: "Download", click: function () { |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
272 |
a = document.createElement('a'); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
273 |
a.setAttribute('href', 'data:text/plain;base64,' + btoa(content)); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
274 |
a.setAttribute('download', 'Annotations - ' + widget.media.title.replace(/[^ \w]/g, '') + '.txt'); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
275 |
a.click(); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
276 |
} } ] |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
277 |
}); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1049
diff
changeset
|
278 |
}; |
| 1033 | 279 |
|
|
520
fe008e95a716
added jsdoc support, and a script to generate the docs.
hamidouk
parents:
287
diff
changeset
|
280 |
/** |
| 868 | 281 |
* This method responsible of drawing a widget on screen. |
282 |
*/ |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
874
diff
changeset
|
283 |
IriSP.Widgets.Widget.prototype.draw = function() { |
| 868 | 284 |
/* implemented by "sub-classes" */ |
| 1033 | 285 |
}; |