|
880
|
1 |
IriSP.Widgets.Tweet = function(player, config) { |
|
|
2 |
IriSP.Widgets.Widget.call(this, player, config); |
|
|
3 |
this.lastAnnotation = false; |
|
|
4 |
}; |
|
|
5 |
|
|
|
6 |
IriSP.Widgets.Tweet.prototype = new IriSP.Widgets.Widget(); |
|
|
7 |
|
|
|
8 |
IriSP.Widgets.Tweet.prototype.defaults = { |
|
|
9 |
hide_timeout: 5000, |
|
|
10 |
polemics : [ |
|
|
11 |
{ |
|
|
12 |
"keywords" : [ "++" ], |
|
|
13 |
"color" : "#30d765" |
|
|
14 |
}, |
|
|
15 |
{ |
|
|
16 |
"keywords" : [ "--" ], |
|
|
17 |
"color" : "#f51123" |
|
|
18 |
}, |
|
|
19 |
{ |
|
|
20 |
"keywords" : [ "==" ], |
|
|
21 |
"color" : "#f1e24a" |
|
|
22 |
}, |
|
|
23 |
{ |
|
|
24 |
"keywords" : [ "??" ], |
|
|
25 |
"color" : "#05aae6" |
|
|
26 |
} |
|
918
|
27 |
], |
|
964
|
28 |
annotation_type: "tweet", |
|
918
|
29 |
pin_at_start: false |
|
880
|
30 |
} |
|
|
31 |
|
|
|
32 |
IriSP.Widgets.Tweet.prototype.messages = { |
|
|
33 |
"fr": { |
|
|
34 |
retweet: "Retweeter", |
|
|
35 |
reply: "Répondre", |
|
|
36 |
keep_visible: "Garder visible", |
|
|
37 |
dont_keep_visible: "Permettre la fermeture automatique", |
|
|
38 |
close_widget: "Fermer l'affichage du tweet", |
|
918
|
39 |
original_time: "Heure d'envoi : ", |
|
|
40 |
video_time: "Temps de la vidéo : ", |
|
|
41 |
show_original: "Voir l'original" |
|
880
|
42 |
}, |
|
|
43 |
"en": { |
|
|
44 |
retweet: "Retweet", |
|
|
45 |
reply: "Reply", |
|
|
46 |
keep_visible: "Keep visible", |
|
|
47 |
dont_keep_visible: "Don't keep visible", |
|
|
48 |
close_widget: "Close tweet display", |
|
|
49 |
original_time: "Tweet sent at: ", |
|
918
|
50 |
video_time: "Video time: ", |
|
|
51 |
show_original: "Show original" |
|
880
|
52 |
} |
|
|
53 |
} |
|
|
54 |
|
|
|
55 |
IriSP.Widgets.Tweet.prototype.template = |
|
|
56 |
'<div class="Ldt-Tweet-Widget"><div class="Ldt-Tweet-Inner"><div class="Ldt-Tweet-PinClose-Buttons">' |
|
918
|
57 |
+ '<a href="#" class="Ldt-Tweet-Pin Ldt-TraceMe{{#pin_at_start}} active" title="{{l10n.dont_keep_visible}}{{/pin_at_start}}{{^pin_at_start}}" title="{{l10n.keep_visible}}{{/pin_at_start}}"></a>' |
|
906
|
58 |
+ '<a href="#" class="Ldt-Tweet-Close Ldt-TraceMe" title="{{l10n.close_widget}}"></a>' |
|
880
|
59 |
+ '</div><div class="Ldt-Tweet-AvatarContainer"><a href="#" class="Ldt-Tweet-ProfileLink" target="_blank">' |
|
|
60 |
+ '<img src="" class="Ldt-Tweet-Avatar"/></a></div><h3><a href="#" class="Ldt-Tweet-ProfileLink Ldt-Tweet-ScreenName" target="_blank">' |
|
|
61 |
+ '</a> (<span class="Ldt-Tweet-FullName"></span>)</h3><p class="Ldt-Tweet-Contents"></p><div class="Ldt-Tweet-Bottom">' |
|
918
|
62 |
+ '<span class="Ldt-Tweet-Time"></span>' |
|
|
63 |
+ '<a class="Ldt-Tweet-Original" href="" target="_blank">{{l10n.show_original}}</a>' |
|
|
64 |
+ '<a href="" target="_blank" class="Ldt-Tweet-Retweet"><div class="Ldt-Tweet-Icon"></div>{{l10n.retweet}}</a>' |
|
880
|
65 |
+ '<a href="" target="_blank" class="Ldt-Tweet-Reply"><div class="Ldt-Tweet-Icon"></div>{{l10n.reply}}</a></div></div></div>'; |
|
|
66 |
|
|
|
67 |
|
|
|
68 |
IriSP.Widgets.Tweet.prototype.draw = function() { |
|
|
69 |
this.renderTemplate(); |
|
918
|
70 |
this.pinned = this.pin_at_start; |
|
880
|
71 |
var _this = this; |
|
|
72 |
this.$.find(".Ldt-Tweet-Pin").click(function() { |
|
|
73 |
_this.pinned = !_this.pinned; |
|
|
74 |
var _el = IriSP.jQuery(this) |
|
|
75 |
if (_this.pinned) { |
|
|
76 |
_el.addClass("active").attr("title",_this.l10n.dont_keep_visible); |
|
|
77 |
_this.cancelTimeout(); |
|
|
78 |
} else { |
|
|
79 |
_el.removeClass("active").attr("title",_this.l10n.keep_visible); |
|
|
80 |
_this.hideTimeout(); |
|
|
81 |
} |
|
|
82 |
}); |
|
|
83 |
this.$.find(".Ldt-Tweet-Close").click(function() { |
|
|
84 |
_this.hide(); |
|
|
85 |
}); |
|
|
86 |
this.$.hide(); |
|
964
|
87 |
this.getWidgetAnnotations().forEach(function(_annotation) { |
|
|
88 |
_annotation.on("click", function() { |
|
|
89 |
_this.show(_annotation); |
|
|
90 |
}); |
|
|
91 |
}); |
|
880
|
92 |
} |
|
|
93 |
|
|
964
|
94 |
IriSP.Widgets.Tweet.prototype.show = function(_tweet) { |
|
880
|
95 |
if (typeof _tweet !== "undefined" && typeof _tweet.source !== "undefined") { |
|
|
96 |
var _entities = []; |
|
|
97 |
for (var _i = 0; _i < _tweet.source.entities.hashtags.length; _i++) { |
|
|
98 |
var _hash = _tweet.source.entities.hashtags[_i]; |
|
|
99 |
_entities.push({ |
|
|
100 |
is_link: true, |
|
|
101 |
text: '#' + _hash.text, |
|
|
102 |
url: 'http://twitter.com/search?q=%23' + encodeURIComponent(_hash.text), |
|
|
103 |
indices: _hash.indices |
|
|
104 |
}); |
|
|
105 |
} |
|
|
106 |
for (var _i = 0; _i < _tweet.source.entities.urls.length; _i++) { |
|
|
107 |
var _url = _tweet.source.entities.urls[_i], |
|
|
108 |
_displayurl = (typeof _url.display_url !== "undefined" && _url.display_url !== null ? _url.display_url : _url.url), |
|
|
109 |
_linkurl = (typeof _url.expanded_url !== "undefined" && _url.expanded_url !== null ? _url.expanded_url : _url.url); |
|
|
110 |
_displayurl = _displayurl.replace(/^\w+:\/\//,''); |
|
|
111 |
if (!/^\w+:\/\//.test(_linkurl)) { |
|
|
112 |
_linkurl = 'http://' + _linkurl; |
|
|
113 |
} |
|
|
114 |
_entities.push({ |
|
|
115 |
is_link: true, |
|
|
116 |
text: _displayurl, |
|
|
117 |
url: _linkurl, |
|
|
118 |
indices: _url.indices |
|
|
119 |
}); |
|
|
120 |
} |
|
|
121 |
for (var _i = 0; _i < _tweet.source.entities.user_mentions.length; _i++) { |
|
|
122 |
var _user = _tweet.source.entities.user_mentions[_i]; |
|
|
123 |
_entities.push({ |
|
|
124 |
is_link: true, |
|
|
125 |
text: '@' + _user.screen_name, |
|
|
126 |
url: 'http://twitter.com/' + encodeURIComponent(_user.screen_name), |
|
|
127 |
indices: _user.indices |
|
|
128 |
}); |
|
|
129 |
} |
|
|
130 |
for (var _i = 0; _i < this.polemics.length; _i++) { |
|
|
131 |
for (var _j = 0; _j < this.polemics[_i].keywords.length; _j++) { |
|
|
132 |
var _p = _tweet.source.text.indexOf(this.polemics[_i].keywords[_j]); |
|
|
133 |
while (_p !== -1) { |
|
|
134 |
var _end = (_p + this.polemics[_i].keywords[_j].length); |
|
|
135 |
_entities.push({ |
|
|
136 |
is_link: false, |
|
|
137 |
text: this.polemics[_i].keywords[_j], |
|
|
138 |
color: this.polemics[_i].color, |
|
|
139 |
indices: [_p, _end] |
|
|
140 |
}); |
|
|
141 |
_p = _tweet.source.text.indexOf(this.polemics[_i].keywords[_j], _end); |
|
|
142 |
} |
|
|
143 |
} |
|
|
144 |
} |
|
|
145 |
_entities = IriSP._(_entities).sortBy(function(_entity) { |
|
|
146 |
return _entity.indices[0]; |
|
|
147 |
}); |
|
|
148 |
var _currentPos = 0, |
|
|
149 |
_txt = ''; |
|
|
150 |
for (var _i = 0; _i < _entities.length; _i++) { |
|
|
151 |
if (_entities[_i].indices[0] >= _currentPos) { |
|
|
152 |
_txt += _tweet.source.text.substring(_currentPos, _entities[_i].indices[0]); |
|
|
153 |
_currentPos = _entities[_i].indices[1]; |
|
|
154 |
if (_entities[_i].is_link) { |
|
|
155 |
_txt += '<a href="' + _entities[_i].url + '" target="_blank">'; |
|
|
156 |
} else { |
|
|
157 |
_txt += '<span style="background:' + _entities[_i].color + '">'; |
|
|
158 |
} |
|
|
159 |
_txt += _entities[_i].text; |
|
|
160 |
if (_entities[_i].is_link) { |
|
|
161 |
_txt += '</a>'; |
|
|
162 |
} else { |
|
|
163 |
_txt += '</span>'; |
|
|
164 |
} |
|
|
165 |
} |
|
|
166 |
} |
|
|
167 |
_txt += _tweet.source.text.substring(_currentPos); |
|
|
168 |
this.$.find(".Ldt-Tweet-Avatar").attr("src",_tweet.source.user.profile_image_url); |
|
|
169 |
this.$.find(".Ldt-Tweet-ScreenName").html('@'+_tweet.source.user.screen_name); |
|
918
|
170 |
this.$.find(".Ldt-Tweet-ProfileLink").attr("href", "https://twitter.com/" + _tweet.source.user.screen_name); |
|
880
|
171 |
this.$.find(".Ldt-Tweet-FullName").html(_tweet.source.user.name); |
|
|
172 |
this.$.find(".Ldt-Tweet-Contents").html(_txt); |
|
|
173 |
this.$.find(".Ldt-Tweet-Time").html(this.l10n.original_time + new Date(_tweet.source.created_at).toLocaleTimeString() + " / " + this.l10n.video_time + _tweet.begin.toString()); |
|
918
|
174 |
this.$.find(".Ldt-Tweet-Retweet").attr("href", "https://twitter.com/intent/retweet?tweet_id=" + _tweet.source.id_str); |
|
|
175 |
this.$.find(".Ldt-Tweet-Reply").attr("href", "https://twitter.com/intent/tweet?in_reply_to=" + _tweet.source.id_str); |
|
|
176 |
this.$.find(".Ldt-Tweet-Original").attr("href", "https://twitter.com/" + _tweet.source.user.screen_name + "/status/" + _tweet.source.id_str); |
|
957
|
177 |
this.player.trigger("Annotation.minimize"); |
|
880
|
178 |
this.$.slideDown(); |
|
|
179 |
this.cancelTimeout(); |
|
|
180 |
if (!this.pinned) { |
|
|
181 |
this.hideTimeout(); |
|
|
182 |
} |
|
|
183 |
} else { |
|
|
184 |
this.hide(); |
|
|
185 |
} |
|
|
186 |
} |
|
|
187 |
|
|
|
188 |
IriSP.Widgets.Tweet.prototype.hide = function() { |
|
957
|
189 |
this.player.trigger("Annotation.maximize"); |
|
880
|
190 |
this.$.slideUp(); |
|
|
191 |
this.cancelTimeout(); |
|
|
192 |
} |
|
|
193 |
|
|
|
194 |
IriSP.Widgets.Tweet.prototype.cancelTimeout = function() { |
|
|
195 |
if (typeof this.hide_timer !== "undefined") { |
|
|
196 |
window.clearTimeout(this.hide_timer); |
|
|
197 |
this.hide_timer = undefined; |
|
|
198 |
} |
|
|
199 |
} |
|
|
200 |
|
|
|
201 |
IriSP.Widgets.Tweet.prototype.hideTimeout = function() { |
|
|
202 |
this.cancelTimeout(); |
|
|
203 |
this.hide_timer = window.setTimeout(this.functionWrapper("hide"), this.hide_timeout); |
|
|
204 |
} |