PageSourceSearch

https://www.fuenlan.es/wp-content/themes/inceptio/js/jquery.tweet.js?ver=1.14

js fuenlan.es collected 2026-10-10 00:34:15 UTC 17,862 bytes, 312 lines download raw bytes

1//updated by ixtendo
2// jquery.tweet.js - See http://tweet.seaofclouds.com/ or https://github.com/seaofclouds/tweet for more info
3// Copyright (c) 2008-2012 Todd Matthews & Steve Purcell
4(function (factory) {
5    if (typeof define === 'function' && define.amd)
6        define(['jquery'], factory); // AMD support for RequireJS etc.
7    else
8        factory(jQuery);
9}(function ($) {
10    $.fn.tweet = function(o){
11        var s = $.extend({
12            username: null,                           // [string or array] required unless using the 'query' option; one or more twitter screen names (use 'list' option for multiple names, where possible)
13            list: null,                               // [string]   optional name of list belonging to username
14            favorites: false,                         // [boolean]  display the user's favorites instead of his tweets
15            query: null,                              // [string]   optional search query (see also: http://search.twitter.com/operators)
16            avatar_size: null,                        // [integer]  height and width of avatar if displayed (48px max)
17            count: 3,                                 // [integer]  how many tweets to display?
18            fetch: null,                              // [integer]  how many tweets to fetch via the API (set this higher than 'count' if using the 'filter' option)
19            page: 1,                                  // [integer]  which page of results to fetch (if count != fetch, you'll get unexpected results)
20            retweets: true,                           // [boolean]  whether to fetch (official) retweets (not supported in all display modes)
21            intro_text: null,                         // [string]   do you want text BEFORE your your tweets?
22            outro_text: null,                         // [string]   do you want text AFTER your tweets?
23            join_text:  null,                         // [string]   optional text in between date and tweet, try setting to "auto"
24            auto_join_text_default: " I said, ",      // [string]   auto text for non verb: "I said" bullocks
25            auto_join_text_ed: " I ",                 // [string]   auto text for past tense: "I" surfed
26            auto_join_text_ing: " I am ",             // [string]   auto tense for present tense: "I was" surfing
27            auto_join_text_reply: " I replied to ",   // [string]   auto tense for replies: "I replied to" @someone "with"
28            auto_join_text_url: " I was looking at ", // [string]   auto tense for urls: "I was looking at" http:...
29            loading_text: null,                       // [string]   optional loading text, displayed while tweets load
30            refresh_interval: null,                   // [integer]  optional number of seconds after which to reload tweets
31            twitter_url: "twitter.com",               // [string]   custom twitter url, if any (apigee, etc.)
32            twitter_api_url: "api.twitter.com",       // [string]   custom twitter api url, if any (apigee, etc.)
33            twitter_search_url: "search.twitter.com", // [string]   custom twitter search url, if any (apigee, etc.)
34            template: "{avatar}{time}{join} {text}",  // [string or function] template used to construct each tweet <li> - see code for available vars
35            comparator: function(tweet1, tweet2) {    // [function] comparator used to sort tweets (see Array.sort)
36                return tweet2.tweet_time - tweet1.tweet_time;
37            },
38            filter: function(tweet) {                 // [function] whether or not to include a particular tweet (be sure to also set 'fetch')
39                return true;
40            }
41            // You can attach callbacks to the following events using jQuery's standard .bind() mechanism:
42            //   "loaded" -- triggered when tweets have been fetched and rendered
43        }, o);
44
45        // See http://daringfireball.net/2010/07/improved_regex_for_matching_urls
46        var defaultMessages = {
47            'msg1': 'about {p1} days ago',
48            'msg2': 'about a day ago',
49            'msg3': 'about {p1} hours ago',
50            'msg4': 'about an hour ago',
51            'msg5': 'about {p1} minutes ago',
52            'msg6': 'about {p1} seconds ago',
53            'msg7': 'just now'
54        };
55        var url_regexp = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi;
56
57        // Expand values inside simple string templates with {placeholders}
58        function t(template, info) {
59            if (typeof template === "string") {
60                var result = template;
61                for(var key in info) {
62                    var val = info[key];
63                    result = result.split('{'+key+'}').join(val === null ? '' : val);
64                }
65                return result;
66            } else return template(info);
67        }
68        // Export the t function for use when passing a function as the 'template' option
69        $.extend({tweet: {t: t}});
70
71        function replacer (regex, replacement) {
72            return function() {
73                var returning = [];
74                this.each(function() {
75                    returning.push(this.replace(regex, replacement));
76                });
77                return $(returning);
78            };
79        }
80
81        function escapeHTML(s) {
82            return s.replace(/</g,"&lt;").replace(/>/g,"^&gt;");
83        }
84
85        $.fn.extend({
86            linkUser: replacer(/(^|[\W])@(\w+)/gi, "$1<span class=\"at\">@</span><a href=\"http://"+s.twitter_url+"/$2\">$2</a>"),
87            // Support various latin1 (\u00**) and arabic (\u06**) alphanumeric chars
88            linkHash: replacer(/(?:^| )[\#]+([\w\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff\u0600-\u06ff]+)/gi,
89                ' <a href="https://'+s.twitter_url+'/search?q=%23$1&src=hash&lang=all'+
90                    ((s.username && s.username.length === 1 && !s.list) ? '&from='+s.username.join("%2BOR%2B") : '')+
91                    '" class="tweet_hashtag">#$1</a>'),
92            makeHeart: replacer(/(&lt;)+[3]/gi, "<tt class='heart'>&#x2665;</tt>")
93        });
94
95        function linkURLs(text, entities) {
96            return text.replace(url_regexp, function(match) {
97                var url = (/^[a-z]+:/i).test(match) ? match : "http://"+match;
98                var text = match;
99                for(var i = 0; i < entities.length; ++i) {
100                    var entity = entities[i];
101                    if (entity.url === url && entity.expanded_url) {
102                        url = entity.expanded_url;
103                        text = entity.display_url;
104                        break;
105                    }
106                }
107                return "<a href=\""+escapeHTML(url)+"\">"+escapeHTML(text)+"</a>";
108            });
109        }
110
111        function parse_date(date_str) {
112            // The non-search twitter APIs return inconsistently-formatted dates, which Date.parse
113            // cannot handle in IE. We therefore perform the following transformation:
114            // "Wed Apr 29 08:53:31 +0000 2009" => "Wed, Apr 29 2009 08:53:31 +0000"
115            return Date.parse(date_str.replace(/^([a-z]{3})( [a-z]{3} \d\d?)(.*)( \d{4})$/i, '$1,$2$4$3'));
116        }
117
118        function extract_relative_time(date) {
119            var toInt = function(val) { return parseInt(val, 10); };
120            var relative_to = new Date();
121            var delta = toInt((relative_to.getTime() - date) / 1000);
122            if (delta < 1) delta = 0;
123            return {
124                days:    toInt(delta / 86400),
125                hours:   toInt(delta / 3600),
126                minutes: toInt(delta / 60),
127                seconds: toInt(delta)
128            };
129        }
130
131        function format_relative_time(time_ago) {
132            var messages = defaultMessages;
133            if(document.incTweetJSKeys){
134                messages = document.incTweetJSKeys;
135            }
136            if ( time_ago.days > 2 ) {
137                return messages['msg1'].replace('{p1}', time_ago.days);
138            }
139            if ( time_ago.hours > 24 ){
140                return messages['msg2'];
141            }
142            if ( time_ago.hours > 2 ){
143                return messages['msg3'].replace('{p1}', time_ago.hours);
144            }
145            if ( time_ago.minutes > 45 ) {
146                return messages['msg4'];
147            }
148            if ( time_ago.minutes > 2 )  {
149                return messages['msg5'].replace('{p1}', time_ago.minutes);
150            }
151            if ( time_ago.seconds > 1 ) {
152                return messages['msg6'].replace('{p1}', time_ago.seconds);
153            }
154            return messages['msg7'];
155        }
156
157        function build_auto_join_text(text) {
158            if (text.match(/^(@([A-Za-z0-9-_]+)) .*/i)) {
159                return s.auto_join_text_reply;
160            } else if (text.match(url_regexp)) {
161                return s.auto_join_text_url;
162            } else if (text.match(/^((\w+ed)|just) .*/im)) {
163                return s.auto_join_text_ed;
164            } else if (text.match(/^(\w*ing) .*/i)) {
165                return s.auto_join_text_ing;
166            } else {
167                return s.auto_join_text_default;
168            }
169        }
170
171//        function build_api_url() {
172//            var proto = ('https:' == document.location.protocol ? 'https:' : 'http:');
173//            var count = (s.fetch === null) ? s.count : s.fetch;
174//            var common_params = '&include_entities=1&callback=?';
175//            if (s.list) {
176//                return proto+"//"+s.twitter_api_url+"/1/"+s.username[0]+"/lists/"+s.list+"/statuses.json?page="+s.page+"&per_page="+count+common_params;
177//            } else if (s.favorites) {
178//                return proto+"//"+s.twitter_api_url+"/1/favorites.json?screen_name="+s.username[0]+"&page="+s.page+"&count="+count+common_params;
179//            } else if (s.query === null && s.username.length == 1) {
180//                return proto+'//'+s.twitter_api_url+'/1/statuses/user_timeline.json?screen_name='+s.username[0]+'&count='+count+(s.retweets ? '&include_rts=1' : '')+'&page='+s.page+common_params;
181//            } else {
182//                var query = (s.query || 'from:'+s.username.join(' OR from:'));
183//                return proto+'//'+s.twitter_search_url+'/search.json?&q='+encodeURIComponent(query)+'&rpp='+count+'&page='+s.page+common_params;
184//            }
185//        }
186
187        function build_api_url() {
188            var apiUrl = s.twitter_api_url;
189            if(apiUrl.indexOf('?') >= 0){
190                apiUrl += '&url='
191            }else{
192                apiUrl += '?url=';
193            }
194            var proto = ('https:' == document.location.protocol ? 'https:' : 'http:');
195            var count = (s.fetch === null) ? s.count : s.fetch;
196            var common_params = '&include_entities=1';
197            if (s.list) {
198                return apiUrl+encodeURIComponent(s.username[0]+"/lists/"+s.list+"/statuses.json?page="+s.page+"&per_page="+count+common_params);
199            } else if (s.favorites) {
200                return apiUrl+encodeURIComponent("favorites.json?screen_name="+s.username[0]+"&page="+s.page+"&count="+count+common_params);
201            } else if (s.query === null && s.username.length === 1) {
202                return apiUrl+encodeURIComponent('statuses/user_timeline.json?screen_name='+s.username[0]+'&count='+count+(s.retweets ? '&include_rts=1' : '')+'&page='+s.page+common_params);
203            } else {
204                var query = (s.query || 'from:'+s.username.join(' OR from:'));
205                return apiUrl+encodeURIComponent('search/tweets.json?q=' + query + common_params);
206            }
207        }
208
209        function extract_avatar_url(item, secure) {
210            if (secure) {
211                return ('user' in item) ?
212                    item.user.profile_image_url_https :
213                    extract_avatar_url(item, false).
214                        replace(/^http:\/\/[a-z0-9]{1,3}\.twimg\.com\//, "https://s3.amazonaws.com/twitter_production/");
215            } else {
216                return item.profile_image_url || item.user.profile_image_url;
217            }
218        }
219
220        // Convert twitter API objects into data available for
221        // constructing each tweet <li> using a template
222        function extract_template_data(item){
223            var o = {};
224            o.item = item;
225            o.source = item.source;
226            o.screen_name = item.from_user || item.user.screen_name;
227            // The actual user name is not returned by all Twitter APIs, so please do not
228            // file an issue if it is empty:
229            o.name = item.from_user_name || item.user.name;
230            o.retweet = typeof(item.retweeted_status) != 'undefined';
231
232            o.tweet_time = parse_date(item.created_at);
233            o.join_text = s.join_text === "auto" ? build_auto_join_text(item.text) : s.join_text;
234            o.tweet_id = item.id_str;
235            o.twitter_base = "http://"+s.twitter_url+"/";
236            o.user_url = o.twitter_base+o.screen_name;
237            o.tweet_url = o.user_url+"/status/"+o.tweet_id;
238            o.reply_url = o.twitter_base+"intent/tweet?in_reply_to="+o.tweet_id;
239            o.retweet_url = o.twitter_base+"intent/retweet?tweet_id="+o.tweet_id;
240            o.favorite_url = o.twitter_base+"intent/favorite?tweet_id="+o.tweet_id;
241            o.retweeted_screen_name = o.retweet && item.retweeted_status.user.screen_name;
242            o.tweet_relative_time = format_relative_time(extract_relative_time(o.tweet_time));
243            o.entities = item.entities ? (item.entities.urls || []).concat(item.entities.media || []) : [];
244            o.tweet_raw_text = o.retweet ? ('RT @'+o.retweeted_screen_name+' '+item.retweeted_status.text) : item.text; // avoid '...' in long retweets
245            o.tweet_text = $([linkURLs(o.tweet_raw_text, o.entities)]).linkUser().linkHash()[0];
246            o.retweeted_tweet_text = $([linkURLs(item.text, o.entities)]).linkUser().linkHash()[0];
247            o.tweet_text_fancy = $([o.tweet_text]).makeHeart()[0];
248
249            o.avatar_size = s.avatar_size;
250            o.avatar_url = extract_avatar_url(o.retweet ? item.retweeted_status : item, (document.location.protocol === 'https:'));
251            o.avatar_screen_name = o.retweet ? o.retweeted_screen_name : o.screen_name;
252            o.avatar_profile_url = o.twitter_base+o.avatar_screen_name;
253
254            // Default spans, and pre-formatted blocks for common layouts
255            o.user = t('<a class="tweet_user" href="{user_url}">{screen_name}</a>', o);
256            o.join = s.join_text ? t('<span class="tweet_join">{join_text}</span>', o) : '';
257            o.avatar = o.avatar_size ?
258                t('<a class="tweet_avatar" href="{avatar_profile_url}"><img src="{avatar_url}" height="{avatar_size}" width="{avatar_size}" alt="{avatar_screen_name}\'s avatar" title="{avatar_screen_name}\'s avatar" border="0"/></a>', o) : '';
259            o.time = t('<span class="tweet_time"><a href="{tweet_url}" title="view tweet on twitter">{tweet_relative_time}</a></span>', o);
260            o.text = t('<span class="tweet_text">{tweet_text_fancy}</span>', o);
261            o.retweeted_text = t('<span class="tweet_text">{retweeted_tweet_text}</span>', o);
262            o.reply_action = t('<a class="tweet_action tweet_reply" href="{reply_url}">reply</a>', o);
263            o.retweet_action = t('<a class="tweet_action tweet_retweet" href="{retweet_url}">retweet</a>', o);
264            o.favorite_action = t('<a class="tweet_action tweet_favorite" href="{favorite_url}">favorite</a>', o);
265            return o;
266        }
267
268        function render_tweets(widget, tweets) {
269            var list = $('<ul class="tweet_list">');
270            list.append($.map(tweets, function(o) { return "<li>" + t(s.template, o) + "</li>"; }).join('')).
271                children('li:first').addClass('tweet_first').end().
272                children('li:odd').addClass('tweet_even').end().
273                children('li:even').addClass('tweet_odd');
274
275            $(widget).empty().append(list);
276            if (s.intro_text) list.before('<p class="tweet_intro">'+s.intro_text+'</p>');
277            if (s.outro_text) list.after('<p class="tweet_outro">'+s.outro_text+'</p>');
278
279            $(widget).trigger("loaded").trigger((tweets.length === 0 ? "empty" : "full"));
280            if (s.refresh_interval) {
281                window.setTimeout(function() { $(widget).trigger("tweet:load"); }, 1000 * s.refresh_interval);
282            }
283        }
284
285        function load(widget) {
286            var loading = $('<p class="loading">'+s.loading_text+'</p>');
287            if (s.loading_text) $(widget).not(":has(.tweet_list)").empty().append(loading);
288            $.getJSON(build_api_url(), function(data){
289                var tweets = $.map(data.statuses || data, extract_template_data);
290                tweets = $.grep(tweets, s.filter).sort(s.comparator).slice(0, s.count);
291                $(widget).trigger("tweet:retrieved", [tweets]);
292            });
293        }
294
295        return this.each(function(i, widget){
296            if(s.username && typeof(s.username) === "string"){
297                s.username = [s.username];
298            }
299
300            $(widget).unbind("tweet:render").unbind("tweet:retrieved").unbind("tweet:load").
301                bind({
302                    "tweet:load": function() { load(widget); },
303                    "tweet:retrieved": function(ev, tweets) {
304                        $(widget).trigger("tweet:render", [tweets]);
305                    },
306                    "tweet:render": function(ev, tweets) {
307                        render_tweets($(widget), tweets);
308                    }
309                }).trigger("tweet:load");
310        });
311    };
312}));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.