1 line
No EOL
3.3 KiB
JavaScript
1 line
No EOL
3.3 KiB
JavaScript
import dom from"./../dom.js";import connectionManager from"./../emby-apiclient/connectionmanager.js";import events from"./../emby-apiclient/events.js";import userSettings from"./../common/usersettings/usersettings.js";import playbackManager from"./../common/playback/playbackmanager.js";import itemManager from"./../common/itemmanager/itemmanager.js";import globalize from"./../common/globalize.js";import loading from"./../loading/loading.js";import"./../dialoghelper/dialoghelper.js";require(["css!modules/alphanumericshortcuts/alphanumericshortcuts.css"]);let currentChangeOptions,inputDisplayElement;function getAllChannels(apiClient,options){var query;return options.channelsResult?Promise.resolve(options.channelsResult):(query={UserId:apiClient.getCurrentUserId(),IsAiring:!0,ImageTypeLimit:1,EnableImageTypes:"Primary,Thumb,Backdrop",Fields:"ProgramPrimaryImageAspectRatio,PrimaryImageAspectRatio",EnableUserData:!1,SortBy:"ChannelNumber,SortName",AddCurrentProgram:!1},userSettings.addLiveTvChannelSortingToQuery(query,globalize),apiClient.getLiveTvChannels(query).then(function(result){return options.channelsResult=result}))}function clearState(){clearAlphaNumericShortcutTimeout(),currentChangeOptions=null;var elem=inputDisplayElement;elem&&(elem.innerHTML="",elem.classList.add("hide"))}function onAlphanumericShortcutTimeout(){var options=currentChangeOptions,options=(clearState(),options?.newItem);options&&(loading.show(),playbackManager.play({items:[options]}))}function ensureInputDisplayElement(){inputDisplayElement||((inputDisplayElement=document.createElement("div")).classList.add("alphanumeric-shortcut","hide","dialog"),dom.allowBackdropFilter()&&inputDisplayElement.classList.add("dialog-blur"),document.body.appendChild(inputDisplayElement))}let alpanumericShortcutTimeout;function clearAlphaNumericShortcutTimeout(){alpanumericShortcutTimeout&&(clearTimeout(alpanumericShortcutTimeout),alpanumericShortcutTimeout=null)}function resetAlphaNumericShortcutTimeout(){clearAlphaNumericShortcutTimeout(),alpanumericShortcutTimeout=setTimeout(onAlphanumericShortcutTimeout,2e3)}function updateDisplayElementWithItem(item){var html,elem=inputDisplayElement;elem&&(html="",html+=itemManager.getDisplayName(item,{channelNumberFirst:!0}),elem.innerHTML=html,elem.classList.remove("hide"))}function updateDisplayElement(options){let item=options.currentItem,offset=options.offset;getAllChannels(connectionManager.getApiClient(item),options).then(function(result){let index=-1;var channels=result.Items;for(let i=0,length=channels.length;i<length;i++)if(channels[i].Id===item.Id){index=i;break}-1===index&&(index=0),index+=offset,index=Math.min(channels.length-1,index),index=Math.max(index,0),(item=channels[index])&&(options.numChannels=channels.length,options.newItem=item,options.newItemIndex=index,updateDisplayElementWithItem(item))})}events.on(playbackManager,"playbackstop",clearState);export default{onChannelChangeRequest:function(options){ensureInputDisplayElement();var maxIndex,index,currentOptions=currentChangeOptions;currentOptions?(null!=(index=currentOptions.newItemIndex)&&(maxIndex=currentOptions.numChannels-1,(index=index+options.offset)<0?options.offset+=0-index:maxIndex<index&&(options.offset-=index-maxIndex)),currentOptions.offset+=options.offset,options=currentOptions):currentChangeOptions=options,updateDisplayElement(options),resetAlphaNumericShortcutTimeout()}}; |