var tdbAutoload={};
(function(g,d,m){var p=g(document),k=g(d);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"),c=a.data("autoload-org-post-id"),h=c,f=0;tdbAutoload.original_post_id=c;tdbAutoload.loaded_posts.push(c);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: "+c);tdbAutoload.log("tdbAutoload count: "+parseInt(l,10));tdbAutoload.log("tdbAutoload scroll percent: "+d.tdb_p_autoload_vars.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=d.tdb_p_autoload_vars.autoloadScrollPercent;(!l||f<parseInt(l,10))&&b>=e&&c===h&&(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()),data:{currentPostId:h,originalPostId:tdbAutoload.original_post_id,loadedPosts:tdbAutoload.loaded_posts},success:function(b,e,n){null!==b&&void 0===b.error&&(void 0!==b.noPosts?tdbAutoload._ajaxLoadingEnd(a):(f++,e=g(b.article),g(e).appendTo(a.find(".tdc-content-wrap")),h=c=b.id,tdbAutoload.loaded_posts.push(c),e.filter("#tdb-infinte-post-"+
h+"-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=d.MutationObserver||d.WebKitMutationObserver||d.MozMutationObserver,f=document.querySelector("#"+b.attr("id")),
c=(f.contentDocument||f.contentWindow.document).getElementsByTagName("html"),n=m.debounce(function(){var a=c[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(c[0],{childList:!0,subtree:!0})})))},error:function(a,b,e){}}))}},100);var n=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()},100);"on"===e&&(k.scroll(b),k.scroll(q),k.resize(n),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),l=b.offset().top-g("#wpadminbar").outerHeight(),c=b.outerHeight(!0);b=b.attr("id");l<a&&l+
c>e&&(c=document.getElementById(b).contentWindow,l=a-l,"undefined"!==typeof d.tdSmartSidebar&&c.tdSmartSidebar.td_events_scroll(l))})},_locationChange:function(){var a=k.scrollTop(),e=a+k.height(),b=[];g(".tdb-autoload-wrap").find("article, iframe").filter(function(){return g(this).parent().hasClass("tdb-autoload-wrap")}).each(function(){var f=g(this),c=g(".td-header-menu-wrap.td-affix");c=c.length?c.outerHeight():0;var d=g("#wpadminbar");d=d.length?d.outerHeight():0;c=f.offset().top-(c+d);var l=
f.outerHeight(!0);d=f.data("post-url");var h="",k=f.data("post-title");f.is("iframe")?(f=f.contents().find("#tdb-autoload-article article"),f.length&&(h=f.data("post-edit-url"))):h=f.data("post-edit-url");f=c+l;c<a&&f>e?b.push({top:c,bottom:f,post_url:d,post_edit_url:h,post_title:k}):c>a&&c<e?b.push({top:c,bottom:f,post_url:d,post_edit_url:h,post_title:k}):f>a&&f<e&&b.push({top:c,bottom:f,post_url:d,post_edit_url:h,post_title:k})});if(0===b.length){var l=d.location.href;var c=d.tdb_p_autoload_vars.origPostEditUrl;
var h=document.title}else 1===b.length?(h=b.pop(),l=h.post_url,c=h.post_edit_url,h=h.post_title):(l=b[0].post_url,c=b[0].post_edit_url,h=b[0].post_title);tdbAutoload._updatePostURL(l,c,h)},_updatePostURL:function(a,e,b){d.location.href===a||""===a||d.location.href.includes(a)||(d.history.replaceState(null,null,a),document.title=b,d.tdb_p_autoload_vars.isAdminBarShowing&&e&&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(d.tdb_global_vars.permalinkStructure)?d.tdb_global_vars.wpRestUrl+a+"&"+
e:d.tdb_global_vars.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,d){}};p.ready(function(){tdbAutoload.init()})})(jQuery,this,_);
