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