-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.wtfstockphotos.min.js
1 lines (1 loc) · 1.38 KB
/
jquery.wtfstockphotos.min.js
1
(function(){!function($){return $.wtfstockphotos=function(el,options){var defaults,getNextImageUrl,init,plugin,replaceImages,shuffle;return defaults={limit:30},plugin=this,plugin.settings={},plugin.urls=[],getNextImageUrl=function(){var url;return url=plugin.urls.pop(),plugin.urls.unshift(url),url},replaceImages=function(){var _i,_len,_ref,_results;for(_ref=$(plugin.el),_results=[],_i=0,_len=_ref.length;_len>_i;_i++)el=_ref[_i],el.onerror=function(){return console.log("bad url"),el.src=getNextImageUrl()},_results.push(el.src=getNextImageUrl());return _results},shuffle=function(array){var i,j,temp,_i,_ref;for(i=_i=_ref=array.length-1;1>=_ref?1>=_i:_i>=1;i=1>=_ref?++_i:--_i)j=Math.floor(Math.random()*(i+1)),temp=array[i],array[i]=array[j],array[j]=temp;return array},init=function(){var req;return plugin.settings=$.extend({},defaults,options),plugin.el=el,req=$.ajax({url:"http://reddit.com/r/wtfstockphotos.json?limit="+plugin.settings.limit,dataType:"jsonp",jsonp:"jsonp"}),req.done(function(res){var post,posts;return posts=function(){var _i,_len,_ref,_results;for(_ref=res.data.children,_results=[],_i=0,_len=_ref.length;_len>_i;_i++)post=_ref[_i],_results.push(post);return _results}(),plugin.urls=shuffle(function(){var _i,_len,_results;for(_results=[],_i=0,_len=posts.length;_len>_i;_i++)post=posts[_i],_results.push(post.data.url);return _results}()),replaceImages()})},init()}}(jQuery)}).call(this);