jellyfin-web/dashboard-ui/scripts/librarybrowser.js

1 line
18 KiB
JavaScript
Raw Normal View History

define(["appSettings","dom","browser","datetime","scrollStyles"],function(appSettings,dom,browser,datetime){"use strict";function fadeInRight(elem){var pct=browser.mobile?"4%":"0.5%",keyframes=[{opacity:"0",transform:"translate3d("+pct+", 0, 0)",offset:0},{opacity:"1",transform:"none",offset:1}];elem.animate(keyframes,{duration:160,iterations:1,easing:"ease-out"})}var libraryBrowser=function(window,document,screen){var pageSizeKey="pagesize_v4",libraryBrowser={getDefaultPageSize:function(key,defaultValue){return 100},getSavedQueryKey:function(modifier){return window.location.href.split("#")[0]+(modifier||"")},loadSavedQueryValues:function(key,query){var values=appSettings.get(key+"_"+Dashboard.getCurrentUserId());return values?(values=JSON.parse(values),Object.assign(query,values)):query},saveQueryValues:function(key,query){var values={};query.SortBy&&(values.SortBy=query.SortBy),query.SortOrder&&(values.SortOrder=query.SortOrder);try{appSettings.set(key+"_"+Dashboard.getCurrentUserId(),JSON.stringify(values))}catch(e){}},saveViewSetting:function(key,value){try{appSettings.set(key+"_"+Dashboard.getCurrentUserId()+"_view",value)}catch(e){}},getSavedView:function(key){var val=appSettings.get(key+"_"+Dashboard.getCurrentUserId()+"_view");return val},getSavedViewSetting:function(key){return new Promise(function(resolve,reject){var val=LibraryBrowser.getSavedView(key);resolve(val)})},allowSwipe:function(target){function allowSwipeOn(elem){return!dom.parentWithTag(elem,"input")&&(!elem.classList||!elem.classList.contains("hiddenScrollX")&&!elem.classList.contains("smoothScrollX")&&!elem.classList.contains("animatedScrollX"))}for(var parent=target;null!=parent;){if(!allowSwipeOn(parent))return!1;parent=parent.parentNode}return!0},configureSwipeTabs:function(ownerpage,tabs){if(browser.touch){var pageCount=ownerpage.querySelectorAll(".pageTabContent").length,onSwipeLeft=function(e,target){if(LibraryBrowser.allowSwipe(target)&&ownerpage.contains(target)){var selected=parseInt(tabs.selectedIndex()||"0");selected<pageCount-1&&tabs.selectedIndex(selected+1)}},onSwipeRight=function(e,target){if(LibraryBrowser.allowSwipe(target)&&ownerpage.contains(target)){var selected=parseInt(tabs.selectedIndex()||"0");selected>0&&tabs.selectedIndex(selected-1)}};require(["touchHelper"],function(TouchHelper){var touchHelper=new TouchHelper(ownerpage.parentNode.parentNode);Events.on(touchHelper,"swipeleft",onSwipeLeft),Events.on(touchHelper,"swiperight",onSwipeRight),ownerpage.addEventListener("viewdestroy",function(){touchHelper.destroy()})})}},configurePaperLibraryTabs:function(ownerpage,tabs,panels,animateTabs,enableSwipe){enableSwipe!==!1&&LibraryBrowser.configureSwipeTabs(ownerpage,tabs),ownerpage.addEventListener("viewbeforeshow",function(){tabs.triggerBeforeTabChange&&null==this.firstTabIndex&&tabs.triggerBeforeTabChange()}),ownerpage.addEventListener("viewshow",function(){this.firstTabIndex?(tabs.selectedIndex(this.firstTabIndex),this.firstTabIndex=null):tabs.triggerTabChange()}),tabs.addEventListener("beforetabchange",function(e){null!=e.detail.previousIndex&&panels[e.detail.previousIndex].classList.remove("is-active");var newPanel=panels[e.detail.selectedTabIndex];null!=e.detail.previousIndex&&e.detail.previousIndex!=e.detail.selectedTabIndex&&newPanel.animate&&(animateTabs||[]).indexOf(e.detail.selectedTabIndex)!=-1&&fadeInRight(newPanel),newPanel.classList.add("is-active")})},showTab:function(url,index){var afterNavigate=function(){document.removeEventListener("pageinit",afterNavigate),window.location.href.toLowerCase().indexOf(url.toLowerCase())!=-1&&(this.firstTabIndex=index)};window.location.href.toLowerCase().indexOf(url.toLowerCase())!=-1?require(["viewManager"],function(viewManager){afterNavigate.call(viewManager.currentView())}):(pageClassOn("pageinit","page",afterNavigate),Dashboard.navigate(url))},getArtistLinksHtml:function(artists,cssClass){for(var html=[],i=0,length=artists.length;i<length;i++){var artist=artists[i],css=cssClass?' class="'+cssClass+'"':"";html.push("<a"+css+' href="itemdetails.html?id='+artist.Id+'">'+artist.