forked from adrianengine/jquery-spectragram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spectragram.min.js
1 lines (1 loc) · 2.83 KB
/
spectragram.min.js
1
"function"!=typeof Object.create&&(Object.create=function(t){function e(){}return e.prototype=t,new e}),function(t,e,s,a){var i={API_URL:"https://api.instagram.com/v1",initialize:function(e,s){this.elem=s,this.$elem=t(s),this.accessToken=t.fn.spectragram.accessData.accessToken,this.options=t.extend({},t.fn.spectragram.options,e),this.endpoints=this.setEndpoints(),this.messages={defaultImageAltText:"Instagram Photo related with "+this.options.query,notFound:"This user account is private or doesn't have any photos."}},setEndpoints:function(){return{usersSelf:"/users/self/?access_token="+this.accessToken,usersMediaRecent:"/users/self/media/recent/?&count="+this.options.max+"&access_token="+this.accessToken,tagsMediaRecent:"/tags/"+this.options.query+"/media/recent?&count="+this.options.max+"&access_token="+this.accessToken}},getPhotos:function(e){var s=this;s.fetch(e).done(function(e){var a=s.options.query||"User";e.data.length?s.display(e):t.error("Spectragram.js - Error: "+a+" does not have photos.")})},getUserFeed:function(){this.getPhotos(this.endpoints.usersMediaRecent)},getRecentTagged:function(){this.getPhotos(this.endpoints.tagsMediaRecent)},fetch:function(e){var s=this.API_URL+e;return t.ajax({type:"GET",dataType:"jsonp",cache:!1,url:s})},display:function(e){var s,a,i,n,o,r,c,h,d,p=[];if(i=0===t(this.options.wrapEachWith).length,void 0===e.data||200!==e.meta.code||0===e.data.length)i?this.$elem.append(this.messages.notFound):this.$elem.append(t(this.options.wrapEachWith).append(this.messages.notFound));else{c=this.options.max>=e.data.length?e.data.length:this.options.max,h=this.options.size;for(var u=0;u<c;u++)"small"===h?(d=e.data[u].images.thumbnail.url,o=e.data[u].images.thumbnail.height,r=e.data[u].images.thumbnail.width):"medium"===h?(d=e.data[u].images.low_resolution.url,o=e.data[u].images.low_resolution.height,r=e.data[u].images.low_resolution.width):(d=e.data[u].images.standard_resolution.url,o=e.data[u].images.standard_resolution.height,r=e.data[u].images.standard_resolution.width),n=null!==e.data[u].caption?t("<span>").text(e.data[u].caption.text).html():this.messages.defaultImageAltText,a=t("<img>",{alt:n,attr:{height:o,width:r},src:d}),s=t("<a>",{href:e.data[u].link,target:"_blank",title:n}).append(a),i?p.push(s):p.push(t(this.options.wrapEachWith).append(s));this.$elem.append(p)}"function"==typeof this.options.complete&&this.options.complete.call(this)}};jQuery.fn.spectragram=function(e,s){jQuery.fn.spectragram.accessData.accessToken?this.each(function(){var a=Object.create(i);if(a.initialize(s,this),a[e])return a[e](this);t.error("Method "+e+" does not exist on jQuery.spectragram")}):t.error("You must define an accessToken on jQuery.spectragram")},jQuery.fn.spectragram.options={complete:null,max:20,query:"instagram",size:"medium",wrapEachWith:"<li></li>"},jQuery.fn.spectragram.accessData={accessToken:null}}(jQuery,window,document);