| author | ymh <ymh.work@gmail.com> |
| Fri, 02 Oct 2015 11:27:17 +0200 | |
| changeset 1068 | 7623f9af9272 |
| parent 1033 | c20df1c080e6 |
| child 1072 | ac1eacb3aa33 |
| permissions | -rw-r--r-- |
| 924 | 1 |
// TODO: Migrate Timeupdate functions to Extract |
| 876 | 2 |
|
3 |
IriSP.Widgets.Annotation = function(player, config) { |
|
4 |
IriSP.Widgets.Widget.call(this, player, config); |
|
5 |
this.lastAnnotation = false; |
|
| 923 | 6 |
this.minimized = this.start_minimized || false; |
7 |
this.bounds = [ 0, 0 ]; |
|
| 876 | 8 |
}; |
9 |
||
10 |
IriSP.Widgets.Annotation.prototype = new IriSP.Widgets.Widget(); |
|
11 |
||
12 |
IriSP.Widgets.Annotation.prototype.messages = { |
|
| 923 | 13 |
fr: { |
| 876 | 14 |
watching: "Je regarde ", |
15 |
on_site: " sur ", |
|
| 1002 | 16 |
tags_: "Mots-clés\u00a0:", |
17 |
description_: "Description\u00a0:", |
|
| 1009 | 18 |
creator_: "Créé par\u00a0:", |
| 1002 | 19 |
excerpt_from: "Extrait de\u00a0:", |
| 982 | 20 |
untitled: "Segment sans titre" |
| 876 | 21 |
}, |
| 923 | 22 |
en: { |
| 876 | 23 |
watching: "I'm watching ", |
24 |
on_site: " on ", |
|
| 923 | 25 |
tags_: "Keywords:", |
26 |
description_: "Description:", |
|
| 1009 | 27 |
creator_: "Created by\u00a0:", |
| 982 | 28 |
excerpt_from: "Excerpt from:", |
29 |
untitled: "Untitled segment" |
|
| 876 | 30 |
} |
| 1013 | 31 |
}; |
| 876 | 32 |
|
33 |
IriSP.Widgets.Annotation.prototype.template = |
|
| 965 | 34 |
'{{#show_arrow}}<div class="Ldt-Annotation-Arrow"></div>{{/show_arrow}}' |
35 |
+ '<div class="Ldt-Annotation-Widget {{^show_arrow}}Ldt-Annotation-ShowTop{{/show_arrow}}">' |
|
| 923 | 36 |
+ '<div class="Ldt-Annotation-Inner Ldt-Annotation-Empty{{#start_minimized}} Ldt-Annotation-Minimized{{/start_minimized}}">' |
37 |
+ '<div class="Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-MaxMinButton"></div>' |
|
| 982 | 38 |
+ '{{#show_social}}<div class="Ldt-Annotation-Social Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty"></div>{{/show_social}}' |
| 1007 | 39 |
+ '<h3 class="Ldt-Annotation-HiddenWhenEmpty">{{#show_annotation_type}}<span class="Ldt-Annotation-Type"></span> » {{/show_annotation_type}}<a class="Ldt-Annotation-Title" href="#"></a> <span class="Ldt-Annotation-Time Ldt-Annotation-HiddenWhenMinimized">' |
| 982 | 40 |
+ '(<span class="Ldt-Annotation-Begin"></span> - <span class="Ldt-Annotation-End"></span>)</span></h3>' |
41 |
+ '<h3 class="Ldt-Annotation-MashupOrigin Ldt-Annotation-HiddenWhenEmpty">{{l10n.excerpt_from}} <span class="Ldt-Annotation-MashupMedia"></span> <span class="Ldt-Annotation-Time Ldt-Annotation-HiddenWhenMinimized">' |
|
42 |
+ '(<span class="Ldt-Annotation-MashupBegin"></span> - <span class="Ldt-Annotation-MashupEnd"></span>)</span></h3>' |
|
| 1009 | 43 |
+ '<div class="Ldt-Annotation-Cleared Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-Creator-Block"><div class="Ldt-Annotation-Label">{{l10n.creator_}}</div>' |
| 1033 | 44 |
+ '{{#show_creator}}<p class="Ldt-Annotation-Labelled Ldt-Annotation-Creator"></p></div>{{/show_creator}}' |
45 |
+ '{{#show_description}}<div class="Ldt-Annotation-Cleared Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-Description-Block"><div class="Ldt-Annotation-Label">{{l10n.description_}}</div>' |
|
46 |
+ '<p class="Ldt-Annotation-Labelled Ldt-Annotation-Description"></p></div>{{/show_description}}' |
|
| 923 | 47 |
+ '<div class="Ldt-Annotation-Tags-Block Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-Cleared">' |
48 |
+ '<div class="Ldt-Annotation-Label">{{l10n.tags_}}</div><ul class="Ldt-Annotation-Labelled Ldt-Annotation-Tags"></ul>' |
|
| 924 | 49 |
+ '</div></div></div></div>'; |
| 876 | 50 |
|
51 |
IriSP.Widgets.Annotation.prototype.defaults = { |
|
52 |
annotation_type : "chap", |
|
| 965 | 53 |
start_minimized: false, |
54 |
show_arrow : true, |
|
| 1009 | 55 |
show_creator: true, |
| 1033 | 56 |
show_description: true, |
| 1004 | 57 |
arrow_position: .5, |
| 964 | 58 |
site_name : "Lignes de Temps", |
| 982 | 59 |
search_on_tag_click: true, |
60 |
show_social: true, |
|
61 |
show_annotation_type: false |
|
| 1013 | 62 |
}; |
| 876 | 63 |
|
64 |
IriSP.Widgets.Annotation.prototype.draw = function() { |
|
| 965 | 65 |
|
| 983 | 66 |
var _this = this, |
67 |
currentAnnotation; |
|
| 965 | 68 |
|
69 |
function timeupdate(_time) { |
|
70 |
var _list = _this.getWidgetAnnotationsAtTime(); |
|
71 |
if (!_list.length) { |
|
72 |
_this.$.find(".Ldt-Annotation-Inner").addClass("Ldt-Annotation-Empty"); |
|
73 |
if (_this.arrow) { |
|
74 |
_this.arrow.moveToTime(_time); |
|
75 |
} |
|
76 |
_this.bounds = [ _time, _time ]; |
|
77 |
_this.sendBounds(); |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
| 983 | 81 |
function highlightTitleAndDescription() { |
82 |
if (!currentAnnotation) { |
|
83 |
return; |
|
84 |
} |
|
85 |
var title = currentAnnotation.title, |
|
|
988
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
985
diff
changeset
|
86 |
description = currentAnnotation.description.replace(/(^\s+|\s+$)/g,''), |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
985
diff
changeset
|
87 |
rx = (currentAnnotation.found ? (_this.source.getAnnotations().regexp || false) : false); |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
985
diff
changeset
|
88 |
_this.$.find(".Ldt-Annotation-Title").html(IriSP.textFieldHtml(title,rx) || "(" + _this.l10n.untitled + ")"); |
| 983 | 89 |
if (description) { |
90 |
_this.$.find(".Ldt-Annotation-Description-Block").removeClass("Ldt-Annotation-EmptyBlock"); |
|
|
988
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
985
diff
changeset
|
91 |
_this.$.find(".Ldt-Annotation-Description").html(IriSP.textFieldHtml(description,rx)); |
| 983 | 92 |
} else { |
93 |
_this.$.find(".Ldt-Annotation-Description-Block").addClass("Ldt-Annotation-EmptyBlock"); |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
| 965 | 97 |
function drawAnnotation(_annotation) { |
| 983 | 98 |
currentAnnotation = _annotation; |
| 965 | 99 |
var _url = (typeof _annotation.url !== "undefined" |
100 |
? _annotation.url |
|
101 |
: (document.location.href.replace(/#.*$/,'') + '#id=' + _annotation.id)), |
|
102 |
_text = _this.l10n.watching + _annotation.title + (_this.site_name ? _this.l10n.on_site + _this.site_name : ''), |
|
103 |
_tags = _annotation.getTags(), |
|
104 |
_tagblock = _this.$.find(".Ldt-Annotation-Tags"); |
|
| 985 | 105 |
_tagblock.empty(); |
| 965 | 106 |
if (_tags.length) { |
107 |
_this.$.find(".Ldt-Annotation-Tags-Block").removeClass("Ldt-Annotation-EmptyBlock"); |
|
108 |
_tags.forEach(function(_tag) { |
|
109 |
var _trimmedTitle = _tag.title.replace(/(^\s+|\s+$)/g,''); |
|
110 |
if (_trimmedTitle) { |
|
111 |
var _el = IriSP.jQuery('<li class="Ldt-Annotation-TagLabel"></li>').append(IriSP.jQuery('<span>').text(_trimmedTitle)); |
|
112 |
_el.click(function() { |
|
113 |
if (_this.search_on_tag_click) { |
|
| 983 | 114 |
_this.source.getAnnotations().search(_trimmedTitle); |
| 965 | 115 |
} |
116 |
_tag.trigger("click"); |
|
117 |
}); |
|
118 |
_tagblock.append(_el); |
|
119 |
} |
|
120 |
}); |
|
121 |
} else { |
|
122 |
_this.$.find(".Ldt-Annotation-Tags-Block").addClass("Ldt-Annotation-EmptyBlock"); |
|
123 |
} |
|
| 983 | 124 |
highlightTitleAndDescription(); |
| 1009 | 125 |
if (_this.show_creator) { |
126 |
_this.$.find(".Ldt-Annotation-Creator").text(_annotation.creator); |
|
127 |
} |
|
| 982 | 128 |
if (_this.show_annotation_type) { |
| 1013 | 129 |
_this.$.find(".Ldt-Annotation-Type").text(_annotation.getAnnotationType().title); |
| 1025 | 130 |
_this.$.find(".Ldt-Annotation-Type").attr("title", _annotation.getAnnotationType().description); |
| 982 | 131 |
} |
132 |
_this.$.find(".Ldt-Annotation-Begin").text(_annotation.begin.toString()); |
|
133 |
_this.$.find(".Ldt-Annotation-End").text(_annotation.end.toString()); |
|
| 965 | 134 |
if (_annotation.elementType === "mashedAnnotation") { |
135 |
_this.$.find('.Ldt-Annotation-Inner').addClass("Ldt-Annotation-isMashup"); |
|
| 982 | 136 |
_this.$.find(".Ldt-Annotation-MashupMedia").text(_annotation.getMedia().title); |
137 |
_this.$.find(".Ldt-Annotation-MashupBegin").text(_annotation.annotation.begin.toString()); |
|
138 |
_this.$.find(".Ldt-Annotation-MashupEnd").text(_annotation.annotation.end.toString()); |
|
| 965 | 139 |
} else { |
140 |
_this.$.find('.Ldt-Annotation-Inner').removeClass("Ldt-Annotation-isMashup"); |
|
141 |
} |
|
142 |
if (typeof _this.socialWidget !== "undefined") { |
|
143 |
_this.socialWidget.updateUrls(_url, _text); |
|
144 |
} else { |
|
145 |
setTimeout(function() { |
|
146 |
if (typeof _this.socialWidget !== "undefined") { |
|
147 |
_this.socialWidget.updateUrls(_url, _text); |
|
148 |
} |
|
149 |
},800); |
|
150 |
} |
|
151 |
_this.$.find(".Ldt-Annotation-Inner").removeClass("Ldt-Annotation-Empty"); |
|
152 |
_this.bounds = [ _annotation.begin, _annotation.end ]; |
|
153 |
if (_this.arrow) { |
|
| 1004 | 154 |
_this.arrow.moveToTime((1 - _this.arrow_position) * _annotation.begin + _this.arrow_position * _annotation.end); |
| 965 | 155 |
} |
156 |
_this.sendBounds(); |
|
157 |
} |
|
158 |
|
|
| 876 | 159 |
this.renderTemplate(); |
| 982 | 160 |
|
| 1007 | 161 |
this.$.find(".Ldt-Annotation-Title").click(function() { |
162 |
if (currentAnnotation) { |
|
163 |
_this.media.setCurrentTime(currentAnnotation.begin); |
|
164 |
} |
|
165 |
return false; |
|
166 |
}); |
|
167 |
|
|
| 983 | 168 |
if (this.show_social) { |
| 982 | 169 |
this.insertSubwidget(this.$.find(".Ldt-Annotation-Social"), { type: "Social" }, "socialWidget"); |
170 |
} |
|
171 |
|
|
| 1004 | 172 |
if (this.show_arrow) { |
173 |
this.insertSubwidget(this.$.find(".Ldt-Annotation-Arrow"), { type: "Arrow", width: this.width }, "arrow"); |
|
174 |
} |
|
| 965 | 175 |
this.onMediaEvent("timeupdate",timeupdate); |
| 957 | 176 |
this.onMdpEvent("Annotation.hide","hide"); |
177 |
this.onMdpEvent("Annotation.show","show"); |
|
178 |
this.onMdpEvent("Annotation.minimize","minimize"); |
|
179 |
this.onMdpEvent("Annotation.maximize","maximize"); |
|
180 |
this.onMdpEvent("Annotation.getBounds","sendBounds"); |
|
| 923 | 181 |
this.$.find(".Ldt-Annotation-MaxMinButton").click(this.functionWrapper("toggleSize")); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
182 |
this.$.on("resize", function () { _this.width = _this.$.parent().width(); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
183 |
_this.$.css({ width: _this.width }); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
184 |
}); |
| 965 | 185 |
this.getWidgetAnnotations().forEach(function(_a) { |
186 |
_a.on("enter", function() { |
|
| 1013 | 187 |
drawAnnotation(_a); |
| 965 | 188 |
}); |
189 |
}); |
|
| 983 | 190 |
this.source.getAnnotations().on("found", highlightTitleAndDescription); |
191 |
this.source.getAnnotations().on("not-found", highlightTitleAndDescription); |
|
192 |
this.source.getAnnotations().on("search-cleared", highlightTitleAndDescription); |
|
|
996
c472984db275
refactored drag-and-drop interface (IE Compatibility)
veltr
parents:
994
diff
changeset
|
193 |
IriSP.attachDndData(this.$.find("h3"), function() { |
|
c472984db275
refactored drag-and-drop interface (IE Compatibility)
veltr
parents:
994
diff
changeset
|
194 |
return { |
|
c472984db275
refactored drag-and-drop interface (IE Compatibility)
veltr
parents:
994
diff
changeset
|
195 |
title: currentAnnotation.title, |
|
c472984db275
refactored drag-and-drop interface (IE Compatibility)
veltr
parents:
994
diff
changeset
|
196 |
description: currentAnnotation.description, |
|
c472984db275
refactored drag-and-drop interface (IE Compatibility)
veltr
parents:
994
diff
changeset
|
197 |
image: currentAnnotation.thumbnail, |
|
c472984db275
refactored drag-and-drop interface (IE Compatibility)
veltr
parents:
994
diff
changeset
|
198 |
uri: (typeof currentAnnotation.url !== "undefined" |
|
c472984db275
refactored drag-and-drop interface (IE Compatibility)
veltr
parents:
994
diff
changeset
|
199 |
? currentAnnotation.url |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
200 |
: (document.location.href.replace(/#.*$/,'') + '#id=' + currentAnnotation.id)), |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
201 |
text: '[' + currentAnnotation.begin.toString() + '] ' + currentAnnotation.title |
| 1013 | 202 |
}; |
| 993 | 203 |
}); |
| 1013 | 204 |
}; |
| 923 | 205 |
|
206 |
IriSP.Widgets.Annotation.prototype.sendBounds = function() { |
|
| 957 | 207 |
this.player.trigger("Annotation.boundsChanged",this.bounds); |
| 1013 | 208 |
}; |
| 876 | 209 |
|
210 |
IriSP.Widgets.Annotation.prototype.drawAnnotation = function(_annotation) { |
|
211 |
this.lastAnnotation = _annotation.id; |
|
| 965 | 212 |
|
| 1013 | 213 |
}; |
| 880 | 214 |
|
215 |
IriSP.Widgets.Annotation.prototype.hide = function() { |
|
216 |
this.$.slideUp(); |
|
| 1013 | 217 |
}; |
| 880 | 218 |
|
219 |
IriSP.Widgets.Annotation.prototype.show = function() { |
|
220 |
this.$.slideDown(); |
|
| 1013 | 221 |
}; |
| 880 | 222 |
|
| 923 | 223 |
IriSP.Widgets.Annotation.prototype.toggleSize = function() { |
224 |
if (this.minimized) { |
|
225 |
this.maximize(); |
|
226 |
} else { |
|
227 |
this.minimize(); |
|
228 |
} |
|
| 1013 | 229 |
}; |
| 923 | 230 |
|
| 880 | 231 |
IriSP.Widgets.Annotation.prototype.minimize = function() { |
| 923 | 232 |
this.minimized = true; |
| 880 | 233 |
this.$.find('.Ldt-Annotation-Inner').addClass("Ldt-Annotation-Minimized"); |
| 1013 | 234 |
}; |
| 880 | 235 |
|
236 |
IriSP.Widgets.Annotation.prototype.maximize = function() { |
|
| 923 | 237 |
this.minimized = false; |
| 880 | 238 |
this.$.find('.Ldt-Annotation-Inner').removeClass("Ldt-Annotation-Minimized"); |
| 1033 | 239 |
}; |