2017-03-21 23:03:23 -07:00
|
|
|
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),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")})},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.Name+"</a>")}return html=html.join(" / ")},getHref:function(item,context,topParentId){if(!item)throw new Error("item cannot be null");if(item.url)return item.url;var url,id=item.Id||item.ItemId;if("SeriesTimer"==item.Type)return"itemdetails.html?seriesTimerId="+id;if("livetv"==item.CollectionType)return"livetv.html";if("channels"==item.CollectionType)return"channels.html";if("folders"!=context){if("movies"==item.CollectionType)return"movies.html?topParentId="+item.Id;if("boxsets"==item.CollectionType)return"itemlist.html?topParentId="+item.Id+"&parentId="+item.Id;if("tvshows"==item.CollectionType)return"tv.html?topParentId="+item.Id;if("music"==item.CollectionType)return"music.html?topParentId="+item.Id;if("games"==item.Collection
|