EmbyCrackedClient/web/modules/viewmanager/viewmanager.js

1 line
12 KiB
JavaScript
Raw Permalink Normal View History

2025-06-25 11:46:04 +08:00
import layoutManager from"./../layoutmanager.js";import focusManager from"./../focusmanager.js";import pluginManager from"./../common/pluginmanager.js";import userSettings from"./../common/usersettings/usersettings.js";import events from"./../emby-apiclient/events.js";import appSettings from"./../common/appsettings.js";let mainAnimatedPages,pageContainerCount=3,ViewClasses=[],CurrentViewStack=[];function extractPath(urlOrPath){try{var pathname=new URL(urlOrPath).pathname;if(pathname)return pathname}catch(e){}return urlOrPath}function removeItemOnce(arr,value){value=arr.indexOf(value);return-1<value&&arr.splice(value,1),arr}function removeViewInfoFromCurrentViews(viewInfo){removeItemOnce(CurrentViewStack,viewInfo)}function findOldestViewToRemove(ignoreViewInfo){var candidates=[],views=CurrentViewStack;for(let i=0,length=views.length;i<length;i++){var viewInfo=views[i];"true"!==viewInfo.params.asDialog&&candidates.push(viewInfo)}if(candidates.length>=pageContainerCount)for(let i=0,length=candidates.length;i<length;i++){let viewInfo=candidates[i];if(viewInfo!==ignoreViewInfo)return viewInfo}return null}function disableRestoreOnCurrentViews(){var views=CurrentViewStack;for(let i=0,length=views.length;i<length;i++){var viewInfo=views[i];"true"!==viewInfo.params.asDialog&&(viewInfo=viewInfo.view)&&(viewInfo.allowRestore=!1)}}function getViewInfoByUrl(url){var views=CurrentViewStack;for(let i=0,length=views.length;i<length;i++){var viewInfo=views[i];if(viewInfo.url===url)return viewInfo}return null}function setControllerClass(view,options){if(options.controllerFactory)return Promise.resolve();let controllerUrl=view.getAttribute("data-controller");return controllerUrl?(controllerUrl.startsWith("__plugin/")&&(controllerUrl=controllerUrl.substring("__plugin/".length)),controllerUrl=pluginManager.getConfigurationResourceUrl(controllerUrl),require([controllerUrl]).then(function(deps){options.controllerFactory=deps[0]})):Promise.resolve()}function ensureWindowScrollOption(detail,view){let windowScroll=detail.windowScroll;return 3!==windowScroll||(windowScroll=detail.windowScroll=!view.classList.contains("scrollFrameY")&&!view.querySelector('.emby-scroller[data-bindheader="true"],.scrollFrameY[data-bindheader="true"]'))||(detail.adjustHeaderForEmbeddedScroll=!0),!0===windowScroll}function parseHtml(html,hasScript){hasScript&&(html=(html=html.replaceAll("\x3c!--<script","<script")).replaceAll("<\/script>--\x3e","<\/script>"));hasScript=document.createElement("div");return hasScript.innerHTML=html,hasScript.querySelector('.view,div[data-role="page"]')}function normalizeNewView(options,isPluginpage){let viewHtml=options.view;options.params?.asDialog&&(viewHtml=viewHtml.replace('data-bindheader="true"','data-bindheader="false"'));isPluginpage=!!isPluginpage&&viewHtml.includes("<script"),isPluginpage=parseHtml(viewHtml,isPluginpage);options.view=isPluginpage}function getViewHideEventInfo(previousViewInfo,newViewInfo){previousViewInfo=Object.assign({},previousViewInfo);return previousViewInfo.newViewInfo=newViewInfo,{detail:previousViewInfo,bubbles:!0,cancelable:!1}}function onBeforeChange(previousViewInfo,newViewInfo,isRestored,isBack){previousViewInfo&&dispatchViewEvent(previousViewInfo.view,getViewHideEventInfo(previousViewInfo,newViewInfo),"viewbeforehide");var newView=newViewInfo.view,isRestored=getViewEventDetail(newViewInfo,isRestored,isBack,previousViewInfo);let navMenuId=isRestored.detail.navMenuId;return navMenuId||"search"===isRestored.detail.params?.type&&(navMenuId="search"),navMenuId=navMenuId||(navMenuId=window.location.href.toString()).substring(navMenuId.indexOf("#!")+2),isRestored.detail.navMenuId=navMenuId,newViewInfo.controllerFactory&&!newView.controller&&(newView.controller=new newViewInfo.controllerFactory(newView,isRestored.detail.params)),newViewInfo.controller&&newView.controller&&(isBack=extractPath(newViewInfo.controller),newView.controller.name=isBack.replaceAll(".js","").replaceAll(".","").replaceAll("/","-"),newView.classList.add("view-"+newView.controller.name)),dispatchViewEvent(newView,isRestored,"viewbefo