seb86/Auto-Load-Next-Post

View on GitHub
assets/js/frontend/auto-load-next-post.min.js

Summary

Maintainability
A
0 mins
Test Coverage
/*! Auto Load Next Post v1.6.0-beta.1 Thursday 5th September 2019 22:50:39 PM GMT+0200 */
var version=auto_load_next_post_params.alnp_version,content_container=auto_load_next_post_params.alnp_content_container,post_title_selector=auto_load_next_post_params.alnp_title_selector,nav_container=auto_load_next_post_params.alnp_navigation_container,comments_container=auto_load_next_post_params.alnp_comments_container,remove_comments=auto_load_next_post_params.alnp_remove_comments,track_pageviews=auto_load_next_post_params.alnp_google_analytics,is_customizer=auto_load_next_post_params.alnp_is_customizer,is_mobile=auto_load_next_post_params.alnp_is_mobile,event_on_load=auto_load_next_post_params.alnp_event_on_load,event_on_entering=auto_load_next_post_params.alnp_event_on_entering,post_title=window.document.title,curr_url=window.location.href,orig_curr_url=window.location.href,post_count=0,post_url=curr_url,overridden_post_url="",stop_reading=!1,scroll_up=!1,article_container="article",ready=auto_load_next_post_params.alnp_load_in_footer,disable_mobile=auto_load_next_post_params.alnp_disable_mobile;!function(s){if("undefined"==typeof auto_load_next_post_params)return;if("yes"==is_mobile&&disable_mobile)return;if(content_container.length<=0)return;if(post_title_selector.length<=0)return;if(nav_container.length<=0)return;function t(){if(s("article").length<=0&&(article_container="div"),!(-1<orig_curr_url.indexOf("#comments")||orig_curr_url.match(/#comment-*([0-9]+)/)||-1<orig_curr_url.indexOf("#respond"))){s(content_container).prepend('<hr style="height:0px;margin:0px;padding:0px;border:none;" data-powered-by="alnp" data-initial-post="true" data-title="'+post_title+'" data-url="'+orig_curr_url+'"/>'),s(content_container).find(article_container).attr("data-initial-post",!0);var t=s(content_container).find(article_container).attr("id");void 0!==t&&0<t.length&&(t=t.replace("post-",""),s(content_container).find("article[data-initial-post]").prev().attr("data-post-id",t)),"yes"===remove_comments&&(s(comments_container).remove(),0<s("#disqus_thread").length&&s("#disqus_thread").remove()),p(),s("body").on("alnp-post-changed",function(t,e,r,n,a,o){"yes"==track_pageviews&&"yes"!=is_customizer&&("undefined"==typeof _gaq&&"undefined"==typeof ga&&"undefined"==typeof __gaTracker||(r=r.replace(/https?:\/\/[^\/]+/i,""),"undefined"!=typeof _gaq&&null!==_gaq&&_gaq.push(["_trackPageview",r]),"undefined"!=typeof ga&&null!==ga&&ga("send","pageview",r),"undefined"!=typeof __gaTracker&&null!==__gaTracker&&__gaTracker("send","pageview",r)))}),s("body").on("mousewheel",function(t){scroll_up=0<t.originalEvent.wheelDelta}),is_customizer||History.Adapter.bind(window,"statechange",function(){var t=History.getState();if(scroll_up){var e=History.savedStates;if(e[e.length-2].url===orig_curr_url)return void(window.location=document.referrer)}if(t.url!=curr_url){var r=s('hr[data-url="'+t.url+'"]').next(article_container).find(post_title_selector);if(0<r.length){var n=r[0].dataset.title;History.pushState(null,n,t.url),s("html, body").animate({scrollTop:r.offset().top-100},1e3,function(){s("body").trigger("alnp-previous-post",[r])})}}})}}function p(){0<post_count&&s('hr[data-powered-by="alnp"]').on("scrollSpy:enter",e),s('hr[data-powered-by="alnp"]').on("scrollSpy:exit",r),s('hr[data-powered-by="alnp"]').scrollSpy()}function d(t,e){if("string"==typeof t){var r=jQuery("body");t=t.split(",");for(var n=0;n<t.length;n++)t[n]=t[n].replace(/^\s\s*/,"").replace(/\s\s*$/,""),r.trigger(t[n],e);return this}}function e(){var t=s(this);s("body").trigger("alnp-enter",[t]),d(event_on_entering,[t]),n(t,"enter")}function r(){var t=s(this);s("body").trigger("alnp-leave",[t]),n(t,"leave")}function n(t,e){var r=s(t),n=r.attr("data-url"),a=r.attr("data-title"),o=r.attr("data-post-id"),i=r.attr("data-initial-post"),_=r.offset(),l=s(document).scrollTop();_.top-l<=200&&curr_url!=n&&(curr_url=n,is_customizer||History.pushState(null,a,n),s("body").trigger("alnp-post-changed",[a,n,o,post_count,stop_reading,i])),"leave"==e&&function(){if(stop_reading)return;if(overridden_post_url="",s(nav_container).length<=0)return;(post_url=s(nav_container).find('a[rel="prev"]').attr("href"))||(post_url=s(nav_container).find('a[rel="previous"]').attr("href"));"yes"==is_customizer&&(post_url=post_url.substring(0,post_url.indexOf("?")));s("body").trigger("alnp-post-url",[post_count,post_url]),overridden_post_url&&(post_url=overridden_post_url);if(!post_url)return;var t="";if(-1<post_url.indexOf("?p="))t=post_url+"&alnp=1";else{var e="alnp/";"/"!=post_url.charAt(post_url.length-1)&&(e="/"+e),t=post_url+e}s(nav_container).remove(),s.get(t,function(t){var e=s("<div>"+t+"</div>");s("body").trigger("alnp-post-data",[e]),t=e.html();var r='<hr style="height:0px;margin:0px;padding:0px;border:none;" data-powered-by="alnp" data-initial-post="false" data-url="'+post_url+'"/>',n=s(r+t),a=n.find(post_title_selector),o=s(e).find(article_container).attr("id"),i=[a.text(),post_url,o,post_count];void 0!==o&&""!==o&&(o=o.replace("post-","")),s(content_container).append(n),s(article_container+'[id="post-'+o+'"]').attr("data-initial-post",!1),"yes"===remove_comments&&(s(comments_container).remove(),0<s("#disqus_thread").length&&s("#disqus_thread").remove()),s('hr[data-url="'+post_url+'"]').attr("data-title",a.text()).attr("data-post-id",o),p(),post_count+=1,s("body").trigger("alnp-post-loaded",i),d(event_on_load,i)})}()}0==ready&&s(document).ready(function(){t()}),ready&&t()}(jQuery);