[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/vendor/bootstrap/js/ -> scrollspy.min.js (source)

   1  import{E as EventHandler,S as SelectorEngine,d as defineJQueryPlugin,B as BaseComponent,f as getSelectorFromElement,M as Manipulator,h as getElement,a as typeCheckConfig}from"./dom.min.js?5.1.3";const NAME="scrollspy",DATA_KEY="bs.scrollspy",EVENT_KEY=`.$DATA_KEY}`,DATA_API_KEY=".data-api",Default={offset:10,method:"auto",target:""},DefaultType={offset:"number",method:"string",target:"(string|element)"},EVENT_ACTIVATE=`activate$EVENT_KEY}`,EVENT_SCROLL=`scroll$EVENT_KEY}`,EVENT_LOAD_DATA_API=`load$EVENT_KEY}.data-api`,CLASS_NAME_DROPDOWN_ITEM="dropdown-item",CLASS_NAME_ACTIVE="active",SELECTOR_DATA_SPY='[data-bs-spy="scroll"]',SELECTOR_NAV_LIST_GROUP=".nav, .list-group",SELECTOR_NAV_LINKS=".nav-link",SELECTOR_NAV_ITEMS=".nav-item",SELECTOR_LIST_ITEMS=".list-group-item",SELECTOR_LINK_ITEMS=".nav-link, .list-group-item, .dropdown-item",SELECTOR_DROPDOWN=".dropdown",SELECTOR_DROPDOWN_TOGGLE=".dropdown-toggle",METHOD_OFFSET="offset",METHOD_POSITION="position";class ScrollSpy extends BaseComponent{constructor(t,e){super(t),this._scrollElement="BODY"===this._element.tagName?window:this._element,this._config=this._getConfig(e),this._offsets=[],this._targets=[],this._activeTarget=null,this._scrollHeight=0,EventHandler.on(this._scrollElement,EVENT_SCROLL,(()=>this._process())),this.refresh(),this._process()}static get Default(){return Default}static get NAME(){return NAME}refresh(){const t=this._scrollElement===this._scrollElement.window?"offset":"position",e="auto"===this._config.method?t:this._config.method,s="position"===e?this._getScrollTop():0;this._offsets=[],this._targets=[],this._scrollHeight=this._getScrollHeight();SelectorEngine.find(SELECTOR_LINK_ITEMS,this._config.target).map((t=>{const o=getSelectorFromElement(t),i=o?SelectorEngine.findOne(o):null;if(i){const t=i.getBoundingClientRect();if(t.width||t.height)return[Manipulator[e](i).top+s,o]}return null})).filter((t=>t)).sort(((t,e)=>t[0]-e[0])).forEach((t=>{this._offsets.push(t[0]),this._targets.push(t[1])}))}dispose(){EventHandler.off(this._scrollElement,EVENT_KEY),super.dispose()}_getConfig(t){return(t={...Default,...Manipulator.getDataAttributes(this._element),..."object"==typeof t&&t?t:{}}).target=getElement(t.target)||document.documentElement,typeCheckConfig(NAME,t,DefaultType),t}_getScrollTop(){return this._scrollElement===window?this._scrollElement.pageYOffset:this._scrollElement.scrollTop}_getScrollHeight(){return this._scrollElement.scrollHeight||Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)}_getOffsetHeight(){return this._scrollElement===window?window.innerHeight:this._scrollElement.getBoundingClientRect().height}_process(){const t=this._getScrollTop()+this._config.offset,e=this._getScrollHeight(),s=this._config.offset+e-this._getOffsetHeight();if(this._scrollHeight!==e&&this.refresh(),t>=s){const t=this._targets[this._targets.length-1];this._activeTarget!==t&&this._activate(t)}else{if(this._activeTarget&&t<this._offsets[0]&&this._offsets[0]>0)return this._activeTarget=null,void this._clear();for(let e=this._offsets.length;e--;){this._activeTarget!==this._targets[e]&&t>=this._offsets[e]&&(void 0===this._offsets[e+1]||t<this._offsets[e+1])&&this._activate(this._targets[e])}}}_activate(t){this._activeTarget=t,this._clear();const e=SELECTOR_LINK_ITEMS.split(",").map((e=>`$e}[data-bs-target="$t}"],$e}[href="$t}"]`)),s=SelectorEngine.findOne(e.join(","),this._config.target);s.classList.add("active"),s.classList.contains("dropdown-item")?SelectorEngine.findOne(".dropdown-toggle",s.closest(".dropdown")).classList.add("active"):SelectorEngine.parents(s,".nav, .list-group").forEach((t=>{SelectorEngine.prev(t,".nav-link, .list-group-item").forEach((t=>t.classList.add("active"))),SelectorEngine.prev(t,".nav-item").forEach((t=>{SelectorEngine.children(t,".nav-link").forEach((t=>t.classList.add("active")))}))})),EventHandler.trigger(this._scrollElement,EVENT_ACTIVATE,{relatedTarget:t})}_clear(){SelectorEngine.find(SELECTOR_LINK_ITEMS,this._config.target).filter((t=>t.classList.contains("active"))).forEach((t=>t.classList.remove("active")))}static jQueryInterface(t){return this.each((function(){const e=ScrollSpy.getOrCreateInstance(this,t);if("string"==typeof t){if(void 0===e[t])throw new TypeError(`No method named "$t}"`);e[t]()}}))}}if(EventHandler.on(window,EVENT_LOAD_DATA_API,(()=>{SelectorEngine.find(SELECTOR_DATA_SPY).forEach((t=>new ScrollSpy(t)))})),defineJQueryPlugin(ScrollSpy),window.bootstrap=window.bootstrap||{},window.bootstrap.Scrollspy=ScrollSpy,Joomla&&Joomla.getOptions){const t=Joomla.getOptions("bootstrap.scrollspy");"object"==typeof t&&null!==t&&Object.keys(t).forEach((e=>{const s=t[e],o={offset:s.offset?s.offset:10,method:s.method?s.method:"auto"};s.target&&(o.target=s.target);const i=Array.from(document.querySelectorAll(e));i.length&&i.map((t=>new window.bootstrap.Scrollspy(t,o)))}))}export{ScrollSpy as S};


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer