wp_back/wp-content/plugins/easy-table-of-contents/assets/js/ez-toc-widget-sticky.min.js
2024-05-20 15:37:46 +03:00

1 line
2.9 KiB
JavaScript

jQuery(function(t){var i,e,o,c=t("span.ez-toc-section").toArray(),s=(i=c,i.reduce(function(i,e){var o;return i[e.id]=t('.ez-toc-widget-sticky-container .ez-toc-widget-sticky-list a[href="#'+t(o=e).attr("id")+'"]'),i},{})),n=t.map(s,function(t,i){return t}),a=(e=30,"undefined"!=typeof ezTOC&&void 0!==ezTOC.smooth_scroll&&1===parseInt(ezTOC.smooth_scroll)&&(e=void 0!==ezTOC.scroll_offset?parseInt(ezTOC.scroll_offset):30),o=t("#wpadminbar"),o.length&&(e+=o.height()),e);function r(){var i,e,o,r,l,d=(i=a,e=c,o=t(window).scrollTop()+i+1,r=e[0],l=o-t(r).offset().top,e.forEach(function(i){var e=o-t(i).offset().top;e>0&&e<l&&(l=e,r=i)}),r);if(d){var h,p,g,f,v,u,w,z,y,k=s[d.id];(function t(i,e){e.forEach(function(t){i!==t&&t.parent().hasClass("active")&&t.parent().removeClass("active")})})(k,n),(g=(h=k).parent()).hasClass("active")||g.addClass("active"),y=(f=p=g,v=t(f),u=v.html(),v.parent().append('<li id="ez-toc-widget-sticky-height-test" class="active">'+u+"</li>"),w=t("#ez-toc-widget-sticky-height-test"),z=w.height(),w.remove(),z-v.children("ul").first().height()),t("#ez-toc-widget-sticky-active-height").remove(),t('<style id="ez-toc-widget-sticky-active-height">.ez-toc-widget-sticky-container ul.ez-toc-widget-sticky-list li.active {height:'+y+"px;} </style>").appendTo("head")}}function l(){t(window).off("load resize scroll",r)}c.length>0&&t(".ez-toc-widget-sticky-container").length&&t(window).on("load resize scroll",r),setTimeout(function(){jQuery(window).on("load resize scroll",h)},100);var d="";function h(i){i.preventDefault(),jQuery(document).width()>980&&jQuery(window).scrollTop()>=ezTocWidgetSticky.scroll_fixed_position&&(0==jQuery(".post,.post-content").length||jQuery(".post,.post-content").length>0&&jQuery(window).scrollTop()<=jQuery(".post,.post-content").height())?(jQuery(".ez-toc-widget-sticky").css({position:"fixed",width:"auto"!=ezTocWidgetSticky.sidebar_width?ezTocWidgetSticky.sidebar_width+""+ezTocWidgetSticky.sidebar_width_size_unit:t("#ez-toc-widget-sticky-container").parents(".widget-area").width(),top:"30"!=ezTocWidgetSticky.fixed_top_position?ezTocWidgetSticky.fixed_top_position+""+ezTocWidgetSticky.fixed_top_position_size_unit:"30px","z-index":"9999999","background-color":jQuery(document).find("body").css("background-color")}),jQuery(".ez-toc-widget-sticky nav").css({"overflow-y":"on"==ezTocWidgetSticky.navigation_scroll_bar?"auto":"hidden","max-height":"auto"!=ezTocWidgetSticky.scroll_max_height?ezTocWidgetSticky.scroll_max_height+""+ezTocWidgetSticky.scroll_max_height_size_unit:"calc(100vh - 111px)"})):jQuery(".ez-toc-widget-sticky,.ez-toc-widget-sticky nav").attr("style",!1);var e=jQuery("#ez-toc-widget-sticky-container li.active a").attr("href");let o=Math.round(jQuery("#ez-toc-widget-sticky-container .ez-toc-link[href='"+e+"']").position().top);jQuery("#ez-toc-widget-sticky-container nav>ul>li:last-child a").position().top,e!=d&&jQuery(".ez-toc-widget-sticky nav").scrollTop(Math.round(jQuery(".ez-toc-widget-sticky nav").scrollTop()+o)-50),d=e}});