82 }); |
82 }); |
83 this.$.find(".Ldt-Tweet-Close").click(function() { |
83 this.$.find(".Ldt-Tweet-Close").click(function() { |
84 _this.hide(); |
84 _this.hide(); |
85 }); |
85 }); |
86 this.$.hide(); |
86 this.$.hide(); |
87 this.getWidgetAnnotations().forEach(function(_annotation) { |
87 } |
88 _annotation.on("click", function() { |
88 |
89 _this.show(_annotation); |
89 IriSP.Widgets.Tweet.prototype.show = function(_id) { |
90 }); |
90 var _tweet = this.source.getElement(_id); |
91 }); |
|
92 }; |
|
93 |
|
94 IriSP.Widgets.Tweet.prototype.show = function(_tweet) { |
|
95 if (typeof _tweet !== "undefined" && typeof _tweet.source !== "undefined") { |
91 if (typeof _tweet !== "undefined" && typeof _tweet.source !== "undefined") { |
96 var extend = [ |
92 var _entities = []; |
97 [ |
93 for (var _i = 0; _i < _tweet.source.entities.hashtags.length; _i++) { |
98 /#(\w+)/gm, |
94 var _hash = _tweet.source.entities.hashtags[_i]; |
99 function(matches) { |
95 _entities.push({ |
100 return '<a href="http://twitter.com/search?q=%23' + matches[1] + '" target="_blank">'; |
96 is_link: true, |
101 }, |
97 text: '#' + _hash.text, |
102 '</a>' |
98 url: 'http://twitter.com/search?q=%23' + encodeURIComponent(_hash.text), |
103 ] |
99 indices: _hash.indices |
104 ]; |
100 }); |
105 var _urls = IriSP._(_tweet.source.entities.urls).sortBy(function(_entity) { |
101 } |
|
102 for (var _i = 0; _i < _tweet.source.entities.urls.length; _i++) { |
|
103 var _url = _tweet.source.entities.urls[_i], |
|
104 _displayurl = (typeof _url.display_url !== "undefined" && _url.display_url !== null ? _url.display_url : _url.url), |
|
105 _linkurl = (typeof _url.expanded_url !== "undefined" && _url.expanded_url !== null ? _url.expanded_url : _url.url); |
|
106 _displayurl = _displayurl.replace(/^\w+:\/\//,''); |
|
107 if (!/^\w+:\/\//.test(_linkurl)) { |
|
108 _linkurl = 'http://' + _linkurl; |
|
109 } |
|
110 _entities.push({ |
|
111 is_link: true, |
|
112 text: _displayurl, |
|
113 url: _linkurl, |
|
114 indices: _url.indices |
|
115 }); |
|
116 } |
|
117 for (var _i = 0; _i < _tweet.source.entities.user_mentions.length; _i++) { |
|
118 var _user = _tweet.source.entities.user_mentions[_i]; |
|
119 _entities.push({ |
|
120 is_link: true, |
|
121 text: '@' + _user.screen_name, |
|
122 url: 'http://twitter.com/' + encodeURIComponent(_user.screen_name), |
|
123 indices: _user.indices |
|
124 }); |
|
125 } |
|
126 for (var _i = 0; _i < this.polemics.length; _i++) { |
|
127 for (var _j = 0; _j < this.polemics[_i].keywords.length; _j++) { |
|
128 var _p = _tweet.source.text.indexOf(this.polemics[_i].keywords[_j]); |
|
129 while (_p !== -1) { |
|
130 var _end = (_p + this.polemics[_i].keywords[_j].length); |
|
131 _entities.push({ |
|
132 is_link: false, |
|
133 text: this.polemics[_i].keywords[_j], |
|
134 color: this.polemics[_i].color, |
|
135 indices: [_p, _end] |
|
136 }); |
|
137 _p = _tweet.source.text.indexOf(this.polemics[_i].keywords[_j], _end); |
|
138 } |
|
139 } |
|
140 } |
|
141 _entities = IriSP._(_entities).sortBy(function(_entity) { |
106 return _entity.indices[0]; |
142 return _entity.indices[0]; |
107 }); |
143 }); |
108 |
|
109 var _currentPos = 0, |
144 var _currentPos = 0, |
110 _txt = ''; |
145 _txt = ''; |
111 IriSP._(_urls).each(function(_url) { |
146 for (var _i = 0; _i < _entities.length; _i++) { |
112 if (_url.indices[0] >= _currentPos) { |
147 if (_entities[_i].indices[0] >= _currentPos) { |
113 _txt += _tweet.source.text.substring(_currentPos, _url.indices[0]); |
148 _txt += _tweet.source.text.substring(_currentPos, _entities[_i].indices[0]); |
114 _txt += (typeof _url.expanded_url !== "undefined" && _url.expanded_url !== null ? _url.expanded_url : _url.url); |
149 _currentPos = _entities[_i].indices[1]; |
115 _currentPos = _url.indices[1]; |
150 if (_entities[_i].is_link) { |
|
151 _txt += '<a href="' + _entities[_i].url + '" target="_blank">'; |
|
152 } else { |
|
153 _txt += '<span style="background:' + _entities[_i].color + '">'; |
|
154 } |
|
155 _txt += _entities[_i].text; |
|
156 if (_entities[_i].is_link) { |
|
157 _txt += '</a>'; |
|
158 } else { |
|
159 _txt += '</span>'; |
|
160 } |
116 } |
161 } |
117 }); |
162 } |
118 _txt += _tweet.source.text.substring(_currentPos); |
163 _txt += _tweet.source.text.substring(_currentPos); |
119 |
164 this.$.find(".Ldt-Tweet-Avatar").attr("src",_tweet.source.user.profile_image_url); |
120 for (var _i = 0; _i < this.polemics.length; _i++) { |
165 this.$.find(".Ldt-Tweet-ScreenName").html('@'+_tweet.source.user.screen_name); |
121 var rx = IriSP.Model.regexpFromTextOrArray(this.polemics[_i].keywords); |
166 this.$.find(".Ldt-Tweet-ProfileLink").attr("href", "https://twitter.com/" + _tweet.source.user.screen_name); |
122 extend.push([ |
167 this.$.find(".Ldt-Tweet-FullName").html(_tweet.source.user.name); |
123 rx, |
168 this.$.find(".Ldt-Tweet-Contents").html(_txt); |
124 '<span style="background: ' + this.polemics[_i].color + '">', |
|
125 '</span>' |
|
126 ]); |
|
127 } |
|
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); |
|
136 this.$.find(".Ldt-Tweet-Contents").html(IriSP.textFieldHtml(_txt, rx, extend)); |
|
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()); |
169 this.$.find(".Ldt-Tweet-Time").html(this.l10n.original_time + new Date(_tweet.source.created_at).toLocaleTimeString() + " / " + this.l10n.video_time + _tweet.begin.toString()); |
138 this.$.find(".Ldt-Tweet-Retweet").attr("href", "https://twitter.com/intent/retweet?tweet_id=" + _tweet.source.id_str); |
170 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); |
171 this.$.find(".Ldt-Tweet-Reply").attr("href", "https://twitter.com/intent/tweet?in_reply_to=" + _tweet.source.id_str); |
140 this.$.find(".Ldt-Tweet-Original").attr("href", "https://twitter.com/" + screen_name + "/status/" + _tweet.source.id_str); |
172 this.$.find(".Ldt-Tweet-Original").attr("href", "https://twitter.com/" + _tweet.source.user.screen_name + "/status/" + _tweet.source.id_str); |
141 this.player.trigger("Annotation.minimize"); |
173 this.player.popcorn.trigger("IriSP.Annotation.minimize"); |
142 this.$.slideDown(); |
174 this.$.slideDown(); |
143 this.cancelTimeout(); |
175 this.cancelTimeout(); |
144 if (!this.pinned) { |
176 if (!this.pinned) { |
145 this.hideTimeout(); |
177 this.hideTimeout(); |
146 } |
178 } |
147 } else { |
179 } else { |
148 this.hide(); |
180 this.hide(); |
149 } |
181 } |
150 }; |
182 } |
151 |
183 |
152 IriSP.Widgets.Tweet.prototype.hide = function() { |
184 IriSP.Widgets.Tweet.prototype.hide = function() { |
153 this.player.trigger("Annotation.maximize"); |
185 this.player.popcorn.trigger("IriSP.Annotation.maximize"); |
154 this.$.slideUp(); |
186 this.$.slideUp(); |
155 this.cancelTimeout(); |
187 this.cancelTimeout(); |
156 }; |
188 } |
157 |
189 |
158 IriSP.Widgets.Tweet.prototype.cancelTimeout = function() { |
190 IriSP.Widgets.Tweet.prototype.cancelTimeout = function() { |
159 if (typeof this.hide_timer !== "undefined") { |
191 if (typeof this.hide_timer !== "undefined") { |
160 window.clearTimeout(this.hide_timer); |
192 window.clearTimeout(this.hide_timer); |
161 this.hide_timer = undefined; |
193 this.hide_timer = undefined; |
162 } |
194 } |
163 }; |
195 } |
164 |
196 |
165 IriSP.Widgets.Tweet.prototype.hideTimeout = function() { |
197 IriSP.Widgets.Tweet.prototype.hideTimeout = function() { |
166 this.cancelTimeout(); |
198 this.cancelTimeout(); |
167 this.hide_timer = window.setTimeout(this.functionWrapper("hide"), this.hide_timeout); |
199 this.hide_timer = window.setTimeout(this.functionWrapper("hide"), this.hide_timeout); |
168 }; |
200 } |