| author | durandn |
| Fri, 18 Sep 2015 14:41:51 +0200 | |
| changeset 1051 | 3820cf5fe29e |
| parent 1013 | 392ddcd212d7 |
| child 1072 | ac1eacb3aa33 |
| permissions | -rw-r--r-- |
| 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 = { |
|
| 987 | 9 |
hide_timeout: 10000, |
| 880 | 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 |
| 1013 | 30 |
}; |
| 880 | 31 |
|
32 |
IriSP.Widgets.Tweet.prototype.messages = { |
|
33 |
"fr": { |
|
34 |
retweet: "Retweeter", |
|
35 |
reply: "Répondre", |
|
| 982 | 36 |
keep_visible: "Empêcher la fermeture automatique", |
| 880 | 37 |
dont_keep_visible: "Permettre la fermeture automatique", |
38 |
close_widget: "Fermer l'affichage du tweet", |
|
| 1002 | 39 |
original_time: "Heure d'envoi\u00a0: ", |
40 |
video_time: "Temps de la vidéo\u00a0: ", |
|
| 918 | 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 |
} |
| 1013 | 53 |
}; |
| 880 | 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; |
|
| 1013 | 74 |
var _el = IriSP.jQuery(this); |
| 880 | 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 |
}); |
|
| 1013 | 92 |
}; |
| 880 | 93 |
|
| 964 | 94 |
IriSP.Widgets.Tweet.prototype.show = function(_tweet) { |
| 880 | 95 |
if (typeof _tweet !== "undefined" && typeof _tweet.source !== "undefined") { |
|
988
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
96 |
var extend = [ |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
97 |
[ |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
98 |
/#(\w+)/gm, |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
99 |
function(matches) { |
| 1013 | 100 |
return '<a href="http://twitter.com/search?q=%23' + matches[1] + '" target="_blank">'; |
|
988
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
101 |
}, |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
102 |
'</a>' |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
103 |
] |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
104 |
]; |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
105 |
var _urls = IriSP._(_tweet.source.entities.urls).sortBy(function(_entity) { |
| 880 | 106 |
return _entity.indices[0]; |
107 |
}); |
|
|
988
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
108 |
|
| 880 | 109 |
var _currentPos = 0, |
110 |
_txt = ''; |
|
|
988
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
111 |
IriSP._(_urls).each(function(_url) { |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
112 |
if (_url.indices[0] >= _currentPos) { |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
113 |
_txt += _tweet.source.text.substring(_currentPos, _url.indices[0]); |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
114 |
_txt += (typeof _url.expanded_url !== "undefined" && _url.expanded_url !== null ? _url.expanded_url : _url.url); |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
115 |
_currentPos = _url.indices[1]; |
| 880 | 116 |
} |
|
988
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
117 |
}); |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
118 |
_txt += _tweet.source.text.substring(_currentPos); |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
119 |
|
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
120 |
for (var _i = 0; _i < this.polemics.length; _i++) { |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
121 |
var rx = IriSP.Model.regexpFromTextOrArray(this.polemics[_i].keywords); |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
122 |
extend.push([ |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
123 |
rx, |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
124 |
'<span style="background: ' + this.polemics[_i].color + '">', |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
125 |
'</span>' |
|
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
126 |
]); |
| 880 | 127 |
} |
| 989 | 128 |
var rx = (_tweet.found ? (_this.source.getAnnotations().regexp || false) : false), |
129 |
profile_url = _tweet.source.user ? _tweet.source.user.profile_image_url : _tweet.source.profile_image_url, |
|
130 |
screen_name = _tweet.source.user ? _tweet.source.user.screen_name :_tweet.source.from_user, |
|
131 |
user_name = _tweet.source.user ? _tweet.source.user.name :_tweet.source.from_user_name; |
|
132 |
this.$.find(".Ldt-Tweet-Avatar").attr("src", profile_url); |
|
133 |
this.$.find(".Ldt-Tweet-ScreenName").html('@' + screen_name); |
|
134 |
this.$.find(".Ldt-Tweet-ProfileLink").attr("href", "https://twitter.com/" + screen_name); |
|
135 |
this.$.find(".Ldt-Tweet-FullName").html(user_name); |
|
|
988
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
136 |
this.$.find(".Ldt-Tweet-Contents").html(IriSP.textFieldHtml(_txt, rx, extend)); |
| 880 | 137 |
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 | 138 |
this.$.find(".Ldt-Tweet-Retweet").attr("href", "https://twitter.com/intent/retweet?tweet_id=" + _tweet.source.id_str); |
139 |
this.$.find(".Ldt-Tweet-Reply").attr("href", "https://twitter.com/intent/tweet?in_reply_to=" + _tweet.source.id_str); |
|
| 989 | 140 |
this.$.find(".Ldt-Tweet-Original").attr("href", "https://twitter.com/" + screen_name + "/status/" + _tweet.source.id_str); |
| 957 | 141 |
this.player.trigger("Annotation.minimize"); |
| 880 | 142 |
this.$.slideDown(); |
143 |
this.cancelTimeout(); |
|
144 |
if (!this.pinned) { |
|
145 |
this.hideTimeout(); |
|
146 |
} |
|
147 |
} else { |
|
148 |
this.hide(); |
|
149 |
} |
|
| 1013 | 150 |
}; |
| 880 | 151 |
|
152 |
IriSP.Widgets.Tweet.prototype.hide = function() { |
|
| 957 | 153 |
this.player.trigger("Annotation.maximize"); |
| 880 | 154 |
this.$.slideUp(); |
155 |
this.cancelTimeout(); |
|
| 1013 | 156 |
}; |
| 880 | 157 |
|
158 |
IriSP.Widgets.Tweet.prototype.cancelTimeout = function() { |
|
159 |
if (typeof this.hide_timer !== "undefined") { |
|
160 |
window.clearTimeout(this.hide_timer); |
|
161 |
this.hide_timer = undefined; |
|
162 |
} |
|
| 1013 | 163 |
}; |
| 880 | 164 |
|
165 |
IriSP.Widgets.Tweet.prototype.hideTimeout = function() { |
|
166 |
this.cancelTimeout(); |
|
167 |
this.hide_timer = window.setTimeout(this.functionWrapper("hide"), this.hide_timeout); |
|
| 1013 | 168 |
}; |