diff --git a/build/tweetlight.min.js b/build/tweetlight.min.js index 4d1acd0..fd0e139 100644 --- a/build/tweetlight.min.js +++ b/build/tweetlight.min.js @@ -1,2 +1,2 @@ -/*! tweetlight 4.1.2 | (c) 2015 Pedro Rogério | MIT License */ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define("tweetlight",b):"object"==typeof exports?module.exports=b():a.Tweetlight=b()}(this,function(){"use strict";var a=function(b){return this&&this instanceof a?(this.username=b.username,this.hashtag=b.hashtag,this.container=b.container,this.counter=b.counter,this.showImageProfile=b.showImageProfile||!1,this.endpoint="../request.php",this.onComplete=b.onComplete||function(){},void this.fetch()):new a(b)};return a.prototype={fetch:function(){var a=this.hashtag?"hashtag="+encodeURIComponent(this.hashtag):"username="+this.username,b=this.counter?"&count="+this.counter:"",c=this.endpoint+"?"+a+b;this.getJSON(c,this.loadTweets)},getJSON:function(a,b){var c=new XMLHttpRequest,d=this;c.open("GET",a,!0),c.onreadystatechange=function(){if(4===this.readyState){if(!(this.status>=200&&this.status<400))throw new Error(this.status+" - "+this.statusText);var a=JSON.parse(this.responseText);b.call(d,a)}},c.send(),c=null},loadTweets:function(a){var b=a.httpstatus;200===b?(a.statuses&&(a=a.statuses),this.displayTweets(a),this.onComplete()):this.displayError(a)},displayTweets:function(a){var b,c,d=document.querySelector(this.container),e="";for(c in a)a.hasOwnProperty(c)&&a[c].text&&(b=this.showImageProfile?''+a[c].user.name+'':"",e+="
  • "+b+''+this.twitterLinks(a[c].text)+''+this.prettyDate(a[c].created_at)+"
  • ");d.innerHTML=e},displayError:function(a){var b=document.querySelector(this.container);b.innerHTML='
  • '+a.errors[0].message+"
  • "},prettyDate:function(a){var b,c,d,e,f,g,h=new Date,i=new Date(a);return(-1!==navigator.userAgent.indexOf("MSIE")||navigator.appVersion.indexOf("Trident/")>0)&&(i=Date.parse(a.replace(/( \+)/," UTC$1"))),b=h-i,c=1e3,d=60*c,e=60*d,f=24*e,g=7*f,isNaN(b)||0>b?"":2*c>b?"just now":d>b?Math.floor(b/c)+" seconds ago":2*d>b?"1 minute ago":e>b?Math.floor(b/d)+" minutes ago":2*e>b?"1 hour ago":f>b?Math.floor(b/e)+" hours ago":b>f&&2*f>b?"yesterday":365*f>b?Math.floor(b/f)+" days ago":"over a year ago"},twitterLinks:function(a){return a=a.replace(/(https?:\/\/)([\w\-:;?&=+.%#\/]+)/gi,'$2').replace(/(^|\W)@(\w+)/g,'$1@$2').replace(/(^|\W)#(\w+)/g,'$1#$2')}},a}); \ No newline at end of file +/*! tweetlight 4.2.1 | (c) 2015 Pedro Rogério | MIT License */ +!function(a,b){"use strict";"function"==typeof define&&define.amd?define("tweetlight",b):"object"==typeof exports?module.exports=b():a.Tweetlight=b()}(this,function(){"use strict";var a=function(b){return this&&this instanceof a?(this.username=b.username,this.hashtag=b.hashtag,this.container=b.container,this.counter=b.counter,this.showImageProfile=b.showImageProfile||!1,this.endpoint="../request.php",this.onComplete=b.onComplete||void 0,void this.fetch()):new a(b)};return a.prototype={fetch:function(){var a=this.hashtag?"hashtag="+encodeURIComponent(this.hashtag):"username="+this.username,b=this.counter?"&count="+this.counter:"",c=this.endpoint+"?"+a+b;this.getJSON(c,this.loadTweets)},getJSON:function(a,b){var c=new XMLHttpRequest,d=this;c.open("GET",a,!0),c.onreadystatechange=function(){if(4===this.readyState){if(!(this.status>=200&&this.status<300||304===this.status))throw new Error(this.status+" - "+this.statusText);var a=JSON.parse(this.responseText);b.call(d,a)}},c.send(),c=null},loadTweets:function(a){var b=a.httpstatus;200===b?(a.statuses&&(a=a.statuses),this.displayTweets(a),"function"==typeof this.onComplete&&this.onComplete.call()):this.displayError(a)},displayTweets:function(a){var b,c,d=document.querySelector(this.container),e="";for(c in a)a.hasOwnProperty(c)&&a[c].text&&(b=this.showImageProfile?''+a[c].user.name+'':"",e+="
  • "+b+''+this.twitterLinks(a[c].text)+''+this.prettyDate(a[c].created_at)+"
  • ");d.innerHTML=e},displayError:function(a){var b=document.querySelector(this.container);b.innerHTML='
  • '+a.errors[0].message+"
  • "},prettyDate:function(a){var b,c,d,e,f,g,h=new Date,i=new Date(a);return(-1!==navigator.userAgent.indexOf("MSIE")||navigator.appVersion.indexOf("Trident/")>0)&&(i=Date.parse(a.replace(/( \+)/," UTC$1"))),b=h-i,c=1e3,d=60*c,e=60*d,f=24*e,g=7*f,isNaN(b)||0>b?"":2*c>b?"just now":d>b?Math.floor(b/c)+" seconds ago":2*d>b?"1 minute ago":e>b?Math.floor(b/d)+" minutes ago":2*e>b?"1 hour ago":f>b?Math.floor(b/e)+" hours ago":b>f&&2*f>b?"yesterday":365*f>b?Math.floor(b/f)+" days ago":"over a year ago"},twitterLinks:function(a){return a=a.replace(/(https?:\/\/)([\w\-:;?&=+.%#\/]+)/gi,'$2').replace(/(^|\W)@(\w+)/g,'$1@$2').replace(/(^|\W)#(\w+)/g,'$1#$2')}},a}); \ No newline at end of file diff --git a/src/tweetlight.js b/src/tweetlight.js index 1eadd3d..c887aa6 100644 --- a/src/tweetlight.js +++ b/src/tweetlight.js @@ -24,7 +24,7 @@ this.counter = options.counter; this.showImageProfile = options.showImageProfile || false; this.endpoint = '../request.php'; - this.onComplete = options.onComplete || function () {}; + this.onComplete = options.onComplete || undefined; this.fetch(); }; @@ -44,7 +44,7 @@ xhttp.open('GET', path, true); xhttp.onreadystatechange = function () { if (this.readyState === 4) { - if (this.status >= 200 && this.status < 400) { + if ((this.status >= 200 && this.status < 300) || this.status === 304) { var json = JSON.parse(this.responseText); callback.call(self, json); } else { @@ -65,7 +65,7 @@ this.displayTweets(tweets); - this.onComplete(); + typeof this.onComplete === 'function' && this.onComplete.call(); } else { this.displayError(tweets); }