var tdbAutoload={};
(function(g,c,m){var p=g(document),k=g(c);tdbAutoload={original_post_id:null,loaded_posts:[],is_ajax_running:!1,init:function(){var a=g("#tdb-autoload-article");if(0!==a.length){var e=a.data("autoload"),b=a.data("autoload-type"),l=a.data("autoload-count"),d=a.data("autoload-org-post-id"),f=d,n=0;tdbAutoload.original_post_id=d;tdbAutoload.loaded_posts.push(d);tdbAutoload.log("%c tdbAutoload(inf) art. settings","background: #ffaa00; color: #ffffff; padding:3px 6px");tdbAutoload.log("tdbAutoload status: "+e);
tdbAutoload.log("tdbAutoload type: "+b);tdbAutoload.log("tdbAutoload original post id: "+d);tdbAutoload.log("tdbAutoload count: "+parseInt(l,10));tdbAutoload.log("tdbAutoload scroll percent: "+c.tdb_globals.autoloadScrollPercent);b=m.debounce(function(){tdbAutoload.log("ajax autoload > scroll");if(!0!==tdbAutoload.is_ajax_running){var b=100*k.scrollTop()/(p.height()-k.height()),e=c.tdb_globals.autoloadScrollPercent;(!l||n<parseInt(l,10))&&b>=e&&d===f&&(tdbAutoload._ajaxLoadingStart(a),tdbAutoload.is_ajax_running=
!0,g.ajax({timeout:5E4,type:"POST",url:tdbAutoload._getRestEndPoint("td-cloud-library/ajax_autoload","uid="+tdbAutoload._getUniqueID()),beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",c.tdb_globals.wpRestNonce);d=null},data:{currentPostId:f,originalPostId:tdbAutoload.original_post_id,loadedPosts:tdbAutoload.loaded_posts},success:function(b,e,h){null!==b&&void 0===b.error&&(void 0!==b.noPosts?tdbAutoload._ajaxLoadingEnd(a):(n++,e=g(b.article),g(e).appendTo(a.find(".tdc-content-wrap")),f=d=b.id,
tdbAutoload.loaded_posts.push(d),e.filter("#tdb-infinte-post-"+f+"-iframe").on("load",function(){var b=g(this);tdbAutoload.is_ajax_running=!1;tdbAutoload._ajaxLoadingEnd(a);b.css("opacity",1);setTimeout(function(){var a=b.contents().find("html").outerHeight(!0)+2;tdbAutoload.log("initial iframe load height set to: "+a);b.height(a)},50);b.contents().find("html").attr("id",b.attr("id"));b.contents().find(".grecaptcha-badge").css("visibility","hidden");var e=c.MutationObserver||c.WebKitMutationObserver||
c.MozMutationObserver,h=document.querySelector("#"+b.attr("id")),d=(h.contentDocument||h.contentWindow.document).getElementsByTagName("html"),n=m.debounce(function(){var a=d[0].offsetHeight;tdbAutoload.log("setHeight: height set to: "+a);b.height(a)},10);(new e(function(a){a.forEach(function(a){tdbAutoload.log("mutation occurred!");tdbAutoload.log(a);n()})})).observe(d[0],{childList:!0,subtree:!0})})))},error:function(a,b,e){}}))}},100);var h=m.debounce(function(){tdbAutoload.log("ajax_autoload > resize");
g(".tdb-autoload-wrap").find(".tdb-infinte-post-iframe").each(function(){var a=g(this);a.height(a.contents().find("html").outerHeight())})},100),q=m.debounce(function(){tdbAutoload.log("ajax autoload > scroll location change");tdbAutoload._locationChange()},10);"on"===e&&(k.scroll(b),k.scroll(q),k.resize(h),k.resize(function(){}),k.scroll(function(){}))}},_fixSmartSidebar:function(){var a=k.scrollTop(),e=a+k.height();g(".tdb-autoload-wrap").find("iframe").each(function(){var b=g(this),c=b.offset().top-
g("#wpadminbar").outerHeight(),d=b.outerHeight(!0);b=b.attr("id");c<a&&c+d>e&&document.getElementById(b).contentWindow.tdSmartSidebar.td_events_scroll(a-c)})},_locationChange:function(){var a=k.scrollTop(),e=a+k.height(),b=[];g(".tdb-autoload-wrap").find("article, iframe").each(function(){var c=g(this),h=g(".td-header-menu-wrap.td-affix");h=h.length?h.outerHeight():0;var d=g("#wpadminbar");d=d.length?d.outerHeight():0;if(!c.parent().hasClass("wpb_video_wrapper")){h=c.offset().top-(h+d);var f=c.outerHeight(!0);
d=c.data("post-url");var k=c.data("post-edit-url");c=c.data("post-title");f=h+f;h<a&&f>e?b.push({top:h,bottom:f,post_url:d,post_edit_url:k,post_title:c}):h>a&&h<e?b.push({top:h,bottom:f,post_url:d,post_edit_url:k,post_title:c}):f>a&&f<e&&b.push({top:h,bottom:f,post_url:d,post_edit_url:k,post_title:c})}});if(0===b.length){var l=c.location.href;var d=c.tdb_globals.origPostEditUrl;var f=document.title}else 1===b.length?(f=b.pop(),l=f.post_url,d=f.post_edit_url,f=f.post_title):(l=b[0].post_url,d=b[0].post_edit_url,
f=b[0].post_title);tdbAutoload._updatePostURL(l,d,f)},_updatePostURL:function(a,e,b){c.location.href===a||""===a||c.location.href.includes(a)||(c.history.replaceState(null,null,a),document.title=b,c.tdb_globals.isAdminBarShowing&&g("#wp-admin-bar-edit").find("a").attr("href",e))},_ajaxLoadingStart:function(a){g(".td-loader-gif").remove();a.find(".tdc-content-wrap").append('<div class="td-loader-gif td-loader-animation-start tdb-loader-autoload"></div>');tdLoadingBox.init(tds_theme_color_site_wide);
setTimeout(function(){g(".td-loader-gif").removeClass("td-loader-animation-start").addClass("td-loader-animation-mid")},50)},_ajaxLoadingEnd:function(a){a.find(".td-loader-gif").removeClass("td-loader-animation-mid").addClass("td-loader-animation-end");setTimeout(function(){a.find(".td-loader-gif").remove();tdLoadingBox.stop()},400)},_getRestEndPoint:function(a,e){return m.isEmpty(c.tdb_globals.permalinkStructure)?c.tdb_globals.wpRestUrl+a+"&"+e:c.tdb_globals.wpRestUrl+a+"?"+e},_getUniqueID:function(){function a(){return Math.floor(65536*
(1+Math.random())).toString(16).substring(1)}return a()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a()},log:function(a,c){}};p.ready(function(){tdbAutoload.init()})})(jQuery,this,_);
