seb86/Auto-Load-Next-Post

View on GitHub
assets/js/admin/scanner.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 */
!function(o,s){var a,l,t="",n=!0,e=!1,i=s.is_rtl,d=s.ajax_url,c=0,r=0,p="",u="",m="",f="";function _(t){o.get(s.random_page,function(e){e&&(-1!==e?o(".template-location-results .meter").removeClass("blue").removeClass("animate"):o(".template-location-results .meter").removeClass("blue").addClass("red").removeClass("animate"),setTimeout(function(){n=!1,o(".box.template-location-results").removeClass("show-box").fadeOut(),o(".box.theme-selector-results").addClass("show-box").fadeIn(),-1!==e&&(a=o("<div>"+e+"</div>")),""!=(a=a.html())&&(l=o.dialog({icon:"dashicons dashicons-search",title:s.i18n_scanning_theme,content:"<p>"+s.i18n_scanning_theme_content+"</p>",rtl:i,type:"orange",draggable:!1,closeIcon:!1,boxWidth:"500px",useBootstrap:!1}),window.setTimeout(v,8e3),o("span.post-tested").text(s.random_page),g("alnp_get_container_selectors"),g("alnp_get_title_selectors"),g("alnp_get_post_navigation_selectors"),g("alnp_get_comment_selectors"),o("button.rescan").prop("disabled",!1))},t))})}function g(n){o.ajax({method:"GET",url:d+"?action="+n,dataType:"json",success:function(e){o(e).each(function(e,t){0<o(a).find(t).length?("alnp_get_container_selectors"==n&&""==p&&(o(".selectors").find(".container").removeClass("pending").addClass("found"),o(".results-found").find(".container").addClass("found"),o(".results-found").find(".container span.result").html('<code title="'+s.i18n_copy_title+'">'+t+"</code>"),p=t,c+=1),"alnp_get_title_selectors"==n&&""==u&&(o(".selectors").find(".title").removeClass("pending").addClass("found"),o(".results-found").find(".title").addClass("found"),o(".results-found").find(".title span.result").html('<code title="'+s.i18n_copy_title+'">'+t+"</code>"),u=t,c+=1),"alnp_get_post_navigation_selectors"==n&&""==m&&(o(".results-available").fadeIn("fast"),o(".selectors").find(".navigation").removeClass("pending").addClass("found"),o(".results-found").find(".navigation").addClass("found"),o(".results-found").find(".navigation span.result").html('<code title="'+s.i18n_copy_title+'">'+t+"</code>"),m=t,c+=1),"alnp_get_comment_selectors"==n&&""==f&&(o(".selectors").find(".comments").removeClass("pending").addClass("found"),o(".results-found").find(".comments").addClass("found"),o(".results-found").find(".comments span.result").html('<code title="'+s.i18n_copy_title+'">'+t+"</code>"),f=t,c+=1)):("alnp_get_container_selectors"==n&&""==p&&(o(".results-found").find(".container").removeClass("pending").addClass("not-found"),r+=1),"alnp_get_title_selectors"==n&&""==u&&(o(".results-found").find(".title").removeClass("pending").addClass("not-found"),o(".results-found").find(".title span.result").html('Unable to detect a post title. <a href="https://github.com/autoloadnextpost/alnp-documentation/blob/master/en_US/post-title.md" class="help-tip" target="_blank" title="Click to view documenation on post title" aria-label="View documenation on post title">?</a>'),r+=1),"alnp_get_post_navigation_selectors"==n&&""==m&&(o(".no-post-navigation").fadeIn("fast"),o(".results-found").find(".navigation").removeClass("pending").addClass("not-found"),o(".results-found").find(".navigation span.result").html('Unable to detect a post navigation. <a href="https://github.com/autoloadnextpost/alnp-documentation/blob/master/en_US/post-navigation.md" class="help-tip" target="_blank" title="Click to view documenation on post navigation" aria-label="View documenation on post navigation">?</a>'),r+=1),"alnp_get_comment_selectors"==n&&""==f&&(o(".results-found").find(".comments").removeClass("pending").addClass("not-found"),r+=1))})}})}function h(t,e){o.post(d,{action:"alnp_set_setting",setting:t,value:e}).done(function(e){e?console.log("Setting: "+t+" saved!"):console.log("No response!")})}function v(){0<o.active?window.setTimeout(v,8e3):e=n=!0,n&&(o(".theme-selectors.debug-mode").show(),4==c&&0==r&&(o(".setup-complete").show(),o(".rescan").hide()),1<r&&o(".theme-selectors-undetected").show(),l.isOpen()&&(c<4&&""==m?(l.close(),l=o.dialog({icon:"dashicons dashicons-warning",title:s.i18n_post_nav_missing,content:"<p>"+s.i18n_error_post_nav+"</p>",rtl:i,type:"red",draggable:!1,closeIcon:!0,boxWidth:"500px",useBootstrap:!1})):l.close())),e&&0<c&&(""!=p&&h("content_container",p),""!=u&&h("title_selector",u),""!=m&&h("navigation_container",m),""!=f&&h("comments_container",f))}i="rtl"==i,o("a.scan-button").on("click",function(e){t=o(this).data("step"),e.preventDefault(),"template-location"==t&&(o(".enter .meter").show(),o.get(d,{action:"alnp_find_template_location"},function(e){e&&(-1!==e?o(".enter .meter").removeClass("blue").removeClass("animate"):o(".enter .meter").removeClass("blue").addClass("red").removeClass("animate"),setTimeout(function(){o("h1").fadeOut().hide(),o(".box.enter").removeClass("show-box").fadeOut(),o(".box.template-location-results").addClass("show-box").fadeIn(),t=o(".box").find("a.scan-button:visible").data("step"),-1!==e?(o("span.location").text(e),o(".template-location.debug-mode").show(),o("p.template-found").fadeIn().show()):(o("p.no-template-found").fadeIn().show(),o("a.button-doc").fadeIn().show())},1400))})),"theme-selectors"==t&&(o(".template-location-results .meter").show(),_(1400))}),o("div.found span.result code, span.location, span.post-tested").on("click",function(e){var t=o("<input>"),n=o(this).text();o("body").append(t),t.val(n).select(),document.execCommand("copy"),t.remove(),l=o.dialog({icon:"dashicons dashicons-info",title:s.i18n_copied,content:"<p><strong>"+n+"</strong></p>",rtl:i,type:"blue",draggable:!1,closeIcon:!1,boxWidth:"500px",useBootstrap:!1}),setTimeout(function(){l.isOpen()&&l.close()},2e3)}),o("button.rescan").on("click",function(){o(this).prop("disabled",!0),c=0,m="",n=!1;var e=o.dialog({icon:"dashicons dashicons-info",title:s.i18n_please_wait,content:"<p>"+s.i18n_loading_post+"</p>",rtl:i,type:"blue",draggable:!1,closeIcon:!1,boxWidth:"500px",useBootstrap:!1});setTimeout(function(){e.close()},4e3),_(1e3)})}(jQuery,alnp_scanner_params);