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