| author | Raphael Velt <raph.velt@gmail.com> |
| Fri, 25 Jan 2013 18:49:33 +0100 | |
| changeset 778 | 525f00c2d6ac |
| parent 726 | d82d070cf23e |
| child 792 | 66ae5723b2de |
| 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 ", |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
16 |
tags_: "Mots-clés :", |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
17 |
description_: "Description :", |
| 719 | 18 |
excerpt_from: "Extrait de :", |
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}}' |
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">' |
|
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, |
51 |
site_name : "Lignes de Temps", |
|
| 719 | 52 |
search_on_tag_click: true, |
53 |
show_social: true, |
|
54 |
show_annotation_type: false |
|
| 598 | 55 |
} |
56 |
||
57 |
IriSP.Widgets.Annotation.prototype.draw = function() { |
|
| 694 | 58 |
|
| 719 | 59 |
var _this = this, |
60 |
currentAnnotation; |
|
| 694 | 61 |
|
62 |
function timeupdate(_time) { |
|
63 |
var _list = _this.getWidgetAnnotationsAtTime(); |
|
64 |
if (!_list.length) { |
|
65 |
_this.$.find(".Ldt-Annotation-Inner").addClass("Ldt-Annotation-Empty"); |
|
66 |
if (_this.arrow) { |
|
67 |
_this.arrow.moveToTime(_time); |
|
68 |
} |
|
69 |
_this.bounds = [ _time, _time ]; |
|
70 |
_this.sendBounds(); |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
| 719 | 74 |
function highlightTitleAndDescription() { |
75 |
if (!currentAnnotation) { |
|
76 |
return; |
|
77 |
} |
|
78 |
var title = currentAnnotation.title, |
|
| 778 | 79 |
description = currentAnnotation.description.replace(/(^\s+|\s+$)/g,''), |
80 |
rx = (currentAnnotation.found ? (_this.source.getAnnotations().regexp || false) : false); |
|
81 |
_this.$.find(".Ldt-Annotation-Title").html(IriSP.textFieldHtml(title,rx) || "(" + _this.l10n.untitled + ")"); |
|
| 719 | 82 |
if (description) { |
83 |
_this.$.find(".Ldt-Annotation-Description-Block").removeClass("Ldt-Annotation-EmptyBlock"); |
|
| 778 | 84 |
_this.$.find(".Ldt-Annotation-Description").html(IriSP.textFieldHtml(description,rx)); |
| 719 | 85 |
} else { |
86 |
_this.$.find(".Ldt-Annotation-Description-Block").addClass("Ldt-Annotation-EmptyBlock"); |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
| 694 | 90 |
function drawAnnotation(_annotation) { |
| 719 | 91 |
currentAnnotation = _annotation; |
| 694 | 92 |
var _url = (typeof _annotation.url !== "undefined" |
93 |
? _annotation.url |
|
94 |
: (document.location.href.replace(/#.*$/,'') + '#id=' + _annotation.id)), |
|
95 |
_text = _this.l10n.watching + _annotation.title + (_this.site_name ? _this.l10n.on_site + _this.site_name : ''), |
|
96 |
_tags = _annotation.getTags(), |
|
97 |
_tagblock = _this.$.find(".Ldt-Annotation-Tags"); |
|
| 726 | 98 |
_tagblock.empty(); |
| 694 | 99 |
if (_tags.length) { |
100 |
_this.$.find(".Ldt-Annotation-Tags-Block").removeClass("Ldt-Annotation-EmptyBlock"); |
|
101 |
_tags.forEach(function(_tag) { |
|
102 |
var _trimmedTitle = _tag.title.replace(/(^\s+|\s+$)/g,''); |
|
103 |
if (_trimmedTitle) { |
|
104 |
var _el = IriSP.jQuery('<li class="Ldt-Annotation-TagLabel"></li>').append(IriSP.jQuery('<span>').text(_trimmedTitle)); |
|
105 |
_el.click(function() { |
|
106 |
if (_this.search_on_tag_click) { |
|
| 719 | 107 |
_this.source.getAnnotations().search(_trimmedTitle); |
| 694 | 108 |
} |
109 |
_tag.trigger("click"); |
|
110 |
}); |
|
111 |
_tagblock.append(_el); |
|
112 |
} |
|
113 |
}); |
|
114 |
} else { |
|
115 |
_this.$.find(".Ldt-Annotation-Tags-Block").addClass("Ldt-Annotation-EmptyBlock"); |
|
116 |
} |
|
| 719 | 117 |
highlightTitleAndDescription(); |
118 |
if (_this.show_annotation_type) { |
|
119 |
_this.$.find(".Ldt-Annotation-Type").text(_annotation.getAnnotationType().title) |
|
| 694 | 120 |
} |
| 719 | 121 |
_this.$.find(".Ldt-Annotation-Begin").text(_annotation.begin.toString()); |
122 |
_this.$.find(".Ldt-Annotation-End").text(_annotation.end.toString()); |
|
| 694 | 123 |
if (_annotation.elementType === "mashedAnnotation") { |
124 |
_this.$.find('.Ldt-Annotation-Inner').addClass("Ldt-Annotation-isMashup"); |
|
| 719 | 125 |
_this.$.find(".Ldt-Annotation-MashupMedia").text(_annotation.getMedia().title); |
126 |
_this.$.find(".Ldt-Annotation-MashupBegin").text(_annotation.annotation.begin.toString()); |
|
127 |
_this.$.find(".Ldt-Annotation-MashupEnd").text(_annotation.annotation.end.toString()); |
|
| 694 | 128 |
} else { |
129 |
_this.$.find('.Ldt-Annotation-Inner').removeClass("Ldt-Annotation-isMashup"); |
|
130 |
} |
|
131 |
if (typeof _this.socialWidget !== "undefined") { |
|
132 |
_this.socialWidget.updateUrls(_url, _text); |
|
133 |
} else { |
|
134 |
setTimeout(function() { |
|
135 |
if (typeof _this.socialWidget !== "undefined") { |
|
136 |
_this.socialWidget.updateUrls(_url, _text); |
|
137 |
} |
|
138 |
},800); |
|
139 |
} |
|
140 |
_this.$.find(".Ldt-Annotation-Inner").removeClass("Ldt-Annotation-Empty"); |
|
141 |
_this.bounds = [ _annotation.begin, _annotation.end ]; |
|
142 |
if (_this.arrow) { |
|
143 |
_this.arrow.moveToTime((_annotation.begin + _annotation.end)/2); |
|
144 |
} |
|
145 |
_this.sendBounds(); |
|
146 |
} |
|
147 |
|
|
| 598 | 148 |
this.renderTemplate(); |
| 719 | 149 |
|
150 |
if (this.show_social) { |
|
151 |
this.insertSubwidget(this.$.find(".Ldt-Annotation-Social"), { type: "Social" }, "socialWidget"); |
|
152 |
} |
|
153 |
|
|
| 778 | 154 |
this.insertSubwidget(this.$.find(".Ldt-Annotation-Arrow"), { type: "Arrow", width: this.width }, "arrow"); |
| 694 | 155 |
this.onMediaEvent("timeupdate",timeupdate); |
156 |
this.onMdpEvent("Annotation.hide","hide"); |
|
157 |
this.onMdpEvent("Annotation.show","show"); |
|
158 |
this.onMdpEvent("Annotation.minimize","minimize"); |
|
159 |
this.onMdpEvent("Annotation.maximize","maximize"); |
|
160 |
this.onMdpEvent("Annotation.getBounds","sendBounds"); |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
161 |
this.$.find(".Ldt-Annotation-MaxMinButton").click(this.functionWrapper("toggleSize")); |
| 694 | 162 |
this.getWidgetAnnotations().forEach(function(_a) { |
163 |
_a.on("enter", function() { |
|
164 |
drawAnnotation(_a) |
|
165 |
}); |
|
166 |
}); |
|
| 719 | 167 |
this.source.getAnnotations().on("found", highlightTitleAndDescription); |
168 |
this.source.getAnnotations().on("not-found", highlightTitleAndDescription); |
|
169 |
this.source.getAnnotations().on("search-cleared", highlightTitleAndDescription); |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
170 |
} |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
171 |
|
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
172 |
IriSP.Widgets.Annotation.prototype.sendBounds = function() { |
| 694 | 173 |
this.player.trigger("Annotation.boundsChanged",this.bounds); |
| 598 | 174 |
} |
175 |
||
176 |
IriSP.Widgets.Annotation.prototype.drawAnnotation = function(_annotation) { |
|
177 |
this.lastAnnotation = _annotation.id; |
|
| 694 | 178 |
|
| 598 | 179 |
} |
180 |
||
181 |
IriSP.Widgets.Annotation.prototype.hide = function() { |
|
182 |
this.$.slideUp(); |
|
183 |
} |
|
184 |
||
185 |
IriSP.Widgets.Annotation.prototype.show = function() { |
|
186 |
this.$.slideDown(); |
|
187 |
} |
|
188 |
||
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
189 |
IriSP.Widgets.Annotation.prototype.toggleSize = function() { |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
190 |
if (this.minimized) { |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
191 |
this.maximize(); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
192 |
} else { |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
193 |
this.minimize(); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
194 |
} |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
195 |
} |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
196 |
|
| 598 | 197 |
IriSP.Widgets.Annotation.prototype.minimize = function() { |
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
198 |
this.minimized = true; |
| 598 | 199 |
this.$.find('.Ldt-Annotation-Inner').addClass("Ldt-Annotation-Minimized"); |
200 |
} |
|
201 |
||
202 |
IriSP.Widgets.Annotation.prototype.maximize = function() { |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
203 |
this.minimized = false; |
| 598 | 204 |
this.$.find('.Ldt-Annotation-Inner').removeClass("Ldt-Annotation-Minimized"); |
205 |
} |