EmbyCrackedClient/web/videoosd/chapterstab.js

5 lines
4 KiB
JavaScript
Raw Permalink Normal View History

2025-06-25 11:46:04 +08:00
import BaseTab from"./basetab.js";import cardBuilder from"./../modules/cardbuilder/cardbuilder.js";import playbackManager from"./../modules/common/playback/playbackmanager.js";import focusManager from"./../modules/focusmanager.js";import layoutManager from"./../modules/layoutmanager.js";function fetchItems(query){let chapters=this.currentOptions.currentDisplayChapters||[];var totalItems=chapters.length;return query&&(chapters=chapters.slice(query.StartIndex||0),query.Limit)&&chapters.length>query.Limit&&(chapters.length=query.Limit),Promise.resolve({Items:chapters,TotalRecordCount:totalItems})}function getListOptions(items){return{renderer:cardBuilder,options:{shape:"autooverflow",fields:["Name","ChapterTime"],multiSelect:!1,contextMenu:!1,playedButton:!1,ratingButton:!1,action:"custom",playAction:"custom",enableUserData:!1,draggable:!1,cardClass:"videoOsd-itemstab-card videoOsd-itemstab-card-twoline",defaultShape:"backdrop",allowBottomPadding:!1,background:"black",textLinks:!1,enableFocusScaling:!1},virtualScrollLayout:"horizontal-grid"}}function onCardAction(e){e=e.detail.item;playbackManager.seek(e.StartPositionTicks||0),this.closeTab()}function ChaptersTab(view){BaseTab.apply(this,arguments)}Object.assign(ChaptersTab.prototype,BaseTab.prototype);let FocusScrollOffset="-padding-inline-start";function scrollToCurrent(instance,focus){var currentIndex=instance.getCurrentIndex();console.log("scrolling to chapter index: "+currentIndex),instance.itemsContainer.scrollToIndex(currentIndex,{offsetLeft:FocusScrollOffset},focus)}ChaptersTab.prototype.loadTemplate=function(){var view=this.view;return view.innerHTML=`
<div is="emby-scroller" data-mousewheel="false" data-focusscroll="start" data-focusscrolloffset="`+FocusScrollOffset+`" class="padded-top-focusscale padded-bottom-focusscale">
<div is="emby-itemscontainer" data-focusabletype="nearest" class="focusable focuscontainer-x scrollSlider itemsContainer videoosd-padded-left videoosd-padded-right" data-virtualscrolllayout="horizontal-grid"></div>
</div>
`,this.itemsContainer=view.querySelector(".itemsContainer"),this.itemsContainer.fetchData=fetchItems.bind(this),this.itemsContainer.getListOptions=getListOptions.bind(this),this.itemsContainer.addEventListener("action-null",onCardAction.bind(this)),Promise.resolve()},ChaptersTab.prototype.scrollToCurrentItem=function(focus){this.paused||this.view.contains(document.activeElement)||(focus?focusManager.focus(this.itemsContainer):scrollToCurrent(this,focus))},ChaptersTab.prototype.onResume=function(options){let instance=this;return BaseTab.prototype.onResume.apply(this,arguments).then(function(){var optionsWithoutRefresh=Object.assign(Object.assign({},options),{refresh:!1});let hasFocus=instance.itemsContainer.contains(document.activeElement);return instance.itemsContainer.resume(optionsWithoutRefresh).then(function(){options.refresh?instance.refreshItem():instance.scrollToCurrentItem(hasFocus)})})},ChaptersTab.prototype.refreshItem=function(){BaseTab.prototype.refreshItem.apply(this,arguments);let instance=this,hasFocus=instance.itemsContainer.contains(document.activeElement);return instance.itemsContainer.refreshItems().then(function(){instance.scrollToCurrentItem(hasFocus)})},ChaptersTab.prototype.onTimeUpdate=function(positionTicks,runtimeTicks){BaseTab.prototype.onTimeUpdate.apply(this,arguments),this.paused||layoutManager.tv&&this.scrollToCurrentItem()},ChaptersTab.prototype.getCurrentIndex=function(){var chapters=this.currentOptions.currentDisplayChapters||[],positionTicks=this.positionTicks||0;for(let i=0,length=chapters.length;i<length;i++)if(positionTicks<chapters[i].StartPositionTicks)return Math.max(0,i-1);return positionTicks?Math.max(chapters.length-1,0):0},ChaptersTab.prototype.onPause=function(){BaseTab.prototype.onPause.apply(this,arguments),this.itemsContainer.pause()},ChaptersTab.prototype.destroy=function(){BaseTab.prototype.destroy.apply(this,arguments),this.itemsContainer=null};export default ChaptersTab;