PageSourceSearch

https://www.canveyisland-tc.gov.uk/phoo/6.1.0/scripts/jquery/sonnyt-Tweetie-d2be9a3/tweetie.js

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