EmbyCrackedClient/web/modules/common/inputmanager.js

1 line
6.8 KiB
JavaScript
Raw Normal View History

2025-06-25 11:46:04 +08:00
import dom from"./../dom.js";import appRouter from"./../approuter.js";import playbackManager from"./playback/playbackmanager.js";import focusManager from"./../focusmanager.js";import{appHost}from"./servicelocator.js";import events from"./../emby-apiclient/events.js";let lastInputTime=Date.now();function notify(triggerCommand,evt){lastInputTime=Date.now(),!1!==triggerCommand&&handleCommand("unknown",{originalEvent:evt})}function idleTime(){return Date.now()-lastInputTime}function onFunctionalEvent(){lastInputTime=Date.now()}function select(sourceElement){sourceElement.click()}function on(scope,fn,options){dom.addEventListener(scope,"command",fn,options=options||{})}function off(scope,fn,options){dom.removeEventListener(scope,"command",fn,options=options||{})}events.on(appHost,"pause",onFunctionalEvent),events.on(appHost,"resume",onFunctionalEvent),events.on(appRouter,"navigate",onFunctionalEvent);let commandTimes={};function checkCommandTime(command){var last=commandTimes[command]||0,now=Date.now();return!(now-last<1e3||(commandTimes[command]=now,0))}function normalizeSourceElement(sourceElement){var focusScope=focusManager.getCurrentScope();return sourceElement=sourceElement&&focusScope.contains(sourceElement)?sourceElement:focusScope}function isTextEditable(elem){var readOnly=elem.readOnly;if(!readOnly&&!1===readOnly){if("TEXTAREA"===elem.tagName)return!0;switch(elem.type){case"checkbox":case"radio":case"file":case"hidden":case"range":return!1;default:return!0}}return!1}function allowNavAtStart(elem){return 0===elem.selectionStart}function allowNavAtEnd(elem){var text=elem.value||"";return elem.selectionEnd>=text.length}function allowNavInSelectionRange(elem,command){return("left"===command?"rtl"===document.dir?allowNavAtEnd:allowNavAtStart:"rtl"===document.dir?allowNavAtStart:allowNavAtEnd)(elem)}function allowLeftOrRightNav(elem,command){if(!isTextEditable(elem))return!0;switch(elem.tagName){case"TEXTAREA":return allowNavInSelectionRange(elem,command);case"INPUT":switch(elem.type){case"text":case"tel":case"url":case"password":case"search":return allowNavInSelectionRange(elem,command);case"number":return!1;default:return elem.classList.contains("emby-input-tv")}default:return!0}}function showChannelChanger(currentItem,offset){return Emby.importModule("./modules/channelchanger/channelchanger.js").then(function(ChannelChanger){return ChannelChanger.onChannelChangeRequest({currentItem:currentItem,offset:offset})})}function handleChannelChangeCommand(offset){if(playbackManager.isPlayingVideo()){var item=playbackManager.currentItem();if(item&&"TvChannel"===item.Type)return void showChannelChanger(item,offset)}0<offset?playbackManager.channelUp():playbackManager.channelDown()}function handleCommand(name,options){lastInputTime=Date.now();let sourceElement=options?options.sourceElement:null;sourceElement=normalizeSourceElement(sourceElement=sourceElement||document.activeElement);var eventInfo={detail:{command:name},bubbles:!0,cancelable:!0},eventResult=(options&&(eventInfo.detail.repeat=options.repeat,eventInfo.detail.originalEvent=options.originalEvent,eventInfo.detail.commandOptions=options),sourceElement.dispatchEvent(new CustomEvent("command",eventInfo)));if(!eventResult)return!0;switch(name){case"up":return sourceElement=normalizeSourceElement(sourceElement=document.activeElement||sourceElement),focusManager.moveUp(sourceElement),!0;case"down":return sourceElement=normalizeSourceElement(sourceElement=document.activeElement||sourceElement),focusManager.moveDown(sourceElement),!0;case"left":return allowLeftOrRightNav(sourceElement=normalizeSourceElement(sourceElement=document.activeElement||sourceElement),name)?(focusManager.moveLeft(sourceElement)||options?.originalEvent?.repeat||handleCommand("moveleftedge",{sourceElement:sourceElement,originalEvent:eventInfo.detail.originalEvent}),!0):!1;case"right":return allowLeftOrRightNav(sourceElement=normalizeSourceElement(sourceElement=document.activeElement||sourceElement),name)?(focusManager.moveRight(sourceElement)||options?.originalEvent?.repeat||handleCommand("moverightedge"