11 |
11 |
12 IriSP.Widgets.Annotation.prototype.messages = { |
12 IriSP.Widgets.Annotation.prototype.messages = { |
13 fr: { |
13 fr: { |
14 watching: "Je regarde ", |
14 watching: "Je regarde ", |
15 on_site: " sur ", |
15 on_site: " sur ", |
16 tags_: "Mots-clés\u00a0:", |
16 tags_: "Mots-clés :", |
17 description_: "Description\u00a0:", |
17 description_: "Description :", |
18 creator_: "Créé par\u00a0:", |
18 excerpt_from: "Extrait de :" |
19 excerpt_from: "Extrait de\u00a0:", |
|
20 untitled: "Segment sans titre" |
|
21 }, |
19 }, |
22 en: { |
20 en: { |
23 watching: "I'm watching ", |
21 watching: "I'm watching ", |
24 on_site: " on ", |
22 on_site: " on ", |
25 tags_: "Keywords:", |
23 tags_: "Keywords:", |
26 description_: "Description:", |
24 description_: "Description:", |
27 creator_: "Created by\u00a0:", |
25 excerpt_from: "Excerpt from:" |
28 excerpt_from: "Excerpt from:", |
|
29 untitled: "Untitled segment" |
|
30 } |
26 } |
31 }; |
27 } |
32 |
28 |
33 IriSP.Widgets.Annotation.prototype.template = |
29 IriSP.Widgets.Annotation.prototype.template = |
34 '{{#show_arrow}}<div class="Ldt-Annotation-Arrow"></div>{{/show_arrow}}' |
30 '<div class="Ldt-Annotation-Widget {{#show_top_border}}Ldt-Annotation-ShowTop{{/show_top_border}}">' |
35 + '<div class="Ldt-Annotation-Widget {{^show_arrow}}Ldt-Annotation-ShowTop{{/show_arrow}}">' |
|
36 + '<div class="Ldt-Annotation-Inner Ldt-Annotation-Empty{{#start_minimized}} Ldt-Annotation-Minimized{{/start_minimized}}">' |
31 + '<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>' |
32 + '<div class="Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-MaxMinButton"></div>' |
38 + '{{#show_social}}<div class="Ldt-Annotation-Social Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty"></div>{{/show_social}}' |
33 + '<div class="Ldt-Annotation-Social Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty"></div>' |
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">' |
34 + '<h3 class="Ldt-Annotation-HiddenWhenEmpty"><span class="Ldt-Annotation-Title"></span> <span class="Ldt-Annotation-Time">' |
40 + '(<span class="Ldt-Annotation-Begin"></span> - <span class="Ldt-Annotation-End"></span>)</span></h3>' |
35 + '( <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">' |
36 + '<h3 class="Ldt-Annotation-MashupOrigin Ldt-Annotation-HiddenWhenEmpty">{{l10n.excerpt_from}} <span class="Ldt-Annotation-MashupMedia"></span> <span class="Ldt-Annotation-Time">' |
42 + '(<span class="Ldt-Annotation-MashupBegin"></span> - <span class="Ldt-Annotation-MashupEnd"></span>)</span></h3>' |
37 + '( <span class="Ldt-Annotation-MashupBegin"></span> - <span class="Ldt-Annotation-MashupEnd"></span> )</span></h3>' |
43 + '<div class="Ldt-Annotation-Cleared Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-Creator-Block"><div class="Ldt-Annotation-Label">{{l10n.creator_}}</div>' |
38 + '<div class="Ldt-Annotation-Cleared Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-Description-Block"><div class="Ldt-Annotation-Label">{{l10n.description_}}</div>' |
44 + '{{#show_creator}}<p class="Ldt-Annotation-Labelled Ldt-Annotation-Creator"></p></div>' |
|
45 + '<div class="Ldt-Annotation-Cleared Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-Description-Block"><div class="Ldt-Annotation-Label">{{l10n.description_}}</div>{{/show_creator}}' |
|
46 + '<p class="Ldt-Annotation-Labelled Ldt-Annotation-Description"></p></div>' |
39 + '<p class="Ldt-Annotation-Labelled Ldt-Annotation-Description"></p></div>' |
47 + '<div class="Ldt-Annotation-Tags-Block Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-Cleared">' |
40 + '<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>' |
41 + '<div class="Ldt-Annotation-Label">{{l10n.tags_}}</div><ul class="Ldt-Annotation-Labelled Ldt-Annotation-Tags"></ul>' |
49 + '</div></div></div></div>'; |
42 + '</div></div></div></div>'; |
50 |
43 |
51 IriSP.Widgets.Annotation.prototype.defaults = { |
44 IriSP.Widgets.Annotation.prototype.defaults = { |
52 annotation_type : "chap", |
45 annotation_type : "chap", |
53 start_minimized: false, |
46 start_minimized: true, |
54 show_arrow : true, |
47 show_top_border : false, |
55 show_creator: true, |
48 site_name : "Lignes de Temps" |
56 arrow_position: .5, |
49 } |
57 site_name : "Lignes de Temps", |
|
58 search_on_tag_click: true, |
|
59 show_social: true, |
|
60 show_annotation_type: false |
|
61 }; |
|
62 |
50 |
63 IriSP.Widgets.Annotation.prototype.draw = function() { |
51 IriSP.Widgets.Annotation.prototype.draw = function() { |
64 |
52 this.renderTemplate(); |
65 var _this = this, |
53 this.insertSubwidget(this.$.find(".Ldt-Annotation-Social"), "socialWidget", { type: "Social" }); |
66 currentAnnotation; |
54 this.bindPopcorn("timeupdate","onTimeupdate"); |
67 |
55 this.bindPopcorn("IriSP.Annotation.hide","hide"); |
68 function timeupdate(_time) { |
56 this.bindPopcorn("IriSP.Annotation.show","show"); |
69 var _list = _this.getWidgetAnnotationsAtTime(); |
57 this.bindPopcorn("IriSP.Annotation.minimize","minimize"); |
70 if (!_list.length) { |
58 this.bindPopcorn("IriSP.Annotation.maximize","maximize"); |
71 _this.$.find(".Ldt-Annotation-Inner").addClass("Ldt-Annotation-Empty"); |
59 this.bindPopcorn("IriSP.Annotation.getBounds","sendBounds"); |
72 if (_this.arrow) { |
60 this.$.find(".Ldt-Annotation-MaxMinButton").click(this.functionWrapper("toggleSize")); |
73 _this.arrow.moveToTime(_time); |
61 this.onTimeupdate(); |
74 } |
62 } |
75 _this.bounds = [ _time, _time ]; |
63 |
76 _this.sendBounds(); |
64 IriSP.Widgets.Annotation.prototype.onTimeupdate = function() { |
|
65 var _time = Math.floor(this.player.popcorn.currentTime() * 1000), |
|
66 _list = this.getWidgetAnnotationsAtTime(); |
|
67 if (_list.length) { |
|
68 if (_list[0].id !== this.lastAnnotation) { |
|
69 this.drawAnnotation(_list[0]); |
|
70 this.bounds = [ _list[0].begin.valueOf(), _list[0].end.valueOf() ]; |
77 } |
71 } |
|
72 this.player.popcorn.trigger("IriSP.Arrow.updatePosition",{widget: this.type, time: ( _list[0].begin + _list[0].end ) / 2}); |
78 } |
73 } |
79 |
74 else { |
80 function highlightTitleAndDescription() { |
75 this.lastAnnotation = false; |
81 if (!currentAnnotation) { |
76 this.$.find(".Ldt-Annotation-Inner").addClass("Ldt-Annotation-Empty"); |
82 return; |
77 this.player.popcorn.trigger("IriSP.Arrow.updatePosition",{widget: this.type, time: _time}); |
83 } |
78 this.bounds = [ _time, _time ]; |
84 var title = currentAnnotation.title, |
|
85 description = currentAnnotation.description.replace(/(^\s+|\s+$)/g,''), |
|
86 rx = (currentAnnotation.found ? (_this.source.getAnnotations().regexp || false) : false); |
|
87 _this.$.find(".Ldt-Annotation-Title").html(IriSP.textFieldHtml(title,rx) || "(" + _this.l10n.untitled + ")"); |
|
88 if (description) { |
|
89 _this.$.find(".Ldt-Annotation-Description-Block").removeClass("Ldt-Annotation-EmptyBlock"); |
|
90 _this.$.find(".Ldt-Annotation-Description").html(IriSP.textFieldHtml(description,rx)); |
|
91 } else { |
|
92 _this.$.find(".Ldt-Annotation-Description-Block").addClass("Ldt-Annotation-EmptyBlock"); |
|
93 } |
|
94 } |
79 } |
95 |
80 this.sendBounds(); |
96 function drawAnnotation(_annotation) { |
81 } |
97 currentAnnotation = _annotation; |
|
98 var _url = (typeof _annotation.url !== "undefined" |
|
99 ? _annotation.url |
|
100 : (document.location.href.replace(/#.*$/,'') + '#id=' + _annotation.id)), |
|
101 _text = _this.l10n.watching + _annotation.title + (_this.site_name ? _this.l10n.on_site + _this.site_name : ''), |
|
102 _tags = _annotation.getTags(), |
|
103 _tagblock = _this.$.find(".Ldt-Annotation-Tags"); |
|
104 _tagblock.empty(); |
|
105 if (_tags.length) { |
|
106 _this.$.find(".Ldt-Annotation-Tags-Block").removeClass("Ldt-Annotation-EmptyBlock"); |
|
107 _tags.forEach(function(_tag) { |
|
108 var _trimmedTitle = _tag.title.replace(/(^\s+|\s+$)/g,''); |
|
109 if (_trimmedTitle) { |
|
110 var _el = IriSP.jQuery('<li class="Ldt-Annotation-TagLabel"></li>').append(IriSP.jQuery('<span>').text(_trimmedTitle)); |
|
111 _el.click(function() { |
|
112 if (_this.search_on_tag_click) { |
|
113 _this.source.getAnnotations().search(_trimmedTitle); |
|
114 } |
|
115 _tag.trigger("click"); |
|
116 }); |
|
117 _tagblock.append(_el); |
|
118 } |
|
119 }); |
|
120 } else { |
|
121 _this.$.find(".Ldt-Annotation-Tags-Block").addClass("Ldt-Annotation-EmptyBlock"); |
|
122 } |
|
123 highlightTitleAndDescription(); |
|
124 if (_this.show_creator) { |
|
125 _this.$.find(".Ldt-Annotation-Creator").text(_annotation.creator); |
|
126 } |
|
127 if (_this.show_annotation_type) { |
|
128 _this.$.find(".Ldt-Annotation-Type").text(_annotation.getAnnotationType().title); |
|
129 } |
|
130 _this.$.find(".Ldt-Annotation-Begin").text(_annotation.begin.toString()); |
|
131 _this.$.find(".Ldt-Annotation-End").text(_annotation.end.toString()); |
|
132 if (_annotation.elementType === "mashedAnnotation") { |
|
133 _this.$.find('.Ldt-Annotation-Inner').addClass("Ldt-Annotation-isMashup"); |
|
134 _this.$.find(".Ldt-Annotation-MashupMedia").text(_annotation.getMedia().title); |
|
135 _this.$.find(".Ldt-Annotation-MashupBegin").text(_annotation.annotation.begin.toString()); |
|
136 _this.$.find(".Ldt-Annotation-MashupEnd").text(_annotation.annotation.end.toString()); |
|
137 } else { |
|
138 _this.$.find('.Ldt-Annotation-Inner').removeClass("Ldt-Annotation-isMashup"); |
|
139 } |
|
140 if (typeof _this.socialWidget !== "undefined") { |
|
141 _this.socialWidget.updateUrls(_url, _text); |
|
142 } else { |
|
143 setTimeout(function() { |
|
144 if (typeof _this.socialWidget !== "undefined") { |
|
145 _this.socialWidget.updateUrls(_url, _text); |
|
146 } |
|
147 },800); |
|
148 } |
|
149 _this.$.find(".Ldt-Annotation-Inner").removeClass("Ldt-Annotation-Empty"); |
|
150 _this.bounds = [ _annotation.begin, _annotation.end ]; |
|
151 if (_this.arrow) { |
|
152 _this.arrow.moveToTime((1 - _this.arrow_position) * _annotation.begin + _this.arrow_position * _annotation.end); |
|
153 } |
|
154 _this.sendBounds(); |
|
155 } |
|
156 |
|
157 this.renderTemplate(); |
|
158 |
|
159 this.$.find(".Ldt-Annotation-Title").click(function() { |
|
160 if (currentAnnotation) { |
|
161 _this.media.setCurrentTime(currentAnnotation.begin); |
|
162 } |
|
163 return false; |
|
164 }); |
|
165 |
|
166 if (this.show_social) { |
|
167 this.insertSubwidget(this.$.find(".Ldt-Annotation-Social"), { type: "Social" }, "socialWidget"); |
|
168 } |
|
169 |
|
170 if (this.show_arrow) { |
|
171 this.insertSubwidget(this.$.find(".Ldt-Annotation-Arrow"), { type: "Arrow", width: this.width }, "arrow"); |
|
172 } |
|
173 this.onMediaEvent("timeupdate",timeupdate); |
|
174 this.onMdpEvent("Annotation.hide","hide"); |
|
175 this.onMdpEvent("Annotation.show","show"); |
|
176 this.onMdpEvent("Annotation.minimize","minimize"); |
|
177 this.onMdpEvent("Annotation.maximize","maximize"); |
|
178 this.onMdpEvent("Annotation.getBounds","sendBounds"); |
|
179 this.$.find(".Ldt-Annotation-MaxMinButton").click(this.functionWrapper("toggleSize")); |
|
180 this.getWidgetAnnotations().forEach(function(_a) { |
|
181 _a.on("enter", function() { |
|
182 drawAnnotation(_a); |
|
183 }); |
|
184 }); |
|
185 this.source.getAnnotations().on("found", highlightTitleAndDescription); |
|
186 this.source.getAnnotations().on("not-found", highlightTitleAndDescription); |
|
187 this.source.getAnnotations().on("search-cleared", highlightTitleAndDescription); |
|
188 IriSP.attachDndData(this.$.find("h3"), function() { |
|
189 return { |
|
190 title: currentAnnotation.title, |
|
191 description: currentAnnotation.description, |
|
192 image: currentAnnotation.thumbnail, |
|
193 uri: (typeof currentAnnotation.url !== "undefined" |
|
194 ? currentAnnotation.url |
|
195 : (document.location.href.replace(/#.*$/,'') + '#id=' + currentAnnotation.id)) |
|
196 }; |
|
197 }); |
|
198 }; |
|
199 |
82 |
200 IriSP.Widgets.Annotation.prototype.sendBounds = function() { |
83 IriSP.Widgets.Annotation.prototype.sendBounds = function() { |
201 this.player.trigger("Annotation.boundsChanged",this.bounds); |
84 this.player.popcorn.trigger("IriSP.Annotation.boundsChanged",this.bounds); |
202 }; |
85 } |
203 |
86 |
204 IriSP.Widgets.Annotation.prototype.drawAnnotation = function(_annotation) { |
87 IriSP.Widgets.Annotation.prototype.drawAnnotation = function(_annotation) { |
205 this.lastAnnotation = _annotation.id; |
88 this.lastAnnotation = _annotation.id; |
206 |
89 var _url = (typeof _annotation.url !== "undefined" |
207 }; |
90 ? _annotation.url |
|
91 : (document.location.href.replace(/#.*$/,'') + '#id=' + _annotation.id)); |
|
92 var _text = this.l10n.watching + _annotation.title + (this.site_name ? this.l10n.on_site + this.site_name : ''); |
|
93 var _tags = _annotation.getTagTexts(); |
|
94 if (_tags.length) { |
|
95 var _html = IriSP._(_tags).map(function(_tag) { |
|
96 return '<li class="Ldt-Annotation-TagLabel"><span>' + _tag + '</span></li>'; |
|
97 }).join(""); |
|
98 this.$.find(".Ldt-Annotation-Tags").html(_html); |
|
99 this.$.find(".Ldt-Annotation-Tags-Block").removeClass("Ldt-Annotation-EmptyBlock"); |
|
100 |
|
101 /* Correct the empty tag bug */ |
|
102 this.$.find('.Ldt-Annotation-TagLabel').each(function() { |
|
103 var _el = IriSP.jQuery(this); |
|
104 if (!_el.text().replace(/(^\s+|\s+$)/g,'')) { |
|
105 _el.detach(); |
|
106 } |
|
107 }); |
|
108 |
|
109 this.$.find('.Ldt-Annotation-TagLabel').click(function() { |
|
110 _this.player.popcorn.trigger("IriSP.search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
|
111 }); |
|
112 } else { |
|
113 this.$.find(".Ldt-Annotation-Tags-Block").addClass("Ldt-Annotation-EmptyBlock"); |
|
114 } |
|
115 this.$.find(".Ldt-Annotation-Title").html(_annotation.title); |
|
116 var _desc = _annotation.description.replace(/(^\s+|\s+$)/g,''); |
|
117 if (_desc) { |
|
118 this.$.find(".Ldt-Annotation-Description-Block").removeClass("Ldt-Annotation-EmptyBlock"); |
|
119 this.$.find(".Ldt-Annotation-Description").html(_desc); |
|
120 } else { |
|
121 this.$.find(".Ldt-Annotation-Description-Block").addClass("Ldt-Annotation-EmptyBlock"); |
|
122 } |
|
123 this.$.find(".Ldt-Annotation-Begin").html(_annotation.begin.toString()); |
|
124 this.$.find(".Ldt-Annotation-End").html(_annotation.end.toString()); |
|
125 if (_annotation.elementType === "mashedAnnotation") { |
|
126 this.$.find('.Ldt-Annotation-Inner').addClass("Ldt-Annotation-isMashup"); |
|
127 this.$.find(".Ldt-Annotation-MashupMedia").html(_annotation.getMedia().title); |
|
128 this.$.find(".Ldt-Annotation-MashupBegin").html(_annotation.annotation.begin.toString()); |
|
129 this.$.find(".Ldt-Annotation-MashupEnd").html(_annotation.annotation.end.toString()); |
|
130 } else { |
|
131 this.$.find('.Ldt-Annotation-Inner').removeClass("Ldt-Annotation-isMashup"); |
|
132 } |
|
133 if (typeof this.socialWidget !== "undefined") { |
|
134 this.socialWidget.updateUrls(_url, _text); |
|
135 } else { |
|
136 var _this = this; |
|
137 setTimeout(function() { |
|
138 if (typeof _this.socialWidget !== "undefined") { |
|
139 _this.socialWidget.updateUrls(_url, _text); |
|
140 } |
|
141 },800); |
|
142 } |
|
143 this.$.find(".Ldt-Annotation-Inner").removeClass("Ldt-Annotation-Empty"); |
|
144 } |
208 |
145 |
209 IriSP.Widgets.Annotation.prototype.hide = function() { |
146 IriSP.Widgets.Annotation.prototype.hide = function() { |
210 this.$.slideUp(); |
147 this.$.slideUp(); |
211 }; |
148 } |
212 |
149 |
213 IriSP.Widgets.Annotation.prototype.show = function() { |
150 IriSP.Widgets.Annotation.prototype.show = function() { |
214 this.$.slideDown(); |
151 this.$.slideDown(); |
215 }; |
152 } |
216 |
153 |
217 IriSP.Widgets.Annotation.prototype.toggleSize = function() { |
154 IriSP.Widgets.Annotation.prototype.toggleSize = function() { |
218 if (this.minimized) { |
155 if (this.minimized) { |
219 this.maximize(); |
156 this.maximize(); |
220 } else { |
157 } else { |
221 this.minimize(); |
158 this.minimize(); |
222 } |
159 } |
223 }; |
160 } |
224 |
161 |
225 IriSP.Widgets.Annotation.prototype.minimize = function() { |
162 IriSP.Widgets.Annotation.prototype.minimize = function() { |
226 this.minimized = true; |
163 this.minimized = true; |
227 this.$.find('.Ldt-Annotation-Inner').addClass("Ldt-Annotation-Minimized"); |
164 this.$.find('.Ldt-Annotation-Inner').addClass("Ldt-Annotation-Minimized"); |
228 }; |
165 } |
229 |
166 |
230 IriSP.Widgets.Annotation.prototype.maximize = function() { |
167 IriSP.Widgets.Annotation.prototype.maximize = function() { |
231 this.minimized = false; |
168 this.minimized = false; |
232 this.$.find('.Ldt-Annotation-Inner').removeClass("Ldt-Annotation-Minimized"); |
169 this.$.find('.Ldt-Annotation-Inner').removeClass("Ldt-Annotation-Minimized"); |
233 }; |
170 } |