1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/homesections/homesections.js

1 line
29 KiB
JavaScript
Raw Normal View History

2018-09-12 19:26:21 +02:00
define(["connectionManager","cardBuilder","registrationServices","appSettings","dom","apphost","layoutManager","imageLoader","globalize","itemShortcuts","itemHelper","appRouter","emby-button","paper-icon-button-light","emby-itemscontainer","emby-scroller","emby-linkbutton","css!./homesections"],function(connectionManager,cardBuilder,registrationServices,appSettings,dom,appHost,layoutManager,imageLoader,globalize,itemShortcuts,itemHelper,appRouter){"use strict";function getDefaultSection(index){switch(index){case 0:return"smalllibrarytiles";case 1:return"resume";case 2:return"resumeaudio";case 3:return"livetv";case 4:return"nextup";case 5:return"latestmedia";case 6:return"none";default:return""}}function getAllSectionsToShow(userSettings,sectionCount){for(var sections=[],i=0,length=sectionCount;i<length;i++){var section=userSettings.get("homesection"+i)||getDefaultSection(i);"folders"===section&&(section=getDefaultSection(0)),sections.push(section)}return sections}function loadSections(elem,apiClient,user,userSettings){return getUserViews(apiClient,user.Id).then(function(userViews){var i,length,html="";for(i=0,length=7;i<length;i++)html+='<div class="verticalSection section'+i+'"></div>';elem.innerHTML=html,elem.classList.add("homeSectionsContainer");var promises=[],sections=getAllSectionsToShow(userSettings,7);for(i=0,length=sections.length;i<length;i++)promises.push(loadSection(elem,apiClient,user,userSettings,userViews,sections,i));return Promise.all(promises).then(function(){html="";var style="margin-top:4em;";return layoutManager.tv&&(style+="padding: 0 7.5%;"),html+='<div class="verticalSection padded-left padded-right customizeSection hide" style="'+style+'">',html+='<a href="'+appRouter.getRouteUrl("settings")+'" is="emby-linkbutton" class="raised block"><span>'+globalize.translate("sharedcomponents#HeaderCustomizeHomeScreen")+"</span></a>",html+="</div>",elem.insertAdjacentHTML("beforeend",html),resume(elem,{refresh:!0,returnPromise:!1})})})}function destroySections(elem){var i,length,elems=elem.querySelectorAll(".itemsContainer");for(i=0,length=elems.length;i<length;i++)elems[i].fetchData=null,elems[i].parentContainer=null,elems[i].getItemsHtml=null;elem.innerHTML=""}function pause(elem){var i,length,elems=elem.querySelectorAll(".itemsContainer");for(i=0,length=elems.length;i<length;i++)elems[i].pause()}function resume(elem,options){var i,length,elems=elem.querySelectorAll(".itemsContainer"),promises=[];for(i=0,length=elems.length;i<length;i++)promises.push(elems[i].resume(options));var promise=Promise.all(promises).then(function(){elem.querySelector(".customizeSection").classList.remove("hide")});if(!options||!1!==options.returnPromise)return promise}function loadSection(page,apiClient,user,userSettings,userViews,allSections,index){var section=allSections[index],userId=user.Id,elem=page.querySelector(".section"+index);if("latestmedia"===section)loadRecentlyAdded(elem,apiClient,user,userViews);else{if("librarytiles"===section||"smalllibrarytiles"===section||"smalllibrarytiles-automobile"===section||"librarytiles-automobile"===section)return loadLibraryTiles(elem,apiClient,user,userSettings,"smallBackdrop",userViews,allSections);if("librarybuttons"===section)return loadlibraryButtons(elem,apiClient,user,userSettings,userViews);if("resume"===section)loadResumeVideo(elem,apiClient,userId);else if("resumeaudio"===section)loadResumeAudio(elem,apiClient,userId);else if("activerecordings"===section)loadLatestLiveTvRecordings(elem,!0,apiClient,userId);else{if("nextup"!==section)return"onnow"===section||"livetv"===section?loadOnNow(elem,apiClient,user):(elem.innerHTML="",Promise.resolve());loadNextUp(elem,apiClient,userId)}}return Promise.resolve()}function getUserViews(apiClient,userId){return apiClient.getUserViews({},userId||apiClient.getCurrentUserId()).then(function(result){return result.Items})}function enableScrollX(){return!0}function getSquareShape(){return enableScrollX()?"overflowSquare":"square"}function getThumbShape(){return enableScrollX()?"overflowBackdrop":"backdrop"}function getPortraitShape(){return e