diff --git a/dashboard-ui/scripts/Itemdetailpage.js b/dashboard-ui/scripts/Itemdetailpage.js index 0e515a4851..02cf348499 100644 --- a/dashboard-ui/scripts/Itemdetailpage.js +++ b/dashboard-ui/scripts/Itemdetailpage.js @@ -151,7 +151,7 @@ if (url) { - var style = useBackgroundColor ? "background-color:" + Dashboard.getMetroColor(item.Id) + ";" : ""; + var style = useBackgroundColor ? "background-color:" + LibraryBrowser.getMetroColor(item.Id) + ";" : ""; html += ""; } @@ -700,7 +700,7 @@ html += ''; } else { - var style = "background-color:" + Dashboard.getMetroColor(cast.Name) + ";"; + var style = "background-color:" + LibraryBrowser.getMetroColor(cast.Name) + ";"; html += ''; } diff --git a/dashboard-ui/scripts/indexpage.js b/dashboard-ui/scripts/indexpage.js index dfd932416d..e2ae9d52b8 100644 --- a/dashboard-ui/scripts/indexpage.js +++ b/dashboard-ui/scripts/indexpage.js @@ -19,7 +19,7 @@ apiClient.getItems(userId, options).done(function (result) { - $('#divCollections', page).html(Dashboard.getPosterViewHtml({ + $('#divCollections', page).html(LibraryBrowser.getPosterViewHtml({ items: result.Items, showTitle: true })); diff --git a/dashboard-ui/scripts/itembynamedetailpage.js b/dashboard-ui/scripts/itembynamedetailpage.js index d810a1fffb..86d396fd94 100644 --- a/dashboard-ui/scripts/itembynamedetailpage.js +++ b/dashboard-ui/scripts/itembynamedetailpage.js @@ -95,7 +95,7 @@ } if (url) { - var style = useBackgroundColor ? "background-color:" + Dashboard.getMetroColor(item.Id) + ";" : ""; + var style = useBackgroundColor ? "background-color:" + LibraryBrowser.getMetroColor(item.Id) + ";" : ""; html += ""; } diff --git a/dashboard-ui/scripts/itemlistpage.js b/dashboard-ui/scripts/itemlistpage.js index 4d6d4e2577..a2b0e827e5 100644 --- a/dashboard-ui/scripts/itemlistpage.js +++ b/dashboard-ui/scripts/itemlistpage.js @@ -83,7 +83,7 @@ showTitle: query.Recursive }; - var html = Dashboard.getPosterViewHtml(renderOptions); + var html = LibraryBrowser.getPosterViewHtml(renderOptions); $('#listItems', $.mobile.activePage).html(html); diff --git a/dashboard-ui/scripts/librarybrowser.js b/dashboard-ui/scripts/librarybrowser.js index 5f282702bb..60075ca7c0 100644 --- a/dashboard-ui/scripts/librarybrowser.js +++ b/dashboard-ui/scripts/librarybrowser.js @@ -1 +1,124 @@ - \ No newline at end of file +var LibraryBrowser = { + + getPosterViewHtml: function (options) { + + var items = options.items; + + var primaryImageAspectRatio = options.useAverageAspectRatio ? LibraryBrowser.getAveragePrimaryImageAspectRatio(items) : null; + + var html = ""; + + for (var i = 0, length = items.length; i < length; i++) { + var item = items[i]; + + var hasPrimaryImage = item.ImageTags && item.ImageTags.Primary; + + var href = item.url || (item.IsFolder ? (item.Id ? "itemList.html?parentId=" + item.Id : "#") : "itemdetails.html?id=" + item.Id); + + var showText = options.showTitle || !hasPrimaryImage || (item.Type !== 'Movie' && item.Type !== 'Series' && item.Type !== 'Season' && item.Type !== 'Trailer'); + + var cssClass = showText ? "posterViewItem" : "posterViewItem posterViewItemWithNoText"; + + html += "
"; + + if (options.preferBackdrop && item.BackdropImageTags && item.BackdropImageTags.length) { + html += ""; + } else if (hasPrimaryImage) { + + var height = 300; + var width = primaryImageAspectRatio ? parseInt(height * primaryImageAspectRatio) : null; + + html += ""; + + } + else if (item.BackdropImageTags && item.BackdropImageTags.length) { + html += ""; + } + else if (item.MediaType == "Audio" || item.Type == "MusicAlbum" || item.Type == "MusicArtist") { + + html += ""; + } + else { + + html += ""; + } + + if (showText) { + html += "
"; + html += item.Name; + html += "
"; + } + + html += "
"; + } + + return html; + }, + + getAveragePrimaryImageAspectRatio: function (items) { + + var values = []; + + for (var i = 0, length = items.length; i < length; i++) { + + var ratio = items[i].PrimaryImageAspectRatio || 0; + + if (!ratio) { + continue; + } + + values[values.length] = ratio; + } + + if (!values.length) { + return null; + } + + // Use the median + values.sort(function (a, b) { return a - b; }); + + var half = Math.floor(values.length / 2); + + if (values.length % 2) + return values[half]; + else + return (values[half - 1] + values[half]) / 2.0; + }, + + metroColors: ["#6FBD45", "#4BB3DD", "#4164A5", "#E12026", "#800080", "#E1B222", "#008040", "#0094FF", "#FF00C7", "#FF870F", "#7F0037"], + + getRandomMetroColor: function () { + + var index = Math.floor(Math.random() * (LibraryBrowser.metroColors.length - 1)); + + return LibraryBrowser.metroColors[index]; + }, + + getMetroColor: function (str) { + + if (str) { + var char = str.substr(0,1).charCodeAt(); + var index = String(char).substr(char.length,1); + + return LibraryBrowser.metroColors[index]; + }else { + return LibraryBrowser.getRandomMetroColor(); + } + + } +} \ No newline at end of file diff --git a/dashboard-ui/scripts/loginpage.js b/dashboard-ui/scripts/loginpage.js index 5969e8e619..d9071453f2 100644 --- a/dashboard-ui/scripts/loginpage.js +++ b/dashboard-ui/scripts/loginpage.js @@ -60,7 +60,7 @@ var linkId = "lnkUser" + i; - var background = Dashboard.getMetroColor(user.Id); + var background = LibraryBrowser.getMetroColor(user.Id); html += '
'; diff --git a/dashboard-ui/scripts/movies.js b/dashboard-ui/scripts/movies.js index dfa923b24b..a3b3dc5df6 100644 --- a/dashboard-ui/scripts/movies.js +++ b/dashboard-ui/scripts/movies.js @@ -63,7 +63,7 @@ } else { - html += ''; + html += ''; } html += ''; @@ -86,7 +86,7 @@ ApiClient.getItems(Dashboard.getCurrentUserId(), query).done(function (result) { - $('#items', page).html(Dashboard.getPosterViewHtml({ + $('#items', page).html(LibraryBrowser.getPosterViewHtml({ items: result.Items, useAverageAspectRatio: true diff --git a/dashboard-ui/scripts/moviesrecommended.js b/dashboard-ui/scripts/moviesrecommended.js index 7ede94fb58..450f5f8832 100644 --- a/dashboard-ui/scripts/moviesrecommended.js +++ b/dashboard-ui/scripts/moviesrecommended.js @@ -16,7 +16,7 @@ ApiClient.getItems(Dashboard.getCurrentUserId(), options).done(function (result) { - $('#recentlyAddedItems', page).html(Dashboard.getPosterViewHtml({ + $('#recentlyAddedItems', page).html(LibraryBrowser.getPosterViewHtml({ items: result.Items, useAverageAspectRatio: true })); @@ -43,7 +43,7 @@ $('#resumableSection', page).hide(); } - $('#resumableItems', page).html(Dashboard.getPosterViewHtml({ + $('#resumableItems', page).html(LibraryBrowser.getPosterViewHtml({ items: result.Items, useAverageAspectRatio: true })); diff --git a/dashboard-ui/scripts/plugincatalogpage.js b/dashboard-ui/scripts/plugincatalogpage.js index 16e6d23c65..32d50dcf43 100644 --- a/dashboard-ui/scripts/plugincatalogpage.js +++ b/dashboard-ui/scripts/plugincatalogpage.js @@ -54,7 +54,7 @@ } } - var color = plugin.tileColor || Dashboard.getMetroColor(plugin.name); + var color = plugin.tileColor || LibraryBrowser.getMetroColor(plugin.name); html += "
"; diff --git a/dashboard-ui/scripts/site.js b/dashboard-ui/scripts/site.js index 7b505a8117..ed5de7361a 100644 --- a/dashboard-ui/scripts/site.js +++ b/dashboard-ui/scripts/site.js @@ -421,105 +421,7 @@ var Dashboard = { }, 500); }, - getPosterViewHtml: function (options) { - var items = options.items; - - var primaryImageAspectRatio = options.useAverageAspectRatio ? Dashboard.getAveragePrimaryImageAspectRatio(items) : null; - - var html = ""; - - for (var i = 0, length = items.length; i < length; i++) { - var item = items[i]; - - var hasPrimaryImage = item.ImageTags && item.ImageTags.Primary; - - var href = item.url || (item.IsFolder ? (item.Id ? "itemList.html?parentId=" + item.Id : "#") : "itemdetails.html?id=" + item.Id); - - var showText = options.showTitle || !hasPrimaryImage || (item.Type !== 'Movie' && item.Type !== 'Series' && item.Type !== 'Season' && item.Type !== 'Trailer'); - - var cssClass = showText ? "posterViewItem" : "posterViewItem posterViewItemWithNoText"; - - html += ""; - } - - return html; - }, - - getAveragePrimaryImageAspectRatio: function (items) { - - var values = []; - - for (var i = 0, length = items.length; i < length; i++) { - - var ratio = items[i].PrimaryImageAspectRatio || 0; - - if (!ratio) { - continue; - } - - values[values.length] = ratio; - } - - if (!values.length) { - return null; - } - - // Use the median - values.sort(function (a, b) { return a - b; }); - - var half = Math.floor(values.length / 2); - - if (values.length % 2) - return values[half]; - else - return (values[half - 1] + values[half]) / 2.0; - }, showUserFlyout: function () { @@ -1149,29 +1051,8 @@ var Dashboard = { if (title) { document.title = title; } - }, - - metroColors: ["#6FBD45", "#4BB3DD", "#4164A5", "#E12026", "#800080", "#E1B222", "#008040", "#0094FF", "#FF00C7", "#FF870F", "#7F0037"], - - getRandomMetroColor: function () { - - var index = Math.floor(Math.random() * (Dashboard.metroColors.length - 1)); - - return Dashboard.metroColors[index]; - }, - - getMetroColor: function (str) { - - if (str) { - var char = str.substr(0,1).charCodeAt(); - var index = String(char).substr(char.length,1); - - return Dashboard.metroColors[index]; - }else { - return Dashboard.getRandomMetroColor(); - } - } + }; diff --git a/dashboard-ui/scripts/tvrecommended.js b/dashboard-ui/scripts/tvrecommended.js index 795447846e..3a02f5ee5d 100644 --- a/dashboard-ui/scripts/tvrecommended.js +++ b/dashboard-ui/scripts/tvrecommended.js @@ -16,7 +16,7 @@ ApiClient.getItems(Dashboard.getCurrentUserId(), options).done(function (result) { - $('#recentlyAddedItems', page).html(Dashboard.getPosterViewHtml({ + $('#recentlyAddedItems', page).html(LibraryBrowser.getPosterViewHtml({ items: result.Items, useAverageAspectRatio: true })); @@ -43,7 +43,7 @@ $('#resumableSection', page).hide(); } - $('#resumableItems', page).html(Dashboard.getPosterViewHtml({ + $('#resumableItems', page).html(LibraryBrowser.getPosterViewHtml({ items: result.Items, useAverageAspectRatio: true }));