PageSourceSearch

https://urdomain.com/HTML/assets/js/tweetie.js

js urdomain.com collected 2026-10-04 21:53:29 UTC 5,123 bytes, 130 lines download raw bytes

1/**
2 * Tweetie: A simple Twitter feed plugin
3 * Author: Sonny T. <[email protected]>, sonnyt.com
4 */
5
6(function ($) {
7    'use strict';
8
9    $.fn.twittie = function () {
10        var options = (arguments[0] instanceof Object) ? arguments[0] : {},
11            callback = (typeof arguments[0] === 'function') ? arguments[0] : arguments[1];
12
13        // Default settings
14        var settings = $.extend({
15            'username': null,
16            'list': null,
17            'hashtag': null,
18            'count': 10,
19            'hideReplies': false,
20            'dateFormat': '%b/%d/%Y',
21            'template': '{{date}} - {{tweet}}',
22            'apiPath' : 'assets/api/tweet.php',
23            'loadingText': 'Loading...'
24        }, options);
25
26        if (settings.list && !settings.username) {
27            $.error('If you want to fetch tweets from a list, you must define the username of the list owner.');
28        }
29
30        /**
31         * Applies @reply, #hash and http links
32         * @param  {String} tweet A single tweet
33         * @return {String}       Fixed tweet
34         *
35         * Thanks to @Wachem enhanced linking.
36         */
37        var linking = function (tweet) {
38            var twit = tweet.replace(/(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)/ig,'<a href="$1" target="_blank" title="Visit this link">$1</a>')
39                 .replace(/#([a-zA-Z0-9_]+)/g,'<a href="https://twitter.com/search?q=%23$1&amp;src=hash" target="_blank" title="Search for #$1">#$1</a>')
40                 .replace(/@([a-zA-Z0-9_]+)/g,'<a href="https://twitter.com/$1" target="_blank" title="$1 on Twitter">@$1</a>');
41
42            return twit;
43        };
44
45        /**
46         * Formating a date
47         * @param  {String} twt_date Twitter date
48         * @return {String}          Formatted date
49         */
50        var dating = function (twt_date) {
51            // fix for IE
52            var time = twt_date.split(' ');
53            twt_date = new Date(Date.parse(time[1] + ' ' + time[2] + ', ' + time[5] + ' ' + time[3] + ' UTC'));
54
55            var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
56
57            var _date = {
58                '%d': twt_date.getDate(),
59                '%m': twt_date.getMonth()+1,
60                '%b': months[twt_date.getMonth()].substr(0, 3),
61                '%B': months[twt_date.getMonth()],
62                '%y': String(twt_date.getFullYear()).slice(-2),
63                '%Y': twt_date.getFullYear()
64            };
65
66            var date = settings.dateFormat;
67            var format = settings.dateFormat.match(/%[dmbByY]/g);
68
69            for (var i = 0, len = format.length; i < len; i++) {
70                date = date.replace(format[i], _date[format[i]]);
71            }
72
73            return date;
74        };
75
76        /**
77         * Templating a tweet using '{{ }}' braces
78         * @param  {Object} data Tweet details are passed
79         * @return {String}      Templated string
80         */
81        var templating = function (data) {
82            var temp = settings.template;
83            var temp_variables = ['date', 'tweet', 'avatar', 'url', 'retweeted', 'screen_name', 'user_name'];
84
85            for (var i = 0, len = temp_variables.length; i < len; i++) {
86                temp = temp.replace(new RegExp('{{' + temp_variables[i] + '}}', 'gi'), data[temp_variables[i]]);
87            }
88
89            return temp;
90        };
91
92        // Set loading
93       	this.html('<span>'+settings.loadingText+'</span>');
94
95        var that = this;
96
97        // Fetch tweets
98        $.getJSON(settings.apiPath, { username: settings.username, list: settings.list, hashtag: settings.hashtag, count: settings.count, exclude_replies: settings.hideReplies }, function (twt) {
99            that.find('span').fadeOut('fast', function () {
100                that.html('<ul></ul>');
101
102                for (var i = 0; i < settings.count; i++) {
103                    var tweet = false;
104                    if(twt[i]) {
105                        tweet = twt[i];
106                    } else if(twt.statuses !== undefined && twt.statuses[i]) {
107                        tweet = twt.statuses[i];
108                    } else {
109                        break;
110                    }
111
112                    var temp_data = {
113                        user_name: tweet.user.name,
114                        date: dating(tweet.created_at),
115                        tweet: (tweet.retweeted) ? linking('RT @'+ tweet.user.screen_name +': '+ tweet.retweeted_status.text) : linking(tweet.text),
116                        avatar: '<img src="'+ tweet.user.profile_image_url +'" />',
117                        url: 'https://twitter.com/' + tweet.user.screen_name + '/status/' + tweet.id_str,
118                        retweeted: tweet.retweeted,
119                        screen_name: linking('@'+ tweet.user.screen_name)
120                    };
121
122                    that.find('ul').append('<li>' + templating(temp_data) + '</li>');
123                }
124
125                if (typeof callback === 'function') { callback(); }
126            });
127        });
128    };
129
130})(jQuery);

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.