define(['scrollHelper', 'viewManager', 'appSettings', 'appStorage', 'apphost', 'datetime', 'itemHelper', 'mediaInfo', 'scrollStyles'], function (scrollHelper, viewManager, appSettings, appStorage, appHost, datetime, itemHelper, mediaInfo) { function parentWithClass(elem, className) { while (!elem.classList || !elem.classList.contains(className)) { elem = elem.parentNode; if (!elem) { return null; } } return elem; } function fadeInRight(elem) { var pct = browserInfo.mobile ? '2.5%' : '0.5%'; var 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' }); } function animateSelectionBar(button) { var elem = button.querySelector('.pageTabButtonSelectionBar'); if (!elem) { return; } var keyframes = [ { transform: 'translate3d(-100%, 0, 0)', offset: 0 }, { transform: 'none', offset: 1 }]; if (!elem.animate) { return; } elem.animate(keyframes, { duration: 120, iterations: 1, easing: 'ease-out' }); } var libraryBrowser = (function (window, document, screen) { // Regular Expressions for parsing tags and attributes var SURROGATE_PAIR_REGEXP = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, // Match everything outside of normal chars and " (quote character) NON_ALPHANUMERIC_REGEXP = /([^\#-~| |!])/g; /** * Escapes all potentially dangerous characters, so that the * resulting string can be safely inserted into attribute or * element text. * @param value * @returns {string} escaped text */ function htmlEncode(value) { return value. replace(/&/g, '&'). replace(SURROGATE_PAIR_REGEXP, function (value) { var hi = value.charCodeAt(0); var low = value.charCodeAt(1); return '' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';'; }). replace(NON_ALPHANUMERIC_REGEXP, function (value) { return '' + value.charCodeAt(0) + ';'; }). replace(//g, '>'); } var pageSizeKey = 'pagesize_v4'; function getDesiredAspect(shape) { if (shape) { shape = shape.toLowerCase(); if (shape.indexOf('portrait') != -1) { return (2 / 3); } if (shape.indexOf('backdrop') != -1) { return (16 / 9); } if (shape.indexOf('square') != -1) { return 1; } } return null; } var libraryBrowser = { getDefaultPageSize: function (key, defaultValue) { return 100; var saved = appStorage.getItem(key || pageSizeKey); if (saved) { return parseInt(saved); } if (defaultValue) { return defaultValue; } return 100; }, getDefaultItemsView: function (view, mobileView) { return browserInfo.mobile ? mobileView : view; }, getSavedQueryKey: function (modifier) { return window.location.href.split('#')[0] + (modifier || ''); }, loadSavedQueryValues: function (key, query) { var values = appStorage.getItem(key + '_' + Dashboard.getCurrentUserId()); if (values) { values = JSON.parse(values); return Object.assign(query, values); } return query; }, saveQueryValues: function (key, query) { var values = {}; if (query.SortBy) { values.SortBy = query.SortBy; } if (query.SortOrder) { values.SortOrder = query.SortOrder; } try { appStorage.setItem(key + '_' + Dashboard.getCurrentUserId(), JSON.stringify(values)); } catch (e) { } }, saveViewSetting: function (key, value) { try { appStorage.setItem(key + '_' + Dashboard.getCurrentUserId() + '_view', value); } catch (e) { } }, getSavedView: function (key) { var val = appStorage.getItem(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) { if (elem.classList) { return !elem.classList.contains('hiddenScrollX') && !elem.classList.contains('smoothScrollX') && !elem.classList.contains('libraryViewNav'); } return true; } var parent = target; while (parent != null) { if (!allowSwipeOn(parent)) { return false; } parent = parent.parentNode; } return true; }, selectedTab: function (tabs, selected) { if (selected == null) { return tabs.selectedTabIndex || 0; } var current = LibraryBrowser.selectedTab(tabs); tabs.selectedTabIndex = selected; if (current == selected) { tabs.dispatchEvent(new CustomEvent("tabchange", { detail: { selectedTabIndex: selected } })); } else { var tabButtons = tabs.querySelectorAll('.pageTabButton'); tabButtons[selected].click(); } }, configureSwipeTabs: function (ownerpage, tabs) { var pageCount = ownerpage.querySelectorAll('.pageTabContent').length; require(['hammer'], function (Hammer) { var hammertime = new Hammer(ownerpage); hammertime.get('swipe').set({ direction: Hammer.DIRECTION_HORIZONTAL }); hammertime.on('swipeleft', function (e) { if (LibraryBrowser.allowSwipe(e.target)) { var selected = parseInt(LibraryBrowser.selectedTab(tabs) || '0'); if (selected < (pageCount - 1)) { LibraryBrowser.selectedTab(tabs, selected + 1); } } }); hammertime.on('swiperight', function (e) { if (LibraryBrowser.allowSwipe(e.target)) { var selected = parseInt(LibraryBrowser.selectedTab(tabs) || '0'); if (selected > 0) { LibraryBrowser.selectedTab(tabs, selected - 1); } } }); }); }, configurePaperLibraryTabs: function (ownerpage, tabs, panels, animateTabs) { if (!browserInfo.safari) { LibraryBrowser.configureSwipeTabs(ownerpage, tabs); } if (!browserInfo.safari || !AppInfo.isNativeApp) { var buttons = tabs.querySelectorAll('.pageTabButton'); for (var i = 0, length = buttons.length; i < length; i++) { var div = document.createElement('div'); div.classList.add('pageTabButtonSelectionBar'); buttons[i].appendChild(div); } } tabs.classList.add('hiddenScrollX'); tabs.addEventListener('click', function (e) { var current = tabs.querySelector('.is-active'); var link = parentWithClass(e.target, 'pageTabButton'); if (link && link != current) { if (current) { current.classList.remove('is-active'); panels[parseInt(current.getAttribute('data-index'))].classList.remove('is-active'); } link.classList.add('is-active'); animateSelectionBar(link); var index = parseInt(link.getAttribute('data-index')); var newPanel = panels[index]; // If toCenter is called syncronously within the click event, it sometimes ends up canceling it setTimeout(function () { if (animateTabs && animateTabs.indexOf(index) != -1 && /*browserInfo.animate &&*/ newPanel.animate) { fadeInRight(newPanel); } tabs.dispatchEvent(new CustomEvent("tabchange", { detail: { selectedTabIndex: index } })); newPanel.classList.add('is-active'); //scrollHelper.toCenter(tabs, link, true); }, 120); } }); ownerpage.addEventListener('viewbeforeshow', LibraryBrowser.onTabbedpagebeforeshow); }, onTabbedpagebeforeshow: function (e) { var page = e.target; var delay = 0; var isFirstLoad = false; if (!page.getAttribute('data-firstload')) { delay = 300; isFirstLoad = true; page.setAttribute('data-firstload', '1'); } if (delay) { setTimeout(function () { LibraryBrowser.onTabbedpagebeforeshowInternal(page, e, isFirstLoad); }, delay); } else { LibraryBrowser.onTabbedpagebeforeshowInternal(page, e, isFirstLoad); } }, onTabbedpagebeforeshowInternal: function (page, e, isFirstLoad) { var pageTabsContainer = page.querySelector('.libraryViewNav'); if (isFirstLoad) { console.log('selected tab is null, checking query string'); var selected = page.firstTabIndex != null ? page.firstTabIndex : parseInt(getParameterByName('tab') || '0'); console.log('selected tab will be ' + selected); LibraryBrowser.selectedTab(pageTabsContainer, selected); } else { // Go back to the first tab if (!e.detail.isRestored) { LibraryBrowser.selectedTab(pageTabsContainer, 0); return; } pageTabsContainer.dispatchEvent(new CustomEvent("tabchange", { detail: { selectedTabIndex: LibraryBrowser.selectedTab(pageTabsContainer) } })); } }, showTab: function (url, index) { var afterNavigate = function () { document.removeEventListener('pagebeforeshow', afterNavigate); if (window.location.href.toLowerCase().indexOf(url.toLowerCase()) != -1) { this.firstTabIndex = index; } }; if (window.location.href.toLowerCase().indexOf(url.toLowerCase()) != -1) { afterNavigate.call(viewManager.currentView()); } else { pageClassOn('pagebeforeshow', 'page', afterNavigate); Dashboard.navigate(url); } }, canShare: function (item, user) { if (item.Type == 'Timer') { return false; } return user.Policy.EnablePublicSharing; }, getDateParamValue: function (date) { function formatDigit(i) { return i < 10 ? "0" + i : i; } var d = date; return "" + d.getFullYear() + formatDigit(d.getMonth() + 1) + formatDigit(d.getDate()) + formatDigit(d.getHours()) + formatDigit(d.getMinutes()) + formatDigit(d.getSeconds()); }, playAllFromHere: function (fn, index) { fn(index, 100, "MediaSources,Chapters").then(function (result) { MediaController.play({ items: result.Items }); }); }, queueAllFromHere: function (query, index) { fn(index, 100, "MediaSources,Chapters").then(function (result) { MediaController.queue({ items: result.Items }); }); }, getItemCountsHtml: function (options, item) { var counts = []; var childText; if (item.Type == 'Playlist') { childText = ''; if (item.CumulativeRunTimeTicks) { var minutes = item.CumulativeRunTimeTicks / 600000000; minutes = minutes || 1; childText += Globalize.translate('ValueMinutes', Math.round(minutes)); } else { childText += Globalize.translate('ValueMinutes', 0); } counts.push(childText); } else if (options.context == "movies") { if (item.MovieCount) { childText = item.MovieCount == 1 ? Globalize.translate('ValueOneMovie') : Globalize.translate('ValueMovieCount', item.MovieCount); counts.push(childText); } if (item.TrailerCount) { childText = item.TrailerCount == 1 ? Globalize.translate('ValueOneTrailer') : Globalize.translate('ValueTrailerCount', item.TrailerCount); counts.push(childText); } } else if (options.context == "tv") { if (item.SeriesCount) { childText = item.SeriesCount == 1 ? Globalize.translate('ValueOneSeries') : Globalize.translate('ValueSeriesCount', item.SeriesCount); counts.push(childText); } if (item.EpisodeCount) { childText = item.EpisodeCount == 1 ? Globalize.translate('ValueOneEpisode') : Globalize.translate('ValueEpisodeCount', item.EpisodeCount); counts.push(childText); } } else if (options.context == "games") { if (item.GameCount) { childText = item.GameCount == 1 ? Globalize.translate('ValueOneGame') : Globalize.translate('ValueGameCount', item.GameCount); counts.push(childText); } } else if (options.context == "music") { if (item.AlbumCount) { childText = item.AlbumCount == 1 ? Globalize.translate('ValueOneAlbum') : Globalize.translate('ValueAlbumCount', item.AlbumCount); counts.push(childText); } if (item.SongCount) { childText = item.SongCount == 1 ? Globalize.translate('ValueOneSong') : Globalize.translate('ValueSongCount', item.SongCount); counts.push(childText); } if (item.MusicVideoCount) { childText = item.MusicVideoCount == 1 ? Globalize.translate('ValueOneMusicVideo') : Globalize.translate('ValueMusicVideoCount', item.MusicVideoCount); counts.push(childText); } } return counts.join(' • '); }, getArtistLinksHtml: function (artists, cssClass) { var html = []; for (var i = 0, length = artists.length; i < length; i++) { var artist = artists[i]; var css = cssClass ? (' class="' + cssClass + '"') : ''; html.push('' + artist.Name + ''); } html = html.join(' / '); return html; }, playInExternalPlayer: function (id) { Dashboard.loadExternalPlayer().then(function () { ExternalPlayer.showMenu(id); }); }, showPlayMenu: function (positionTo, itemId, itemType, isFolder, mediaType, resumePositionTicks) { var externalPlayers = AppInfo.supportsExternalPlayers && appSettings.enableExternalPlayers(); if (!resumePositionTicks && mediaType != "Audio" && !isFolder) { if (!externalPlayers || mediaType != "Video") { MediaController.play(itemId); return; } } var menuItems = []; if (resumePositionTicks) { menuItems.push({ name: Globalize.translate('ButtonResume'), id: 'resume', ironIcon: 'play-arrow' }); } menuItems.push({ name: Globalize.translate('ButtonPlay'), id: 'play', ironIcon: 'play-arrow' }); if (!isFolder && externalPlayers && mediaType != "Audio") { menuItems.push({ name: Globalize.translate('ButtonPlayExternalPlayer'), id: 'externalplayer', ironIcon: 'airplay' }); } if (MediaController.canQueueMediaType(mediaType, itemType)) { menuItems.push({ name: Globalize.translate('ButtonQueue'), id: 'queue', ironIcon: 'playlist-add' }); } if (itemType == "Audio" || itemType == "MusicAlbum" || itemType == "MusicArtist" || itemType == "MusicGenre") { menuItems.push({ name: Globalize.translate('ButtonInstantMix'), id: 'instantmix', ironIcon: 'shuffle' }); } if (isFolder || itemType == "MusicArtist" || itemType == "MusicGenre") { menuItems.push({ name: Globalize.translate('ButtonShuffle'), id: 'shuffle', ironIcon: 'shuffle' }); } require(['actionsheet'], function (actionsheet) { actionsheet.show({ items: menuItems, positionTo: positionTo, callback: function (id) { switch (id) { case 'play': MediaController.play(itemId); break; case 'externalplayer': LibraryBrowser.playInExternalPlayer(itemId); break; case 'resume': MediaController.play({ ids: [itemId], startPositionTicks: resumePositionTicks }); break; case 'queue': MediaController.queue(itemId); break; case 'instantmix': MediaController.instantMix(itemId); break; case 'shuffle': MediaController.shuffle(itemId); break; default: break; } } }); }); }, supportsEditing: function (itemType) { if (itemType == "UserRootFolder" || /*itemType == "CollectionFolder" ||*/ itemType == "UserView" || itemType == 'Timer') { return false; } return true; }, getMoreCommands: function (item, user) { var commands = []; if (itemHelper.supportsAddingToCollection(item)) { commands.push('addtocollection'); } if (itemHelper.supportsAddingToPlaylist(item)) { commands.push('playlist'); } if (item.Type == 'BoxSet' || item.Type == 'Playlist') { commands.push('delete'); } else if (item.CanDelete) { commands.push('delete'); } if (user.Policy.IsAdministrator) { if (LibraryBrowser.supportsEditing(item.Type)) { commands.push('edit'); } if (item.MediaType == 'Video' && item.Type != 'TvChannel' && item.Type != 'Program' && item.LocationType != 'Virtual') { commands.push('editsubtitles'); } if (item.Type != 'Timer') { commands.push('editimages'); } } if (user.Policy.IsAdministrator) { commands.push('refresh'); } if (LibraryBrowser.enableSync(item, user)) { commands.push('sync'); } if (item.CanDownload) { if (appHost.supports('filedownload')) { commands.push('download'); } } if (LibraryBrowser.canShare(item, user)) { commands.push('share'); } if (LibraryBrowser.canIdentify(user, item.Type)) { commands.push('identify'); } return commands; }, canIdentify: function (user, itemType) { if (itemType == "Movie" || itemType == "Trailer" || itemType == "Series" || itemType == "Game" || itemType == "BoxSet" || itemType == "Person" || itemType == "Book" || itemType == "MusicAlbum" || itemType == "MusicArtist") { if (user.Policy.IsAdministrator) { return true; } } return false; }, refreshItem: function (itemId) { ApiClient.refreshItem(itemId, { Recursive: true, ImageRefreshMode: 'FullRefresh', MetadataRefreshMode: 'FullRefresh', ReplaceAllImages: false, ReplaceAllMetadata: true }); require(['toast'], function (toast) { toast(Globalize.translate('MessageRefreshQueued')); }); }, deleteItems: function (itemIds) { return new Promise(function (resolve, reject) { var msg = Globalize.translate('ConfirmDeleteItem'); var title = Globalize.translate('HeaderDeleteItem'); if (itemIds.length > 1) { msg = Globalize.translate('ConfirmDeleteItems'); title = Globalize.translate('HeaderDeleteItems'); } require(['confirm'], function (confirm) { confirm(msg, title).then(function () { var promises = itemIds.map(function (itemId) { ApiClient.deleteItem(itemId); Events.trigger(LibraryBrowser, 'itemdeleting', [itemId]); }); resolve(); }, reject); }); }); }, editImages: function (itemId) { require(['components/imageeditor/imageeditor'], function (ImageEditor) { ImageEditor.show(itemId); }); }, editSubtitles: function (itemId) { require(['subtitleEditor'], function (subtitleEditor) { var serverId = ApiClient.serverInfo().Id; subtitleEditor.show(itemId, serverId); }); }, editMetadata: function (itemId) { require(['components/metadataeditor/metadataeditor'], function (metadataeditor) { metadataeditor.show(itemId); }); }, editTimer: function (id) { require(['recordingEditor'], function (recordingEditor) { var serverId = ApiClient.serverInfo().Id; recordingEditor.show(id, serverId); }); }, showMoreCommands: function (positionTo, itemId, itemType, commands) { var items = []; if (commands.indexOf('addtocollection') != -1) { items.push({ name: Globalize.translate('ButtonAddToCollection'), id: 'addtocollection', ironIcon: 'add' }); } if (commands.indexOf('playlist') != -1) { items.push({ name: Globalize.translate('ButtonAddToPlaylist'), id: 'playlist', ironIcon: 'playlist-add' }); } if (commands.indexOf('delete') != -1) { items.push({ name: Globalize.translate('ButtonDelete'), id: 'delete', ironIcon: 'delete' }); } if (commands.indexOf('download') != -1) { items.push({ name: Globalize.translate('ButtonDownload'), id: 'download', ironIcon: 'file-download' }); } if (commands.indexOf('edit') != -1) { items.push({ name: Globalize.translate('ButtonEdit'), id: 'edit', ironIcon: 'mode-edit' }); } if (commands.indexOf('editimages') != -1) { items.push({ name: Globalize.translate('ButtonEditImages'), id: 'editimages', ironIcon: 'photo' }); } if (commands.indexOf('editsubtitles') != -1) { items.push({ name: Globalize.translate('ButtonEditSubtitles'), id: 'editsubtitles', ironIcon: 'closed-caption' }); } if (commands.indexOf('identify') != -1) { items.push({ name: Globalize.translate('ButtonIdentify'), id: 'identify', ironIcon: 'info' }); } if (commands.indexOf('refresh') != -1) { items.push({ name: Globalize.translate('ButtonRefresh'), id: 'refresh', ironIcon: 'refresh' }); } if (commands.indexOf('share') != -1) { items.push({ name: Globalize.translate('ButtonShare'), id: 'share', ironIcon: 'share' }); } var serverId = ApiClient.serverInfo().Id; require(['actionsheet'], function (actionsheet) { actionsheet.show({ items: items, positionTo: positionTo, callback: function (id) { switch (id) { case 'share': require(['sharingmanager'], function (sharingManager) { sharingManager.showMenu({ serverId: serverId, itemId: itemId }); }); break; case 'addtocollection': require(['collectionEditor'], function (collectionEditor) { new collectionEditor().show({ items: [itemId], serverId: serverId }); }); break; case 'playlist': require(['playlistEditor'], function (playlistEditor) { new playlistEditor().show({ items: [itemId], serverId: serverId }); }); break; case 'delete': LibraryBrowser.deleteItems([itemId]); break; case 'download': { require(['fileDownloader'], function (fileDownloader) { var downloadHref = ApiClient.getUrl("Items/" + itemId + "/Download", { api_key: ApiClient.accessToken() }); fileDownloader.download([ { url: downloadHref, itemId: itemId, serverId: serverId }]); }); break; } case 'edit': if (itemType == 'Timer') { LibraryBrowser.editTimer(itemId); } else { LibraryBrowser.editMetadata(itemId); } break; case 'editsubtitles': LibraryBrowser.editSubtitles(itemId); break; case 'editimages': LibraryBrowser.editImages(itemId); break; case 'identify': LibraryBrowser.identifyItem(itemId); break; case 'refresh': ApiClient.refreshItem(itemId, { Recursive: true, ImageRefreshMode: 'FullRefresh', MetadataRefreshMode: 'FullRefresh', ReplaceAllImages: false, ReplaceAllMetadata: true }); require(['toast'], function (toast) { toast(Globalize.translate('MessageRefreshQueued')); }); break; default: break; } } }); }); }, identifyItem: function (itemId) { require(['components/itemidentifier/itemidentifier'], function (itemidentifier) { itemidentifier.show(itemId); }); }, getHref: function (item, context, topParentId) { var href = LibraryBrowser.getHrefInternal(item, context); if (context == 'tv') { if (!topParentId) { topParentId = LibraryMenu.getTopParentId(); } if (topParentId) { href += href.indexOf('?') == -1 ? "?topParentId=" : "&topParentId="; href += topParentId; } } return href; }, getHrefInternal: function (item, context) { if (!item) { throw new Error('item cannot be null'); } if (item.url) { return item.url; } // Handle search hints var id = item.Id || item.ItemId; if (item.CollectionType == 'livetv') { return 'livetv.html'; } if (item.CollectionType == 'channels') { return 'channels.html'; } if (context != 'folders') { if (item.CollectionType == 'movies') { return 'movies.html?topParentId=' + item.Id; } if (item.CollectionType == 'boxsets') { return 'collections.html?topParentId=' + item.Id; } if (item.CollectionType == 'tvshows') { return 'tv.html?topParentId=' + item.Id; } if (item.CollectionType == 'music') { return 'music.html?topParentId=' + item.Id; } if (item.CollectionType == 'games') { return id ? "itemlist.html?parentId=" + id : "#"; //return 'gamesrecommended.html?topParentId=' + item.Id; } if (item.CollectionType == 'playlists') { return 'playlists.html?topParentId=' + item.Id; } if (item.CollectionType == 'photos') { return 'photos.html?topParentId=' + item.Id; } } else if (item.IsFolder) { return id ? "itemlist.html?parentId=" + id : "#"; } if (item.Type == 'CollectionFolder') { return 'itemlist.html?topParentId=' + item.Id + '&parentId=' + item.Id; } if (item.Type == "PhotoAlbum") { return "itemlist.html?context=photos&parentId=" + id; } if (item.Type == "Playlist") { return "itemdetails.html?id=" + id; } if (item.Type == "TvChannel") { return "itemdetails.html?id=" + id; } if (item.Type == "Channel") { return "channelitems.html?id=" + id; } if ((item.IsFolder && item.SourceType == 'Channel') || item.Type == 'ChannelFolderItem') { return "channelitems.html?id=" + item.ChannelId + '&folderId=' + item.Id; } if (item.Type == "Program") { return "itemdetails.html?id=" + id; } if (item.Type == "BoxSet") { return "itemdetails.html?id=" + id; } if (item.Type == "MusicAlbum") { return "itemdetails.html?id=" + id; } if (item.Type == "GameSystem") { return "itemdetails.html?id=" + id; } if (item.Type == "Genre") { return "itemdetails.html?id=" + id; } if (item.Type == "MusicGenre") { return "itemdetails.html?id=" + id; } if (item.Type == "GameGenre") { return "itemdetails.html?id=" + id; } if (item.Type == "Studio") { return "itemdetails.html?id=" + id; } if (item.Type == "Person") { return "itemdetails.html?id=" + id; } if (item.Type == "Recording") { return "itemdetails.html?id=" + id; } if (item.Type == "MusicArtist") { return "itemdetails.html?id=" + id; } var contextSuffix = context ? ('&context=' + context) : ''; if (item.Type == "Series" || item.Type == "Season" || item.Type == "Episode") { return "itemdetails.html?id=" + id + contextSuffix; } if (item.IsFolder) { return id ? "itemlist.html?parentId=" + id : "#"; } return "itemdetails.html?id=" + id; }, getImageUrl: function (item, type, index, options) { options = options || {}; options.type = type; options.index = index; if (type == 'Backdrop') { options.tag = item.BackdropImageTags[index]; } else if (type == 'Screenshot') { options.tag = item.ScreenshotImageTags[index]; } else if (type == 'Primary') { options.tag = item.PrimaryImageTag || item.ImageTags[type]; } else { options.tag = item.ImageTags[type]; } // For search hints return ApiClient.getScaledImageUrl(item.Id || item.ItemId, options); }, getListViewIndex: function (item, options) { if (options.index == 'disc') { return item.ParentIndexNumber == null ? '' : Globalize.translate('ValueDiscNumber', item.ParentIndexNumber); } var sortBy = (options.sortBy || '').toLowerCase(); var code, name; if (sortBy.indexOf('sortname') == 0) { if (item.Type == 'Episode') return ''; // SortName name = (item.SortName || item.Name || '?')[0].toUpperCase(); code = name.charCodeAt(0); if (code < 65 || code > 90) { return '#'; } return name.toUpperCase(); } if (sortBy.indexOf('officialrating') == 0) { return item.OfficialRating || Globalize.translate('HeaderUnrated'); } if (sortBy.indexOf('communityrating') == 0) { if (item.CommunityRating == null) { return Globalize.translate('HeaderUnrated'); } return Math.floor(item.CommunityRating); } if (sortBy.indexOf('criticrating') == 0) { if (item.CriticRating == null) { return Globalize.translate('HeaderUnrated'); } return Math.floor(item.CriticRating); } if (sortBy.indexOf('metascore') == 0) { if (item.Metascore == null) { return Globalize.translate('HeaderUnrated'); } return Math.floor(item.Metascore); } if (sortBy.indexOf('albumartist') == 0) { // SortName if (!item.AlbumArtist) return ''; name = item.AlbumArtist[0].toUpperCase(); code = name.charCodeAt(0); if (code < 65 || code > 90) { return '#'; } return name.toUpperCase(); } return ''; }, getUserDataCssClass: function (key) { if (!key) return ''; return 'libraryItemUserData' + key.replace(new RegExp(' ', 'g'), ''); }, getListViewHtml: function (options) { require(['paper-icon-item', 'paper-item-body', 'material-icons']); var outerHtml = ""; if (options.title) { outerHtml += '