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