91 }); |
91 }); |
92 } |
92 } |
93 |
93 |
94 IriSP.Widgets.Tweet.prototype.show = function(_tweet) { |
94 IriSP.Widgets.Tweet.prototype.show = function(_tweet) { |
95 if (typeof _tweet !== "undefined" && typeof _tweet.source !== "undefined") { |
95 if (typeof _tweet !== "undefined" && typeof _tweet.source !== "undefined") { |
96 var _entities = []; |
96 var extend = [ |
97 for (var _i = 0; _i < _tweet.source.entities.hashtags.length; _i++) { |
97 [ |
98 var _hash = _tweet.source.entities.hashtags[_i]; |
98 /#(\w+)/gm, |
99 _entities.push({ |
99 function(matches) { |
100 is_link: true, |
100 return '<a href="http://twitter.com/search?q=%23' + matches[1] + '" target="_blank">' |
101 text: '#' + _hash.text, |
101 }, |
102 url: 'http://twitter.com/search?q=%23' + encodeURIComponent(_hash.text), |
102 '</a>' |
103 indices: _hash.indices |
103 ] |
104 }); |
104 ]; |
105 } |
105 var _urls = IriSP._(_tweet.source.entities.urls).sortBy(function(_entity) { |
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]; |
106 return _entity.indices[0]; |
147 }); |
107 }); |
|
108 |
148 var _currentPos = 0, |
109 var _currentPos = 0, |
149 _txt = ''; |
110 _txt = ''; |
150 for (var _i = 0; _i < _entities.length; _i++) { |
111 IriSP._(_urls).each(function(_url) { |
151 if (_entities[_i].indices[0] >= _currentPos) { |
112 if (_url.indices[0] >= _currentPos) { |
152 _txt += _tweet.source.text.substring(_currentPos, _entities[_i].indices[0]); |
113 _txt += _tweet.source.text.substring(_currentPos, _url.indices[0]); |
153 _currentPos = _entities[_i].indices[1]; |
114 _txt += (typeof _url.expanded_url !== "undefined" && _url.expanded_url !== null ? _url.expanded_url : _url.url); |
154 if (_entities[_i].is_link) { |
115 _currentPos = _url.indices[1]; |
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 } |
116 } |
|
117 }); |
|
118 _txt += _tweet.source.text.substring(_currentPos); |
|
119 |
|
120 for (var _i = 0; _i < this.polemics.length; _i++) { |
|
121 var rx = IriSP.Model.regexpFromTextOrArray(this.polemics[_i].keywords); |
|
122 extend.push([ |
|
123 rx, |
|
124 '<span style="background: ' + this.polemics[_i].color + '">', |
|
125 '</span>' |
|
126 ]); |
166 } |
127 } |
167 _txt += _tweet.source.text.substring(_currentPos); |
128 var rx = (_tweet.found ? (_this.source.getAnnotations().regexp || false) : false); |
168 this.$.find(".Ldt-Tweet-Avatar").attr("src",_tweet.source.user.profile_image_url); |
129 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); |
130 this.$.find(".Ldt-Tweet-ScreenName").html('@'+_tweet.source.user.screen_name); |
170 this.$.find(".Ldt-Tweet-ProfileLink").attr("href", "https://twitter.com/" + _tweet.source.user.screen_name); |
131 this.$.find(".Ldt-Tweet-ProfileLink").attr("href", "https://twitter.com/" + _tweet.source.user.screen_name); |
171 this.$.find(".Ldt-Tweet-FullName").html(_tweet.source.user.name); |
132 this.$.find(".Ldt-Tweet-FullName").html(_tweet.source.user.name); |
172 this.$.find(".Ldt-Tweet-Contents").html(_txt); |
133 this.$.find(".Ldt-Tweet-Contents").html(IriSP.textFieldHtml(_txt, rx, extend)); |
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()); |
134 this.$.find(".Ldt-Tweet-Time").html(this.l10n.original_time + new Date(_tweet.source.created_at).toLocaleTimeString() + " / " + this.l10n.video_time + _tweet.begin.toString()); |
174 this.$.find(".Ldt-Tweet-Retweet").attr("href", "https://twitter.com/intent/retweet?tweet_id=" + _tweet.source.id_str); |
135 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); |
136 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); |
137 this.$.find(".Ldt-Tweet-Original").attr("href", "https://twitter.com/" + _tweet.source.user.screen_name + "/status/" + _tweet.source.id_str); |
177 this.player.trigger("Annotation.minimize"); |
138 this.player.trigger("Annotation.minimize"); |