|
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 ", |
|
923
|
16 |
tags_: "Mots-clés :", |
|
|
17 |
description_: "Description :", |
|
902
|
18 |
excerpt_from: "Extrait de :" |
|
876
|
19 |
}, |
|
923
|
20 |
en: { |
|
876
|
21 |
watching: "I'm watching ", |
|
|
22 |
on_site: " on ", |
|
923
|
23 |
tags_: "Keywords:", |
|
|
24 |
description_: "Description:", |
|
902
|
25 |
excerpt_from: "Excerpt from:" |
|
876
|
26 |
} |
|
|
27 |
} |
|
|
28 |
|
|
|
29 |
IriSP.Widgets.Annotation.prototype.template = |
|
|
30 |
'<div class="Ldt-Annotation-Widget {{#show_top_border}}Ldt-Annotation-ShowTop{{/show_top_border}}">' |
|
923
|
31 |
+ '<div class="Ldt-Annotation-Inner Ldt-Annotation-Empty{{#start_minimized}} Ldt-Annotation-Minimized{{/start_minimized}}">' |
|
|
32 |
+ '<div class="Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-MaxMinButton"></div>' |
|
925
|
33 |
+ '<div class="Ldt-Annotation-Social Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty"></div>' |
|
923
|
34 |
+ '<h3 class="Ldt-Annotation-HiddenWhenEmpty"><span class="Ldt-Annotation-Title"></span> <span class="Ldt-Annotation-Time">' |
|
|
35 |
+ '( <span class="Ldt-Annotation-Begin"></span> - <span class="Ldt-Annotation-End"></span> )</span></h3>' |
|
|
36 |
+ '<h3 class="Ldt-Annotation-MashupOrigin Ldt-Annotation-HiddenWhenEmpty">{{l10n.excerpt_from}} <span class="Ldt-Annotation-MashupMedia"></span> <span class="Ldt-Annotation-Time">' |
|
|
37 |
+ '( <span class="Ldt-Annotation-MashupBegin"></span> - <span class="Ldt-Annotation-MashupEnd"></span> )</span></h3>' |
|
|
38 |
+ '<div class="Ldt-Annotation-Cleared Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-Description-Block"><div class="Ldt-Annotation-Label">{{l10n.description_}}</div>' |
|
|
39 |
+ '<p class="Ldt-Annotation-Labelled Ldt-Annotation-Description"></p></div>' |
|
|
40 |
+ '<div class="Ldt-Annotation-Tags-Block Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-Cleared">' |
|
|
41 |
+ '<div class="Ldt-Annotation-Label">{{l10n.tags_}}</div><ul class="Ldt-Annotation-Labelled Ldt-Annotation-Tags"></ul>' |
|
924
|
42 |
+ '</div></div></div></div>'; |
|
876
|
43 |
|
|
|
44 |
IriSP.Widgets.Annotation.prototype.defaults = { |
|
|
45 |
annotation_type : "chap", |
|
924
|
46 |
start_minimized: true, |
|
876
|
47 |
show_top_border : false, |
|
|
48 |
site_name : "Lignes de Temps" |
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
IriSP.Widgets.Annotation.prototype.draw = function() { |
|
|
52 |
this.renderTemplate(); |
|
924
|
53 |
this.insertSubwidget(this.$.find(".Ldt-Annotation-Social"), "socialWidget", { type: "Social" }); |
|
957
|
54 |
this.onMediaEvent("timeupdate","onTimeupdate"); |
|
|
55 |
this.onMdpEvent("Annotation.hide","hide"); |
|
|
56 |
this.onMdpEvent("Annotation.show","show"); |
|
|
57 |
this.onMdpEvent("Annotation.minimize","minimize"); |
|
|
58 |
this.onMdpEvent("Annotation.maximize","maximize"); |
|
|
59 |
this.onMdpEvent("Annotation.getBounds","sendBounds"); |
|
923
|
60 |
this.$.find(".Ldt-Annotation-MaxMinButton").click(this.functionWrapper("toggleSize")); |
|
876
|
61 |
this.onTimeupdate(); |
|
|
62 |
} |
|
|
63 |
|
|
957
|
64 |
IriSP.Widgets.Annotation.prototype.onTimeupdate = function(_time) { |
|
|
65 |
var _list = this.getWidgetAnnotationsAtTime(); |
|
876
|
66 |
if (_list.length) { |
|
|
67 |
if (_list[0].id !== this.lastAnnotation) { |
|
|
68 |
this.drawAnnotation(_list[0]); |
|
923
|
69 |
this.bounds = [ _list[0].begin.valueOf(), _list[0].end.valueOf() ]; |
|
876
|
70 |
} |
|
957
|
71 |
this.player.trigger("Arrow.updatePosition",{widget: this.type, time: ( _list[0].begin + _list[0].end ) / 2}); |
|
876
|
72 |
} |
|
|
73 |
else { |
|
880
|
74 |
this.lastAnnotation = false; |
|
|
75 |
this.$.find(".Ldt-Annotation-Inner").addClass("Ldt-Annotation-Empty"); |
|
957
|
76 |
this.player.trigger("Arrow.updatePosition",{widget: this.type, time: _time}); |
|
923
|
77 |
this.bounds = [ _time, _time ]; |
|
876
|
78 |
} |
|
923
|
79 |
this.sendBounds(); |
|
|
80 |
} |
|
|
81 |
|
|
|
82 |
IriSP.Widgets.Annotation.prototype.sendBounds = function() { |
|
957
|
83 |
this.player.trigger("Annotation.boundsChanged",this.bounds); |
|
876
|
84 |
} |
|
|
85 |
|
|
|
86 |
IriSP.Widgets.Annotation.prototype.drawAnnotation = function(_annotation) { |
|
|
87 |
this.lastAnnotation = _annotation.id; |
|
|
88 |
var _url = (typeof _annotation.url !== "undefined" |
|
|
89 |
? _annotation.url |
|
916
|
90 |
: (document.location.href.replace(/#.*$/,'') + '#id=' + _annotation.id)); |
|
880
|
91 |
var _text = this.l10n.watching + _annotation.title + (this.site_name ? this.l10n.on_site + this.site_name : ''); |
|
|
92 |
var _tags = _annotation.getTagTexts(); |
|
|
93 |
if (_tags.length) { |
|
|
94 |
var _html = IriSP._(_tags).map(function(_tag) { |
|
902
|
95 |
return '<li class="Ldt-Annotation-TagLabel"><span>' + _tag + '</span></li>'; |
|
880
|
96 |
}).join(""); |
|
|
97 |
this.$.find(".Ldt-Annotation-Tags").html(_html); |
|
924
|
98 |
this.$.find(".Ldt-Annotation-Tags-Block").removeClass("Ldt-Annotation-EmptyBlock"); |
|
904
|
99 |
|
|
|
100 |
/* Correct the empty tag bug */ |
|
|
101 |
this.$.find('.Ldt-Annotation-TagLabel').each(function() { |
|
|
102 |
var _el = IriSP.jQuery(this); |
|
|
103 |
if (!_el.text().replace(/(^\s+|\s+$)/g,'')) { |
|
|
104 |
_el.detach(); |
|
|
105 |
} |
|
|
106 |
}); |
|
|
107 |
|
|
|
108 |
this.$.find('.Ldt-Annotation-TagLabel').click(function() { |
|
957
|
109 |
_this.player.trigger("search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
|
904
|
110 |
}); |
|
880
|
111 |
} else { |
|
924
|
112 |
this.$.find(".Ldt-Annotation-Tags-Block").addClass("Ldt-Annotation-EmptyBlock"); |
|
880
|
113 |
} |
|
|
114 |
this.$.find(".Ldt-Annotation-Title").html(_annotation.title); |
|
923
|
115 |
var _desc = _annotation.description.replace(/(^\s+|\s+$)/g,''); |
|
|
116 |
if (_desc) { |
|
924
|
117 |
this.$.find(".Ldt-Annotation-Description-Block").removeClass("Ldt-Annotation-EmptyBlock"); |
|
923
|
118 |
this.$.find(".Ldt-Annotation-Description").html(_desc); |
|
|
119 |
} else { |
|
924
|
120 |
this.$.find(".Ldt-Annotation-Description-Block").addClass("Ldt-Annotation-EmptyBlock"); |
|
923
|
121 |
} |
|
880
|
122 |
this.$.find(".Ldt-Annotation-Begin").html(_annotation.begin.toString()); |
|
|
123 |
this.$.find(".Ldt-Annotation-End").html(_annotation.end.toString()); |
|
902
|
124 |
if (_annotation.elementType === "mashedAnnotation") { |
|
|
125 |
this.$.find('.Ldt-Annotation-Inner').addClass("Ldt-Annotation-isMashup"); |
|
|
126 |
this.$.find(".Ldt-Annotation-MashupMedia").html(_annotation.getMedia().title); |
|
|
127 |
this.$.find(".Ldt-Annotation-MashupBegin").html(_annotation.annotation.begin.toString()); |
|
|
128 |
this.$.find(".Ldt-Annotation-MashupEnd").html(_annotation.annotation.end.toString()); |
|
|
129 |
} else { |
|
|
130 |
this.$.find('.Ldt-Annotation-Inner').removeClass("Ldt-Annotation-isMashup"); |
|
|
131 |
} |
|
924
|
132 |
if (typeof this.socialWidget !== "undefined") { |
|
|
133 |
this.socialWidget.updateUrls(_url, _text); |
|
927
|
134 |
} else { |
|
|
135 |
var _this = this; |
|
|
136 |
setTimeout(function() { |
|
|
137 |
if (typeof _this.socialWidget !== "undefined") { |
|
|
138 |
_this.socialWidget.updateUrls(_url, _text); |
|
|
139 |
} |
|
|
140 |
},800); |
|
924
|
141 |
} |
|
880
|
142 |
this.$.find(".Ldt-Annotation-Inner").removeClass("Ldt-Annotation-Empty"); |
|
876
|
143 |
} |
|
880
|
144 |
|
|
|
145 |
IriSP.Widgets.Annotation.prototype.hide = function() { |
|
|
146 |
this.$.slideUp(); |
|
|
147 |
} |
|
|
148 |
|
|
|
149 |
IriSP.Widgets.Annotation.prototype.show = function() { |
|
|
150 |
this.$.slideDown(); |
|
|
151 |
} |
|
|
152 |
|
|
923
|
153 |
IriSP.Widgets.Annotation.prototype.toggleSize = function() { |
|
|
154 |
if (this.minimized) { |
|
|
155 |
this.maximize(); |
|
|
156 |
} else { |
|
|
157 |
this.minimize(); |
|
|
158 |
} |
|
|
159 |
} |
|
|
160 |
|
|
880
|
161 |
IriSP.Widgets.Annotation.prototype.minimize = function() { |
|
923
|
162 |
this.minimized = true; |
|
880
|
163 |
this.$.find('.Ldt-Annotation-Inner').addClass("Ldt-Annotation-Minimized"); |
|
|
164 |
} |
|
|
165 |
|
|
|
166 |
IriSP.Widgets.Annotation.prototype.maximize = function() { |
|
923
|
167 |
this.minimized = false; |
|
880
|
168 |
this.$.find('.Ldt-Annotation-Inner').removeClass("Ldt-Annotation-Minimized"); |
|
|
169 |
} |