EmbyCrackedClient/web/modules/emby-elements/emby-scroller/emby-scroller.js
2025-06-25 11:46:04 +08:00

1 line
No EOL
7.5 KiB
JavaScript

import layoutManager from"./../../layoutmanager.js";import scroller from"./../../scroller/smoothscroller.js";import Headroom from"./../../headroom/headroom.js";import"./../../customelementupgrade.js";import"./../emby-scrollbuttons/emby-scrollbuttons.js";import skinViewManager from"./../../skinviewmanager.js";function onInit(){this.classList.add("emby-scroller")}let headerElement=document.querySelector(".skinHeader"),DefaultFocusScroll="adaptive";function initHeadroom(elem){var headroom;skinViewManager.getSkinOptions().disableHeadRoom||((headroom=new Headroom({scroller:elem,element:headerElement,enableScrollingStatus:!0})).init(),elem.headroom=headroom)}let embyScrollButtonsLoaded;function loadEmbyScrollButtons(){return embyScrollButtonsLoaded?Promise.resolve():(embyScrollButtonsLoaded=!0,Emby.importModule("./modules/emby-elements/emby-scrollbuttons/emby-scrollbuttons.js"))}function loadScrollButtons(scroller){layoutManager.tv||embyScrollButtonsLoaded||loadEmbyScrollButtons();let parent=scroller;(parent="self"!==scroller.getAttribute("data-scrollbuttonparent")?parent.parentNode:parent).insertAdjacentHTML("afterbegin",'<div is="emby-scrollbuttons" class="emby-scrollbuttons"></div>')}layoutManager.tv||loadEmbyScrollButtons();class EmbyScroller extends HTMLDivElement{constructor(){var self=super();return onInit.call(self),self}connectedCallback(){onInit.call(this);var horizontal="false"!==this.getAttribute("data-horizontal"),slider=this.querySelector(".scrollSlider"),bindHeaderValue=(horizontal&&(slider.style["white-space"]="nowrap"),this.getAttribute("data-bindheader")),bindHeaderValue="true"===bindHeaderValue||layoutManager.tv&&"tv"===bindHeaderValue,enableScrollButtons=!layoutManager.tv&&(horizontal||"x"===this.getAttribute("data-scrollbuttonstype"))&&"false"!==this.getAttribute("data-scrollbuttons");let focusScroll=this.getAttribute("data-focusscroll");focusScroll="true"===focusScroll?DefaultFocusScroll:"false"===focusScroll?null:focusScroll||("false"!==this.getAttribute("data-centerfocus")?DefaultFocusScroll:null),this.isPrimaryScroller=bindHeaderValue||"true"===this.getAttribute("data-primaryscroller");var forceScrollbar="true"===this.getAttribute("data-forcescrollbar"),slider={horizontal:horizontal,mouseWheel:"false"!==this.getAttribute("data-mousewheel"),touchDragging:1,slidee:slider,dragHandle:1,hideScrollbar:enableScrollButtons&&horizontal||!forceScrollbar&&null,forceScrollbar:enableScrollButtons&&horizontal||forceScrollbar,allowNativeSmoothScroll:"true"===this.getAttribute("data-allownativesmoothscroll"),focusScroll:focusScroll,focusScrollOffsetLeft:this.getAttribute("data-focusscrolloffsetleft")||this.getAttribute("data-focusscrolloffset")||null,focusScrollOffsetTop:this.getAttribute("data-focusscrolloffsettop")||this.getAttribute("data-focusscrolloffset")||null,forceNativeScroll:"true"===this.getAttribute("data-forcenativescroll"),forceSmoothScroll:"true"===this.getAttribute("data-forcesmoothscroll"),dualScroll:"true"===this.getAttribute("data-dualscroll"),miniScrollbar:"true"===this.getAttribute("data-miniscrollbar"),autoStartEdge:horizontal||this.isPrimaryScroller},forceScrollbar=(slider.dualScroll&&(slider.autoStartEdge=!1),horizontal||this.isPrimaryScroller||(slider.adaptiveBorderYStart=0),this.getAttribute("data-adaptiveborder")),horizontal=(forceScrollbar&&(slider.adaptiveBorderXStart=slider.adaptiveBorderXEnd=slider.adaptiveBorderYStart=slider.adaptiveBorderYEnd=parseInt(forceScrollbar)),this.getAttribute("data-adaptiveborderxstart")),forceScrollbar=(horizontal&&(slider.adaptiveBorderXStart=parseInt(horizontal)),this.getAttribute("data-adaptiveborderystart")),horizontal=(forceScrollbar&&(slider.adaptiveBorderYStart=parseInt(forceScrollbar)),this.getAttribute("data-adaptiveborderxend")),forceScrollbar=(horizontal&&(slider.adaptiveBorderXEnd=parseInt(horizontal)),this.getAttribute("data-adaptiveborderyend"));forceScrollbar&&(slider.adaptiveBorderYEnd=parseInt(forceScrollbar)),this.scroller=new scroller(this,slider),this.scroller.init(),bindHeaderValue&&initHeadroom(this),enableScrollButtons&&loadScrollButtons(this),this.__upgraded=!0,this.dispatchEvent(new CustomEvent("upgraded",{cancelable:!1}))}disconnectedCallback(){var headroom=this.headroom,headroom=(headroom&&(headroom.destroy(),this.headroom=null),this.scroller);headroom&&(headroom.destroy(),this.scroller=null)}pause(){this.paused=!0;var headroom=this.headroom;headroom&&headroom.pause()}beginResume(){this.paused=!1;var headroom=this.headroom;headroom&&headroom.beginResume()}resume(){this.paused=!1;var headroom=this.headroom;headroom?headroom.resume():this.isPrimaryScroller&&(headerElement.classList.add("headroom-scrolling"),headerElement.classList.remove("headroom-hidden"))}getScrollSize(){if(this.scroller)return this.scroller.getScrollSize()}getScrollWidth(){if(this.scroller)return this.scroller.getScrollWidth()}getScrollHeight(){if(this.scroller)return this.scroller.getScrollHeight()}getScrollPosition(){if(this.scroller)return this.scroller.getScrollPosition()}getLastScrollPosition(){if(this.scroller)return this.scroller.getLastScrollPosition()}isNativeScroll(){if(this.scroller)return this.scroller.isNativeScroll()}getScrollLeft(){if(this.scroller)return this.scroller.getScrollLeft()}getScrollTop(){if(this.scroller)return this.scroller.getScrollTop()}getScrollContainerBoundingClientRect(){if(this.scroller)return this.scroller.getScrollContainerBoundingClientRect()}getScrollSlider(){if(this.scroller)return this.scroller.getScrollSlider()}scrollToBeginning(scrollOptions){if(this.scroller)return(scrollOptions=scrollOptions||{}).position=0,this.scroller.scrollToPosition(scrollOptions)}toStart(elem,scrollOptions){this.scroller&&this.scroller.toStart(elem,scrollOptions)}toCenter(elem,scrollOptions){this.scroller&&this.scroller.toCenter(elem,scrollOptions)}scrollToElement(elem,scrollOptions){this.scroller&&this.scroller.scrollToElement(elem,scrollOptions)}scrollToPosition(pos){if(this.scroller)return this.scroller.scrollToPosition(pos)}addScrollEventListener(fn,options){this.scroller&&this.scroller.addScrollEventListener(fn,options)}removeScrollEventListener(fn,options){this.scroller&&this.scroller.removeScrollEventListener(fn,options)}scrollBackwards(){this.scroller&&this.scroller.scrollBackwards()}scrollForwards(){this.scroller&&this.scroller.scrollForwards()}scrollBy(delta,scrollOptions){this.scroller&&this.scroller.scrollBy(delta,scrollOptions)}addResizeObserver(fn){this.scroller&&this.scroller.addResizeObserver(fn)}removeResizeObserver(fn){this.scroller&&this.scroller.removeResizeObserver(fn)}getScrollMultiplier(){if(this.scroller)return this.scroller.getScrollMultiplier()}getScrollLeftMultiplier(){if(this.scroller)return this.scroller.getScrollLeftMultiplier()}getScrollTopMultiplier(){if(this.scroller)return this.scroller.getScrollTopMultiplier()}getPadding(){if(this.scroller)return this.scroller.getPadding()}getElementPosition(element,horizontal,scrollOptions){if(this.scroller)return this.scroller.getElementPosition(element,horizontal,scrollOptions)}notifyResized(){if(this.scroller)return this.scroller.notifyResized()}setHeaderBindingEnabled(enabled){this.headroom&&!this.paused&&(enabled?(this.headroom.beginResume({}),this.headroom.resume({})):(this.headroom.pause(),this.headroom.clearTransform()))}setFocusScroll(focusScroll){this.scroller&&(null==focusScroll&&(focusScroll=DefaultFocusScroll),this.scroller.options)&&(this.scroller.options.focusScroll=focusScroll)}setFocusScrollOffsetLeft(val){this.scroller&&this.scroller.options&&(this.scroller.options.focusScrollOffsetLeft=val)}}customElements.define("emby-scroller",EmbyScroller,{extends:"div"});export default EmbyScroller;