(function($){var Scroller,ajaxurl,stats,type,text,totop,timer;var isIE=(-1!=navigator.userAgent.search('MSIE'));if(isIE){var IEVersion=navigator.userAgent.match(/MSIE\s?(\d+)\.?\d*;/);var IEVersion=parseInt(IEVersion[1]);} Scroller=function(settings){var self=this;this.id=settings.id;this.body=$(document.body);this.window=$(window);this.element=($('#'+settings.id).length)?$('#'+settings.id):$('.'+settings.id);this.wrapperClass=settings.wrapper_class;this.ready=true;this.disabled=false;this.page=1;this.offset=settings.offset;this.currentday=settings.currentday;this.order=settings.order;this.throttle=false;this.handle='
'+text.replace('\\','')+'
';this.click_handle=settings.click_handle;this.google_analytics=settings.google_analytics;this.history=settings.history;this.origURL=window.location.href;this.postID=settings.postID;this.postTitle=settings.postTitle;this.origTitle=document.title;this.postUrl=settings.postUrl;this.curPage=0;this.the_titles=[];this.the_urls=[];this.debug=false;this.footer=$('#infinite-footer');this.footer.wrap=settings.footer;this.the_post_url=[];this.the_post_title=[];this.wpMediaelement=null;if(type=='scroll'){this.window.bind('scroll.infinity',function(){this.throttle=true;});self.gotop();setInterval(function(){if(this.throttle){this.throttle=false;self.thefooter();self.refresh();}},300);self.ensureFilledViewport();this.body.bind('post-load',{self:self},self.checkViewportOnLoad);this.body.bind('post-load',{self:self},self.initializeMejs);}else if(type=='click'){if(this.click_handle){this.element.append(this.handle);} this.body.delegate('#infinite-handle','click.infinity',function(){if(self.click_handle){$('#infinite-handle').remove();} self.refresh();});}};Scroller.prototype.check=function(){var container=this.element.offset();if('object'!==typeof container){return false;} var bottom=this.window.scrollTop()+this.window.height(),threshold=container.top+this.element.outerHeight(false)-(this.window.height()*2);return bottom>threshold;};Scroller.prototype.render=function(response){this.body.addClass('infinity-success');this.element.append(response.html);this.body.trigger('post-load',response);this.ready=true;};Scroller.prototype.query=function(){return{page:this.page,currentday:this.currentday,order:this.order,postID:window.infiniteScroll.settings.postID,postID_order:this.postID,postTitle:this.postTitle,postUrl:this.postUrl,scripts:window.infiniteScroll.settings.scripts,styles:window.infiniteScroll.settings.styles,query_args:window.infiniteScroll.settings.query_args,last_post_date:window.infiniteScroll.settings.last_post_date,version:new Date().getTime()};};Scroller.prototype.gotop=function(){var blog=$('#infinity-blog-title');blog.attr('title',totop);blog.bind('click',function(e){$('html, body').animate({scrollTop:0},'fast');e.preventDefault();});};Scroller.prototype.thefooter=function(){var self=this,width;if($.type(this.footer.wrap)==="string"){width=$('body #'+this.footer.wrap).outerWidth(false);if(width>479) this.footer.find('.container').css('width',width);} if(this.window.scrollTop()>=350) self.footer.animate({'bottom':0},'fast');else if(this.window.scrollTop()<350) self.footer.animate({'bottom':'-50px'},'fast');};Scroller.prototype.refresh=function(){var self=this,query,jqxhr,load,loader,color;if(this.disabled||!this.ready||!this.check()) return;this.ready=false;if(this.click_handle){if(!$('.infinite-loader').length){$('.site-container').append('');} loader=$('.infinite-loader');} query=$.extend({action:'infinite_transporter'},this.query());jqxhr=$.get(infiniteScroll.settings.ajaxurl,query);jqxhr.fail(function(){if(self.click_handle){loader.hide();} self.ready=true;});jqxhr.done(function(response){if(self.click_handle){loader.hide();} if(!response) return;response=$.parseJSON(response);if(!response||!response.type) return;if(response.type=='empty'){self.disabled=true;self.body.addClass('infinity-end').removeClass('infinity-success');}else if(response.type=='success'){if(response.scripts){$(response.scripts).each(function(){var elementToAppendTo=this.footer?'body':'head';window.infiniteScroll.settings.scripts.push(this.handle);if(this.extra_data){var data=document.createElement('script'),dataContent=document.createTextNode("//");data.type='text/javascript';data.appendChild(dataContent);document.getElementsByTagName(elementToAppendTo)[0].appendChild(data);} var script=document.createElement('script');script.type='text/javascript';script.src=this.src;script.id=this.handle;if('wp-mediaelement'===this.handle){self.body.unbind('post-load',self.initializeMejs);} if('wp-mediaelement'===this.handle&&'undefined'===typeof mejs){self.wpMediaelement={};self.wpMediaelement.tag=script;self.wpMediaelement.element=elementToAppendTo;setTimeout(self.maybeLoadMejs.bind(self),250);}else{document.getElementsByTagName(elementToAppendTo)[0].appendChild(script);}});} if(response.styles){$(response.styles).each(function(){window.infiniteScroll.settings.styles.push(this.handle);var style=document.createElement('link');style.rel='stylesheet';style.href=this.src;style.id=this.handle+'-css';if(this.conditional&&(!isIE||!eval(this.conditional.replace(/%ver/g,IEVersion)))) var style=false;if(style) document.getElementsByTagName('head')[0].appendChild(style);});} self.page++;self.render.apply(self,arguments);if(type=='click'){if(response.lastbatch){if(self.click_handle){$('#infinite-handle').remove();}else{self.body.trigger('infinite-transporter-posts-end');}}else{if(self.click_handle){self.element.append(self.handle);}else{self.body.trigger('infinite-transporter-posts-more');}}} if(response.currentday) self.currentday=response.currentday;if(response.postID){self.postID=response.postID;self.postTitle=response.postTitle;self.postUrl=response.postUrl;self.the_post_url.push(response.postUrl);self.the_post_title.push(response.postTitle);} if(self.google_analytics){if(typeof self.postID=='undefined'){var ga_url=self.history.path.replace(/%d/,self.page);}else{var ga_url=response.postPath;} if('object'===typeof _gaq){_gaq.push(['_trackPageview',ga_url]);} if('function'===typeof ga){ga('send','pageview',ga_url);}}}});return jqxhr;};Scroller.prototype.maybeLoadMejs=function(){if(null===this.wpMediaelement){return;} if('undefined'===typeof mejs){setTimeout(this.maybeLoadMejs,250);}else{document.getElementsByTagName(this.wpMediaelement.element)[0].appendChild(this.wpMediaelement.tag);this.wpMediaelement=null;this.body.bind('post-load',{self:this},this.initializeMejs);}} Scroller.prototype.initializeMejs=function(ev,response){if(-1===response.html.indexOf('wp-audio-shortcode')&&-1===response.html.indexOf('wp-video-shortcode')){return;} if('undefined'===typeof mejs){return;} $(function(){var settings={};if(typeof _wpmejsSettings!=='undefined'){settings.pluginPath=_wpmejsSettings.pluginPath;} settings.success=function(mejs){var autoplay=mejs.attributes.autoplay&&'false'!==mejs.attributes.autoplay;if('flash'===mejs.pluginType&&autoplay){mejs.addEventListener('canplay',function(){mejs.play();},false);}};$('.wp-audio-shortcode, .wp-video-shortcode').not('.mejs-container').mediaelementplayer(settings);});} Scroller.prototype.ensureFilledViewport=function(){var self=this,windowHeight=self.window.height(),postsHeight=self.element.height() aveSetHeight=0,wrapperQty=0;if(postsHeight===0){$(self.element.selector+' > li').each(function(){postsHeight+=$(this).height();});if(postsHeight===0){self.body.unbind('post-load',self.checkViewportOnLoad);return;}} $('.'+self.wrapperClass).each(function(){aveSetHeight+=$(this).height();wrapperQty++;});if(wrapperQty>0) aveSetHeight=aveSetHeight/wrapperQty;else aveSetHeight=0;if(postsHeight *',this).each(function(){setHeight+=$(this).outerHeight(false);});} setBottom=setTop+setHeight;var tmp_post_url=typeof self.the_post_url==='undefined'||typeof self.the_post_url[0]==='undefined'?'':self.the_post_url[0];var tmp_post_title=typeof self.the_post_title==='undefined'||typeof self.the_post_url[0]==='undefined'?'':self.the_post_title[0];self.debugInfinity('the_post_url: '+tmp_post_url);self.debugInfinity('the_post_title: '+tmp_post_title);if(setTopwindowBottom){setsInView.push({'id':id,'top':setTop,'bottom':setBottom,'pageNum':setPageNum,'post_url':tmp_post_url,'post_title':tmp_post_title});}else if(setTop>windowTop&&setTopwindowTop&&setBottomself.curPage&&window.location.href!=post_url){self.curPage=pageNum;self.debugInfinity('self.curPage'+self.curPage);self.debugInfinity('pageNum'+pageNum);if(post_url!=''){history.replaceState(null,null,post_url);self.the_urls[pageNum]=post_url;self.the_titles[pageNum]=post_title;document.title=post_title;} if(typeof self.the_post_url!=='undefined'){self.the_post_url.shift();} if(typeof self.the_post_title!=='undefined'){self.the_post_title.shift();}}else if(self.the_urls[pageNum]!=window.location.href){if(pageNum==-1){history.replaceState(null,null,self.origURL);if(self.origTitle!=undefined){document.title=self.origTitle;}}else{history.replaceState(null,null,self.the_urls[pageNum]);if(self.the_titles[pageNum]!=undefined){document.title=self.the_titles[pageNum];}}}}} Scroller.prototype.debugInfinity=function(message){var self=window.infiniteScroll.scroller;if(self.debug){console.log("Infinity: "+message);}} Scroller.prototype.updateURL=function(page){var self=this,offset=self.offset>0?self.offset-1:0,pageSlug=-1==page?self.origURL:window.location.protocol+'//'+self.history.host+self.history.path.replace(/%d/,page+offset)+self.history.parameters;if(window.location.href!=pageSlug){history.pushState(null,null,pageSlug);}} $(document).ready(function(){if('object'!=typeof infiniteScroll) return;ajaxurl=infiniteScroll.settings.ajaxurl;stats=infiniteScroll.settings.stats;type=infiniteScroll.settings.type;text=infiniteScroll.settings.text;totop=infiniteScroll.settings.totop;infiniteScroll.scroller=new Scroller(infiniteScroll.settings);if(!isIE||(isIE&&IEVersion>=10)){$(window).bind('scroll',function(){clearTimeout(timer);timer=setTimeout(infiniteScroll.scroller.determineURL,100);});}});})(jQuery);