| author | Raphael Velt <raph.velt@gmail.com> |
| Tue, 23 Jul 2013 13:14:21 +0200 | |
| changeset 940 | 843f96e4eebd |
| parent 828 | 6030bef81a51 |
| child 955 | 5171f8825985 |
| permissions | -rw-r--r-- |
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1 |
// TODO: Migrate Timeupdate functions to Extract |
| 598 | 2 |
|
3 |
IriSP.Widgets.Annotation = function(player, config) { |
|
4 |
IriSP.Widgets.Widget.call(this, player, config); |
|
5 |
this.lastAnnotation = false; |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
6 |
this.minimized = this.start_minimized || false; |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
7 |
this.bounds = [ 0, 0 ]; |
| 598 | 8 |
}; |
9 |
||
10 |
IriSP.Widgets.Annotation.prototype = new IriSP.Widgets.Widget(); |
|
11 |
||
12 |
IriSP.Widgets.Annotation.prototype.messages = { |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
13 |
fr: { |
| 598 | 14 |
watching: "Je regarde ", |
15 |
on_site: " sur ", |
|
| 940 | 16 |
tags_: "Mots-clés\u00a0:", |
17 |
description_: "Description\u00a0:", |
|
18 |
excerpt_from: "Extrait de\u00a0:", |
|
| 719 | 19 |
untitled: "Segment sans titre" |
| 598 | 20 |
}, |
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
21 |
en: { |
| 598 | 22 |
watching: "I'm watching ", |
23 |
on_site: " on ", |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
24 |
tags_: "Keywords:", |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
25 |
description_: "Description:", |
| 719 | 26 |
excerpt_from: "Excerpt from:", |
27 |
untitled: "Untitled segment" |
|
| 598 | 28 |
} |
29 |
} |
|
30 |
||
31 |
IriSP.Widgets.Annotation.prototype.template = |
|
| 694 | 32 |
'{{#show_arrow}}<div class="Ldt-Annotation-Arrow"></div>{{/show_arrow}}' |
33 |
+ '<div class="Ldt-Annotation-Widget {{^show_arrow}}Ldt-Annotation-ShowTop{{/show_arrow}}">' |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
34 |
+ '<div class="Ldt-Annotation-Inner Ldt-Annotation-Empty{{#start_minimized}} Ldt-Annotation-Minimized{{/start_minimized}}">' |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
35 |
+ '<div class="Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-MaxMinButton"></div>' |
| 719 | 36 |
+ '{{#show_social}}<div class="Ldt-Annotation-Social Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty"></div>{{/show_social}}' |
| 940 | 37 |
+ '<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">' |
| 719 | 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>' |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
41 |
+ '<div class="Ldt-Annotation-Cleared Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-Description-Block"><div class="Ldt-Annotation-Label">{{l10n.description_}}</div>' |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
42 |
+ '<p class="Ldt-Annotation-Labelled Ldt-Annotation-Description"></p></div>' |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
43 |
+ '<div class="Ldt-Annotation-Tags-Block Ldt-Annotation-HiddenWhenMinimized Ldt-Annotation-HiddenWhenEmpty Ldt-Annotation-Cleared">' |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
44 |
+ '<div class="Ldt-Annotation-Label">{{l10n.tags_}}</div><ul class="Ldt-Annotation-Labelled Ldt-Annotation-Tags"></ul>' |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
45 |
+ '</div></div></div></div>'; |
| 598 | 46 |
|
47 |
IriSP.Widgets.Annotation.prototype.defaults = { |
|
48 |
annotation_type : "chap", |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
49 |
start_minimized: false, |
| 694 | 50 |
show_arrow : true, |
| 940 | 51 |
arrow_position: .5, |
| 694 | 52 |
site_name : "Lignes de Temps", |
| 719 | 53 |
search_on_tag_click: true, |
54 |
show_social: true, |
|
55 |
show_annotation_type: false |
|
| 598 | 56 |
} |
57 |
||
58 |
IriSP.Widgets.Annotation.prototype.draw = function() { |
|
| 694 | 59 |
|
| 719 | 60 |
var _this = this, |
61 |
currentAnnotation; |
|
| 694 | 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 |
|
|
| 719 | 75 |
function highlightTitleAndDescription() { |
76 |
if (!currentAnnotation) { |
|
77 |
return; |
|
78 |
} |
|
79 |
var title = currentAnnotation.title, |
|
| 778 | 80 |
description = currentAnnotation.description.replace(/(^\s+|\s+$)/g,''), |
81 |
rx = (currentAnnotation.found ? (_this.source.getAnnotations().regexp || false) : false); |
|
82 |
_this.$.find(".Ldt-Annotation-Title").html(IriSP.textFieldHtml(title,rx) || "(" + _this.l10n.untitled + ")"); |
|
| 719 | 83 |
if (description) { |
84 |
_this.$.find(".Ldt-Annotation-Description-Block").removeClass("Ldt-Annotation-EmptyBlock"); |
|
| 778 | 85 |
_this.$.find(".Ldt-Annotation-Description").html(IriSP.textFieldHtml(description,rx)); |
| 719 | 86 |
} else { |
87 |
_this.$.find(".Ldt-Annotation-Description-Block").addClass("Ldt-Annotation-EmptyBlock"); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
| 694 | 91 |
function drawAnnotation(_annotation) { |
| 719 | 92 |
currentAnnotation = _annotation; |
| 694 | 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"); |
|
| 726 | 99 |
_tagblock.empty(); |
| 694 | 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) { |
|
| 719 | 108 |
_this.source.getAnnotations().search(_trimmedTitle); |
| 694 | 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 |
} |
|
| 719 | 118 |
highlightTitleAndDescription(); |
119 |
if (_this.show_annotation_type) { |
|
120 |
_this.$.find(".Ldt-Annotation-Type").text(_annotation.getAnnotationType().title) |
|
| 694 | 121 |
} |
| 719 | 122 |
_this.$.find(".Ldt-Annotation-Begin").text(_annotation.begin.toString()); |
123 |
_this.$.find(".Ldt-Annotation-End").text(_annotation.end.toString()); |
|
| 694 | 124 |
if (_annotation.elementType === "mashedAnnotation") { |
125 |
_this.$.find('.Ldt-Annotation-Inner').addClass("Ldt-Annotation-isMashup"); |
|
| 719 | 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()); |
|
| 694 | 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) { |
|
| 940 | 144 |
_this.arrow.moveToTime((1 - _this.arrow_position) * _annotation.begin + _this.arrow_position * _annotation.end); |
| 694 | 145 |
} |
146 |
_this.sendBounds(); |
|
147 |
} |
|
148 |
|
|
| 598 | 149 |
this.renderTemplate(); |
| 719 | 150 |
|
| 940 | 151 |
this.$.find(".Ldt-Annotation-Title").click(function() { |
152 |
if (currentAnnotation) { |
|
153 |
_this.media.setCurrentTime(currentAnnotation.begin); |
|
154 |
} |
|
155 |
return false; |
|
156 |
}); |
|
157 |
|
|
| 719 | 158 |
if (this.show_social) { |
159 |
this.insertSubwidget(this.$.find(".Ldt-Annotation-Social"), { type: "Social" }, "socialWidget"); |
|
160 |
} |
|
161 |
|
|
| 940 | 162 |
if (this.show_arrow) { |
163 |
this.insertSubwidget(this.$.find(".Ldt-Annotation-Arrow"), { type: "Arrow", width: this.width }, "arrow"); |
|
164 |
} |
|
| 694 | 165 |
this.onMediaEvent("timeupdate",timeupdate); |
166 |
this.onMdpEvent("Annotation.hide","hide"); |
|
167 |
this.onMdpEvent("Annotation.show","show"); |
|
168 |
this.onMdpEvent("Annotation.minimize","minimize"); |
|
169 |
this.onMdpEvent("Annotation.maximize","maximize"); |
|
170 |
this.onMdpEvent("Annotation.getBounds","sendBounds"); |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
171 |
this.$.find(".Ldt-Annotation-MaxMinButton").click(this.functionWrapper("toggleSize")); |
| 694 | 172 |
this.getWidgetAnnotations().forEach(function(_a) { |
173 |
_a.on("enter", function() { |
|
174 |
drawAnnotation(_a) |
|
175 |
}); |
|
176 |
}); |
|
| 719 | 177 |
this.source.getAnnotations().on("found", highlightTitleAndDescription); |
178 |
this.source.getAnnotations().on("not-found", highlightTitleAndDescription); |
|
179 |
this.source.getAnnotations().on("search-cleared", highlightTitleAndDescription); |
|
| 828 | 180 |
IriSP.attachDndData(this.$.find("h3"), function() { |
181 |
return { |
|
182 |
title: currentAnnotation.title, |
|
183 |
description: currentAnnotation.description, |
|
184 |
image: currentAnnotation.thumbnail, |
|
185 |
uri: (typeof currentAnnotation.url !== "undefined" |
|
186 |
? currentAnnotation.url |
|
187 |
: (document.location.href.replace(/#.*$/,'') + '#id=' + currentAnnotation.id)) |
|
188 |
} |
|
|
792
66ae5723b2de
Drag and drop for Renkan
Raphael Velt <raph.velt@gmail.com>
parents:
778
diff
changeset
|
189 |
}); |
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
190 |
} |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
191 |
|
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
192 |
IriSP.Widgets.Annotation.prototype.sendBounds = function() { |
| 694 | 193 |
this.player.trigger("Annotation.boundsChanged",this.bounds); |
| 598 | 194 |
} |
195 |
||
196 |
IriSP.Widgets.Annotation.prototype.drawAnnotation = function(_annotation) { |
|
197 |
this.lastAnnotation = _annotation.id; |
|
| 694 | 198 |
|
| 598 | 199 |
} |
200 |
||
201 |
IriSP.Widgets.Annotation.prototype.hide = function() { |
|
202 |
this.$.slideUp(); |
|
203 |
} |
|
204 |
||
205 |
IriSP.Widgets.Annotation.prototype.show = function() { |
|
206 |
this.$.slideDown(); |
|
207 |
} |
|
208 |
||
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
209 |
IriSP.Widgets.Annotation.prototype.toggleSize = function() { |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
210 |
if (this.minimized) { |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
211 |
this.maximize(); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
212 |
} else { |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
213 |
this.minimize(); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
214 |
} |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
215 |
} |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
216 |
|
| 598 | 217 |
IriSP.Widgets.Annotation.prototype.minimize = function() { |
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
218 |
this.minimized = true; |
| 598 | 219 |
this.$.find('.Ldt-Annotation-Inner').addClass("Ldt-Annotation-Minimized"); |
220 |
} |
|
221 |
||
222 |
IriSP.Widgets.Annotation.prototype.maximize = function() { |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
223 |
this.minimized = false; |
| 598 | 224 |
this.$.find('.Ldt-Annotation-Inner').removeClass("Ldt-Annotation-Minimized"); |
225 |
} |