1(function($) { 2 /* 3 jquery.twitter.js v1.6 4 Last updated: 16 October 2012 5 6 Created by Damien du Toit 7 http://coda.co.za/content/projects/jquery.twitter/ 8 9 Licensed under a Creative Commons Attribution-Non-Commercial 3.0 Unported License 10 http://creativecommons.org/licenses/by-nc/3.0/ 11 */ 12 13 $.fn.getTwitter = function(options) { 14 15 $.fn.getTwitter.defaults = { 16 userName: null, 17 numTweets: 5, 18 loaderText: "Loading tweets...", 19 slideIn: true, 20 slideDuration: 750, 21 showHeading: true, 22 headingText: "Latest Tweets", 23 showProfileLink: true, 24 showTimestamp: true, 25 includeRetweets: false, 26 excludeReplies: true 27 }; 28 29 var o = $.extend({}, $.fn.getTwitter.defaults, options); 30 31 return this.each(function() { 32 var c = $(this); 33 34 // hide container element, remove alternative content, and add class 35 c.hide().empty().addClass("twitted"); 36 37 // add heading to container element 38 if (o.showHeading) { 39 c.append("<h2>"+o.headingText+"</h2>"); 40 } 41 42 // add twitter list to container element 43 var twitterListHTML = "<ul id=\"twitter_update_list\"></ul>"; 44 c.append(twitterListHTML); 45 46 var tl = $("#twitter_update_list"); 47 48 // hide twitter list 49 tl.hide(); 50 51 // add preLoader to container element 52 var preLoaderHTML = $("<p class=\"preLoader\">"+o.loaderText+"</p>"); 53 c.append(preLoaderHTML); 54 55 // add Twitter profile link to container element 56 if (o.showProfileLink) { 57 var profileLinkHTML = "<p class=\"profileLink\"><a href=\"https://twitter.com/"+o.userName+"\">https://twitter.com/"+o.userName+"</a></p>"; 58 c.append(profileLinkHTML); 59 } 60 61 // show container element 62 c.show(); 63 64 // request (o.numTweets + 20) to avoid not having enough tweets if includeRetweets = false and/or excludeReplies = true 65 window.jsonTwitterFeed = "https://api.twitter.com/1/statuses/user_timeline.json?include_rts="+o.includeRetweets+"&excludeReplies="+o.excludeReplies+"&screen_name="+o.userName+"&count="+(o.numTweets + 20); 66 67 $.ajax({ 68 url: jsonTwitterFeed, 69 data: {}, 70 dataType: "jsonp", 71 callbackParameter: "callback", 72 timeout: 50000, 73 success: function(data) { 74 window.count = 0; 75 76 $.each(data, function(key, val) { 77 var tweetHTML = "<li><span>" + replaceURLWithHTMLLinks(val.text) + "</span>"; 78 79 if (o.showTimestamp) tweetHTML += " <a style=\"font-size:85%\" href=\"https://twitter.com/" + o.userName + "/statuses/" + val.id_str + "\">" + relative_time(val.created_at) + "</a>"; 80 81 tweetHTML += "</li>"; 82 83 $("#twitter_update_list").append(tweetHTML); 84 85 count++; 86 87 if (count == o.numTweets) { 88 // remove preLoader from container element 89 $(preLoaderHTML).remove(); 90 91 // show twitter list 92 if (o.slideIn) { 93 // a fix for the jQuery slide effect 94 // Hat-tip: http://blog.pengoworks.com/index.cfm/2009/4/21/Fixing-jQuerys-slideDown-effect-ie-Jumpy-Animation 95 var tlHeight = tl.data("originalHeight"); 96 97 // get the original height 98 if (!tlHeight) { 99 tlHeight = tl.show().height(); 100 tl.data("originalHeight", tlHeight); 101 tl.hide().css({height: 0}); 102 } 103 104 tl.show().animate({height: tlHeight}, o.slideDuration); 105 } 106 else { 107 tl.show(); 108 } 109 110 // add unique class to first list item 111 tl.find("li:first").addClass("firstTweet"); 112 113 // add unique class to last list item 114 tl.find("li:last").addClass("lastTweet"); 115 116 return false; 117 } 118 }); 119 }, 120 error: function(XHR, textStatus, errorThrown) { 121 //alert("Error: " + textStatus); 122 //alert("Error: " + errorThrown); 123 } 124 }); 125 }); 126 127 function replaceURLWithHTMLLinks(text) { 128 var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; 129 return text.replace(exp, "<a href=\"$1\">$1</a>"); 130 } 131 132 // sourced from https://twitter.com/javascripts/blogger.js 133 function relative_time(time_value) { 134 var values = time_value.split(" "); 135 time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3]; 136 var parsed_date = Date.parse(time_value); 137 var relative_to = (arguments.length > 1) ? arguments[1] : new Date(); 138 var delta = parseInt((relative_to.getTime() - parsed_date) / 1000); 139 delta = delta + (relative_to.getTimezoneOffset() * 60); 140 141 if (delta < 60) { 142 return "less than a minute ago"; 143 } 144 else if (delta < 120) { 145 return "about a minute ago"; 146 } 147 else if (delta < (60*60)) { 148 return (parseInt(delta / 60)).toString() + " minutes ago"; 149 } 150 else if (delta < (120*60)) { 151 return "about an hour ago"; 152 } 153 else if (delta < (24*60*60)) { 154 return "about " + (parseInt(delta / 3600)).toString() + " hours ago"; 155 } 156 else if (delta < (48*60*60)) { 157 return "1 day ago"; 158 } 159 else { 160 return (parseInt(delta / 86400)).toString() + " days ago"; 161 } 162 } 163 }; 164})(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.