Files
help365/crm/jquery.tocify.min.js
2025-05-26 16:15:30 +04:00

5 lines
7.0 KiB
JavaScript

/*! jquery.tocify - v1.9.0 - 2013-10-01
* http://gregfranko.com/jquery.tocify.js/
* Copyright (c) 2013 Greg Franko; Licensed MIT*/
!function(){"use strict";!function(r,d,c){"use strict";var o="tocify",e="tocify-focus",t="tocify-hover",n="tocify-hide",a="tocify-header",i="."+a,l="tocify-subheader",h="."+l,f="tocify-item",u="."+f,p="tocify-extend-page",g="."+p;r.widget("toc.tocify",{version:"1.9.0",options:{context:"body",ignoreSelector:null,selectors:"h1, h2, h3",showAndHide:!0,showEffect:"slideDown",showEffectSpeed:"medium",hideEffect:"slideUp",hideEffectSpeed:"medium",smoothScroll:!0,smoothScrollSpeed:"medium",scrollTo:0,showAndHideOnScroll:!0,highlightOnScroll:!0,highlightOffset:40,theme:"bootstrap",extendPage:!0,extendPageOffset:100,history:!0,scrollHistory:!1,hashGenerator:"compact",highlightDefault:!0},_create:function(){var e=this;e.extendPageScroll=!0,e.items=[],e._generateToc(),e._addCSSClasses(),e.webkit=function(){for(var e in d)if(e&&-1!==e.toLowerCase().indexOf("webkit"))return!0;return!1}(),e._setEventHandlers(),r(d).load(function(){e._setActiveElement(!0),r("html, body").promise().done(function(){setTimeout(function(){e.extendPageScroll=!1},0)})})},_generateToc:function(){var e,t,s=this,i=s.options.ignoreSelector;return e=-1!==this.options.selectors.indexOf(",")?r(this.options.context).find(this.options.selectors.replace(/ /g,"").substr(0,this.options.selectors.indexOf(","))):r(this.options.context).find(this.options.selectors.replace(/ /g,"")),e.length?(s.element.addClass(o),e.each(function(e){r(this).is(i)||(t=r("<ul/>",{id:a+e,class:a}).append(s._nestElements(r(this),e)),s.element.append(t),r(this).nextUntil(this.nodeName.toLowerCase()).each(function(){0===r(this).find(s.options.selectors).length?r(this).filter(s.options.selectors).each(function(){r(this).is(i)||s._appendSubheaders.call(this,s,t)}):r(this).find(s.options.selectors).each(function(){r(this).is(i)||s._appendSubheaders.call(this,s,t)})}))}),undefined):(s.element.addClass(n),undefined)},_setActiveElement:function(e){var t=this,s=d.location.hash.substring(1),i=t.element.find('li[data-unique="'+s+'"]');return s.length?(t.element.find("."+t.focusClass).removeClass(t.focusClass),i.addClass(t.focusClass),t.options.showAndHide&&i.click()):(t.element.find("."+t.focusClass).removeClass(t.focusClass),!s.length&&e&&t.options.highlightDefault&&t.element.find(u).first().addClass(t.focusClass)),t},_nestElements:function(t,e){var s,i,o;return s=r.grep(this.items,function(e){return e===t.text()}),s.length?this.items.push(t.text()+e):this.items.push(t.text()),o=this._generateHashValue(s,t,e),i=r("<li/>",{class:f,"data-unique":o}).append(r("<a/>",{text:t.text()})),t.before(r("<div/>",{name:o,"data-unique":o})),i},_generateHashValue:function(e,t,s){var i="",o=this.options.hashGenerator;if("pretty"===o){for(i=t.text().toLowerCase().replace(/\s/g,"-");i.indexOf("--")>-1;)i=i.replace(/--/g,"-");for(;i.indexOf(":-")>-1;)i=i.replace(/:-/g,"-")}else i="function"==typeof o?o(t.text(),t):t.text().replace(/\s/g,"");return e.length&&(i+=""+s),i},_appendSubheaders:function(e,t){var s=r(this).index(e.options.selectors),i=r(e.options.selectors).eq(s-1),o=+r(this).prop("tagName").charAt(1),n=+i.prop("tagName").charAt(1);n>o?e.element.find(h+"[data-tag="+o+"]").last().append(e._nestElements(r(this),s)):o===n?t.find(u).last().after(e._nestElements(r(this),s)):t.find(u).last().after(r("<ul/>",{class:l,"data-tag":o})).next(h).append(e._nestElements(r(this),s))},_setEventHandlers:function(){var h=this;this.element.on("click.tocify","li",function(){if(h.options.history&&(d.location.hash=r(this).attr("data-unique")),h.element.find("."+h.focusClass).removeClass(h.focusClass),r(this).addClass(h.focusClass),h.options.showAndHide){var e=r('li[data-unique="'+r(this).attr("data-unique")+'"]');h._triggerShow(e)}h._scrollTo(r(this))}),this.element.find("li").on({"mouseenter.tocify":function(){r(this).addClass(h.hoverClass),r(this).css("cursor","pointer")},"mouseleave.tocify":function(){"bootstrap"!==h.options.theme&&r(this).removeClass(h.hoverClass)}}),(h.options.extendPage||h.options.highlightOnScroll||h.options.scrollHistory||h.options.showAndHideOnScroll)&&r(d).on("scroll.tocify",function(){r("html, body").promise().done(function(){var o,e,t,s,n=r(d).scrollTop(),i=r(d).height(),a=r(c).height(),l=r("body")[0].scrollHeight;if(h.options.extendPage&&(h.webkit&&n>=l-i-h.options.extendPageOffset||!h.webkit&&i+n>a-h.options.extendPageOffset)&&!r(g).length){if(e=r('div[data-unique="'+r(u).last().attr("data-unique")+'"]'),!e.length)return;t=e.offset().top,r(h.options.context).append(r("<div />",{class:p,height:Math.abs(t-n)+"px","data-unique":p})),h.extendPageScroll&&(s=h.element.find("li.active"),h._scrollTo(r('div[data-unique="'+s.attr("data-unique")+'"]')))}setTimeout(function(){var e,s=null,i=null,t=r(h.options.context).find("div[data-unique]");t.each(function(e){var t=Math.abs((r(this).next().length?r(this).next():r(this)).offset().top-n-h.options.highlightOffset);return null==s||s>t?(s=t,i=e,undefined):!1}),e=r(t[i]).attr("data-unique"),o=r('li[data-unique="'+e+'"]'),h.options.highlightOnScroll&&o.length&&(h.element.find("."+h.focusClass).removeClass(h.focusClass),o.addClass(h.focusClass)),h.options.scrollHistory&&d.location.hash!=="#"+e&&d.location.replace("#"+e),h.options.showAndHideOnScroll&&h.options.showAndHide&&h._triggerShow(o,!0)},0)})})},show:function(e){var t=this;if(!e.is(":visible"))switch(e.find(h).length||e.parent().is(i)||e.parent().is(":visible")?e.children(h).length||e.parent().is(i)||(e=e.closest(h)):e=e.parents(h).add(e),t.options.showEffect){case"none":e.show();break;case"show":e.show(t.options.showEffectSpeed);break;case"slideDown":e.slideDown(t.options.showEffectSpeed);break;case"fadeIn":e.fadeIn(t.options.showEffectSpeed);break;default:e.show()}return e.parent().is(i)?t.hide(r(h).not(e)):t.hide(r(h).not(e.closest(i).find(h).not(e.siblings()))),t},hide:function(e){var t=this;switch(t.options.hideEffect){case"none":e.hide();break;case"hide":e.hide(t.options.hideEffectSpeed);break;case"slideUp":e.slideUp(t.options.hideEffectSpeed);break;case"fadeOut":e.fadeOut(t.options.hideEffectSpeed);break;default:e.hide()}return t},_triggerShow:function(e,t){var s=this;return e.parent().is(i)||e.next().is(h)?s.show(e.next(h),t):e.parent().is(h)&&s.show(e.parent(),t),s},_addCSSClasses:function(){return"jqueryui"===this.options.theme?(this.focusClass="ui-state-default",this.hoverClass="ui-state-hover",this.element.addClass("ui-widget").find(".toc-title").addClass("ui-widget-header").end().find("li").addClass("ui-widget-content")):"bootstrap"===this.options.theme?(this.element.find(i+","+h).addClass("nav nav-list"),this.focusClass="active"):(this.focusClass=e,this.hoverClass=t),this},setOption:function(){r.Widget.prototype._setOption.apply(this,arguments)},setOptions:function(){r.Widget.prototype._setOptions.apply(this,arguments)},_scrollTo:function(e){var t=document.querySelector('div[data-unique="'+e.attr("data-unique")+'"]');if(t)t.scrollIntoView({behavior:this.options.smoothScroll?"smooth":"auto",block:"start"});return this}})}(window.jQuery,window,document)}();