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

685 lines
22 KiB
JavaScript
Raw Normal View History

2015-05-06 20:11:51 -07:00
(function (window, document, $, devicePixelRatio) {
2013-12-27 14:10:06 -07:00
2014-05-21 20:35:18 -07:00
function renderHeader(user) {
2013-12-27 14:10:06 -07:00
2013-12-28 00:09:05 -07:00
var html = '<div class="viewMenuBar ui-bar-b">';
2013-12-27 14:10:06 -07:00
2015-05-06 20:11:51 -07:00
if (($.browser.safari && window.navigator.standalone) || Dashboard.isRunningInCordova()) {
2015-05-10 14:56:13 -07:00
html += '<button type="button" data-role="none" onclick="history.back();" class="headerButton headerButtonLeft headerBackButton"><div class="fa fa-arrow-left"></div></button>';
2015-04-25 20:25:07 -07:00
}
2014-06-21 22:52:31 -07:00
html += '<button type="button" data-role="none" title="Menu" class="headerButton dashboardMenuButton barsMenuButton headerButtonLeft">';
2014-12-19 23:06:27 -07:00
html += '<div class="barMenuInner fa fa-bars">';
2014-07-27 15:01:29 -07:00
html += '</div>';
2014-06-21 22:52:31 -07:00
html += '</button>';
html += '<button type="button" data-role="none" title="Menu" class="headerButton libraryMenuButton barsMenuButton headerButtonLeft">';
2014-12-19 23:06:27 -07:00
html += '<div class="barMenuInner fa fa-bars">';
2014-07-27 15:01:29 -07:00
html += '</div>';
2014-05-21 20:35:18 -07:00
html += '</button>';
2014-10-25 11:32:58 -07:00
2015-03-21 11:12:12 -07:00
html += '<div class="libraryMenuButtonText headerButton"><span>EMBY</span></div>';
2015-01-20 23:26:16 -07:00
2013-12-27 14:10:06 -07:00
html += '<div class="viewMenuSecondary">';
2015-05-08 09:58:27 -07:00
var btnCastVisible = user.localUser ? '' : 'visibility:hidden;';
2014-10-25 11:32:58 -07:00
2015-05-08 09:58:27 -07:00
if (!AppInfo.enableHeaderImages) {
html += '<button id="btnCast" class="btnCast btnCastIcon btnDefaultCast headerButton headerButtonRight" type="button" data-role="none" style="' + btnCastVisible + '">';
html += '<div class="headerSelectedPlayer"></div><i class="fa fa-wifi"></i>';
html += '</button>';
2014-10-25 11:32:58 -07:00
} else {
2015-05-08 09:58:27 -07:00
html += '<button id="btnCast" class="btnCast btnDefaultCast headerButton headerButtonRight" type="button" data-role="none" style="' + btnCastVisible + '"><div class="headerSelectedPlayer"></div><div class="btnCastImage"></div></button>';
}
2014-05-10 22:11:53 -07:00
2015-05-08 09:58:27 -07:00
if (user.localUser) {
html += '<button onclick="Search.showSearchPanel($.mobile.activePage);" type="button" data-role="none" class="headerButton headerButtonRight headerSearchButton"><div class="fa fa-search" style="font-size:21px;"></div></button>';
2015-05-13 22:42:55 -07:00
html += '<div class="viewMenuSearch hide"><form class="viewMenuSearchForm">';
html += '<input type="text" data-role="none" data-type="search" class="headerSearchInput" autocomplete="off" spellcheck="off" />';
html += '<div class="searchInputIcon fa fa-search"></div>';
html += '<button data-role="none" type="button" data-iconpos="notext" class="imageButton btnCloseSearch"><i class="fa fa-close"></i></button>';
html += '</form></div>';
2014-10-25 11:32:58 -07:00
}
2015-05-06 20:11:51 -07:00
2015-05-05 08:24:47 -07:00
if (user.name) {
2015-05-06 20:11:51 -07:00
2015-05-10 14:56:13 -07:00
html += '<button class="headerButton headerButtonRight headerUserButton" type="button" data-role="none" onclick="Dashboard.showUserFlyout(this);">';
2014-05-10 22:11:53 -07:00
2015-05-08 09:58:27 -07:00
if (user.imageUrl && AppInfo.enableUserImage) {
2013-12-27 14:10:06 -07:00
2015-05-05 08:24:47 -07:00
var userButtonHeight = 26;
2013-12-27 14:10:06 -07:00
2015-05-05 08:24:47 -07:00
var url = user.imageUrl;
2014-12-19 23:06:27 -07:00
2015-05-05 08:24:47 -07:00
if (user.supportsImageParams) {
url += "&height=" + (userButtonHeight * Math.max(devicePixelRatio || 1, 2));
}
2014-10-25 11:32:58 -07:00
2015-05-10 14:56:13 -07:00
html += '<div class="lazy headerUserImage" data-src="' + url + '" style="width:' + userButtonHeight + 'px;height:' + userButtonHeight + 'px;"></div>';
2015-05-05 08:24:47 -07:00
} else {
html += '<div class="fa fa-user"></div>';
2014-10-25 11:32:58 -07:00
}
2013-12-27 14:10:06 -07:00
2015-05-10 14:56:13 -07:00
html += '</button>';
2013-12-27 14:10:06 -07:00
}
2014-10-25 11:32:58 -07:00
if (user.canManageServer) {
2015-01-26 15:47:16 -07:00
html += '<a href="dashboard.html" class="headerButton headerButtonRight dashboardEntryHeaderButton"><div class="fa fa-cog"></div></a>';
2014-06-21 22:52:31 -07:00
}
2013-12-27 14:10:06 -07:00
html += '</div>';
html += '</div>';
2014-05-21 20:35:18 -07:00
$(document.body).prepend(html);
2015-05-09 21:29:04 -07:00
$('.viewMenuBar').trigger('create').lazyChildren();
2014-02-23 13:35:58 -07:00
2014-05-21 20:35:18 -07:00
$(document).trigger('headercreated');
2015-04-25 20:25:07 -07:00
bindMenuEvents();
}
function bindMenuEvents() {
2014-05-29 12:34:20 -07:00
2015-05-06 20:11:51 -07:00
if (AppInfo.isTouchPreferred) {
2015-04-25 20:25:07 -07:00
2015-05-06 20:11:51 -07:00
$('.libraryMenuButton').on('click', function () {
2015-04-25 20:25:07 -07:00
showLibraryMenu(false);
});
2015-05-06 20:11:51 -07:00
$('.dashboardMenuButton').on('click', function () {
2015-04-25 20:25:07 -07:00
showDashboardMenu(false);
});
} else {
$('.libraryMenuButton').createHoverTouch().on('hovertouch', showLibraryMenu);
$('.dashboardMenuButton').createHoverTouch().on('hovertouch', showDashboardMenu);
}
2015-05-04 07:35:38 -07:00
// grab an element
var viewMenuBar = document.getElementsByClassName("viewMenuBar")[0];
2015-05-06 20:11:51 -07:00
initHeadRoom(viewMenuBar);
2013-12-27 14:10:06 -07:00
}
2015-05-07 15:27:01 -07:00
function updateViewMenuBarHeadroom(page, viewMenuBar) {
2015-05-08 09:58:27 -07:00
2015-05-07 15:27:01 -07:00
if ($(page).hasClass('libraryPage')) {
viewMenuBar.removeClass('headroomDisabled');
} else {
viewMenuBar.addClass('headroomDisabled');
}
}
function getItemHref(item, context) {
2013-12-27 14:10:06 -07:00
return LibraryBrowser.getHref(item, context);
2014-05-01 19:54:33 -07:00
}
2014-05-10 22:11:53 -07:00
2014-05-14 13:20:19 -07:00
function getViewsHtml() {
2014-05-10 22:11:53 -07:00
2014-05-01 19:54:33 -07:00
var html = '';
2014-05-14 13:20:19 -07:00
html += '<div class="libraryMenuOptions">';
html += '</div>';
2014-05-01 19:54:33 -07:00
2014-05-14 13:20:19 -07:00
html += '<div class="libraryMenuDivider"></div>';
2014-12-30 23:24:49 -07:00
html += '<div class="adminMenuOptions">';
2014-12-30 12:16:01 -07:00
2015-05-07 15:27:01 -07:00
html += '<a class="sidebarLink lnkMediaFolder" data-itemid="dashboard" data-rel="none" href="dashboard.html"><span class="fa fa-cog sidebarLinkIcon"></span>' + Globalize.translate('ButtonDashboard') + '</a>';
2015-01-23 21:50:45 -07:00
html += '<a class="sidebarLink lnkMediaFolder editorViewMenu" data-itemid="editor" href="edititemmetadata.html"><span class="fa fa-edit sidebarLinkIcon"></span>' + Globalize.translate('ButtonMetadataManager') + '</a>';
2015-05-13 08:39:07 -07:00
html += '<a class="sidebarLink lnkMediaFolder" data-itemid="reports" href="reports.html"><span class="fa fa-bar-chart sidebarLinkIcon"></span>' + Globalize.translate('ButtonReports') + '</a>';
2014-05-14 13:20:19 -07:00
html += '</div>';
2015-01-23 21:50:45 -07:00
html += '<a class="sidebarLink lnkMediaFolder syncViewMenu" data-itemid="mysync" href="mysync.html"><span class="fa fa-cloud sidebarLinkIcon"></span>' + Globalize.translate('ButtonSync') + '</a>';
2014-05-03 16:38:23 -07:00
2014-05-14 13:20:19 -07:00
return html;
}
2014-03-18 10:05:57 -07:00
2014-05-14 13:20:19 -07:00
function showLibraryMenu() {
2014-03-13 02:00:47 -07:00
2014-06-21 22:52:31 -07:00
var page = $.mobile.activePage;
var panel;
2015-05-18 15:23:03 -07:00
ConnectionManager.user(window.ApiClient).done(function (user) {
2014-06-21 22:52:31 -07:00
2015-04-27 10:55:57 -07:00
panel = getLibraryMenu(user);
updateLibraryNavLinks(page);
2014-06-21 22:52:31 -07:00
2015-04-27 10:55:57 -07:00
$(panel).panel('toggle').off('mouseleave.librarymenu').on('mouseleave.librarymenu', function () {
2014-06-21 22:52:31 -07:00
2015-04-27 10:55:57 -07:00
$(this).panel("close");
});
2014-06-21 22:52:31 -07:00
});
}
function showDashboardMenu() {
2014-05-17 14:23:48 -07:00
2014-06-21 22:52:31 -07:00
var page = $.mobile.activePage;
var panel = getDashboardMenu(page);
2014-05-17 14:23:48 -07:00
2014-06-03 20:34:36 -07:00
$(panel).panel('toggle').off('mouseleave.librarymenu').on('mouseleave.librarymenu', function () {
$(this).panel("close");
});
2014-05-17 14:23:48 -07:00
}
2014-05-21 20:35:18 -07:00
2014-05-17 14:23:48 -07:00
function updateLibraryMenu(panel) {
2014-06-03 20:34:36 -07:00
2015-05-18 15:23:03 -07:00
var apiClient = window.ApiClient;
2014-10-25 11:32:58 -07:00
if (!apiClient) {
$('.adminMenuOptions').hide();
2014-12-30 23:24:49 -07:00
$('.syncViewMenu').hide();
2014-10-25 11:32:58 -07:00
return;
}
2014-05-14 13:20:19 -07:00
var userId = Dashboard.getCurrentUserId();
2014-05-03 16:38:23 -07:00
2014-10-25 11:32:58 -07:00
apiClient.getUserViews(userId).done(function (result) {
2014-05-14 13:20:19 -07:00
var items = result.Items;
var html = items.map(function (i) {
2014-12-30 12:16:01 -07:00
var iconCssClass = 'fa';
2014-05-14 13:20:19 -07:00
2014-06-07 12:46:24 -07:00
var itemId = i.Id;
2014-06-21 22:52:31 -07:00
2014-06-07 12:46:24 -07:00
if (i.CollectionType == "channels") {
itemId = "channels";
}
else if (i.CollectionType == "livetv") {
itemId = "livetv";
}
2014-10-25 11:32:58 -07:00
if (i.Type == 'Channel') {
}
2014-06-07 12:46:24 -07:00
2014-12-30 12:16:01 -07:00
if (i.CollectionType == "photos") {
iconCssClass += ' fa-photo';
}
else if (i.CollectionType == "music" || i.CollectionType == "musicvideos") {
iconCssClass += ' fa-music';
}
else if (i.CollectionType == "books") {
iconCssClass += ' fa-book';
}
else if (i.CollectionType == "playlists") {
iconCssClass += ' fa-list';
}
else if (i.CollectionType == "games") {
iconCssClass += ' fa-gamepad';
}
else if (i.CollectionType == "movies") {
iconCssClass += ' fa-film';
}
else if (i.CollectionType == "channels" || i.Type == 'Channel') {
iconCssClass += ' fa-globe';
}
else if (i.CollectionType == "tvshows" || i.CollectionType == "livetv") {
iconCssClass += ' fa-video-camera';
}
else {
iconCssClass += ' fa-folder-open-o';
}
2015-01-23 21:50:45 -07:00
return '<a data-itemid="' + itemId + '" class="lnkMediaFolder sidebarLink" href="' + getItemHref(i, i.CollectionType) + '"><span class="' + iconCssClass + ' sidebarLinkIcon"></span><span class="sectionName">' + i.Name + '</span></a>';
2014-05-14 13:20:19 -07:00
}).join('');
2014-05-21 20:35:18 -07:00
var elem = $('.libraryMenuOptions').html(html);
2015-01-23 21:50:45 -07:00
$('.sidebarLink', elem).on('click', function () {
2014-05-21 20:35:18 -07:00
2014-12-30 12:16:01 -07:00
var section = $('.sectionName', this)[0];
var text = section ? section.innerHTML : this.innerHTML;
$('.libraryMenuButtonText').html(text);
2014-05-21 20:35:18 -07:00
});
2014-05-14 13:20:19 -07:00
});
2013-12-27 14:10:06 -07:00
2014-05-14 13:20:19 -07:00
Dashboard.getCurrentUser().done(function (user) {
2013-12-27 14:10:06 -07:00
2014-12-19 23:06:27 -07:00
if (user.Policy.IsAdministrator) {
2014-05-14 13:20:19 -07:00
$('.adminMenuOptions').show();
} else {
$('.adminMenuOptions').hide();
}
2015-01-17 22:45:10 -07:00
2014-12-30 23:24:49 -07:00
if (user.Policy.EnableSync) {
$('.syncViewMenu').show();
} else {
$('.syncViewMenu').hide();
}
2013-12-27 14:10:06 -07:00
});
}
2014-06-21 22:52:31 -07:00
var requiresLibraryMenuRefresh = false;
2015-05-20 09:28:55 -07:00
var requiresViewMenuRefresh = false;
2014-06-21 22:52:31 -07:00
2014-10-25 11:32:58 -07:00
function getLibraryMenu(user) {
2013-12-27 14:10:06 -07:00
2014-05-12 11:04:25 -07:00
var panel = $('#libraryPanel');
2013-12-27 14:10:06 -07:00
if (!panel.length) {
var html = '';
html += '<div data-role="panel" id="libraryPanel" class="libraryPanel" data-position="left" data-display="overlay" data-position-fixed="true" data-theme="b">';
2015-04-27 10:55:57 -07:00
html += '<div class="sidebarLinks librarySidebarLinks">';
2014-05-21 20:35:18 -07:00
2015-05-06 20:11:51 -07:00
var showUserAtTop = AppInfo.isTouchPreferred;
2015-04-27 10:55:57 -07:00
2015-05-02 09:34:27 -07:00
if (showUserAtTop) {
2015-04-27 10:55:57 -07:00
2015-05-02 09:34:27 -07:00
var userHref = user.localUser && user.localUser.Policy.EnableUserPreferenceAccess ?
'mypreferencesdisplay.html?userId=' + user.localUser.Id :
(user.localUser ? 'index.html' : '#');
2014-10-25 11:32:58 -07:00
2015-05-08 09:58:27 -07:00
var hasUserImage = user.imageUrl && AppInfo.enableUserImage;
var paddingLeft = hasUserImage ? 'padding-left:.7em;' : '';
2015-05-02 09:34:27 -07:00
html += '<a style="margin-top:0;' + paddingLeft + 'display:block;color:#fff;text-decoration:none;font-size:16px;font-weight:400!important;background: #000;" href="' + userHref + '">';
2015-04-27 10:55:57 -07:00
2015-05-02 09:34:27 -07:00
var imgWidth = 44;
2015-04-27 10:55:57 -07:00
2015-05-08 09:58:27 -07:00
if (hasUserImage) {
2015-05-02 09:34:27 -07:00
var url = user.imageUrl;
2015-04-29 10:39:23 -07:00
2015-05-02 09:34:27 -07:00
if (user.supportsImageParams) {
url += "&width=" + (imgWidth * Math.max(devicePixelRatio || 1, 2));
}
2015-05-09 21:29:04 -07:00
html += '<div class="lazy" data-src="' + url + '" style="width:' + imgWidth + 'px;height:' + imgWidth + 'px;background-size:contain;background-repeat:no-repeat;background-position:center center;border-radius:1000px;vertical-align:middle;margin-right:.8em;display:inline-block;"></div>';
2015-05-02 09:34:27 -07:00
} else {
html += '<span class="fa fa-user sidebarLinkIcon"></span>';
}
html += user.name;
html += '</a>';
2015-05-02 16:08:02 -07:00
html += '<div class="libraryMenuDivider" style="margin-top:0;"></div>';
2015-05-02 09:34:27 -07:00
}
2015-04-27 10:55:57 -07:00
2015-05-18 15:23:03 -07:00
var homeHref = window.ApiClient ? 'index.html' : 'selectserver.html';
2014-10-25 11:32:58 -07:00
2015-05-02 09:34:27 -07:00
if (showUserAtTop) {
html += '<a class="lnkMediaFolder sidebarLink" href="' + homeHref + '"><span class="fa fa-home sidebarLinkIcon"></span><span>' + Globalize.translate('ButtonHome') + '</span></a>';
2015-05-02 16:08:02 -07:00
2015-05-02 09:34:27 -07:00
} else {
html += '<a class="lnkMediaFolder sidebarLink" style="margin-top:.5em;padding-left:1em;display:block;color:#fff;text-decoration:none;" href="' + homeHref + '">';
2015-04-29 10:39:23 -07:00
2015-05-02 09:34:27 -07:00
html += '<img style="max-width:36px;vertical-align:middle;margin-right:1em;" src="css/images/mblogoicon.png" />';
2015-04-29 10:39:23 -07:00
2015-05-02 09:34:27 -07:00
html += Globalize.translate('ButtonHome');
html += '</a>';
2015-05-02 16:08:02 -07:00
}
2014-05-21 20:35:18 -07:00
2015-05-08 12:10:53 -07:00
html += '<a class="sidebarLink lnkMediaFolder" data-itemid="dashboard" data-rel="none" href="nowplaying.html"><span class="fa fa-tablet sidebarLinkIcon"></span>' + Globalize.translate('ButtonRemote') + '</a>';
html += '<div class="libraryMenuDivider"></div>';
2014-06-10 10:36:06 -07:00
html += getViewsHtml();
2014-05-09 12:43:06 -07:00
html += '</div>';
2013-12-27 14:10:06 -07:00
html += '</div>';
2014-05-12 11:04:25 -07:00
$(document.body).append(html);
2013-12-27 14:10:06 -07:00
2015-05-09 21:29:04 -07:00
panel = $('#libraryPanel').panel({}).lazyChildren().trigger('create');
2014-05-17 14:23:48 -07:00
updateLibraryMenu();
2013-12-27 14:10:06 -07:00
}
2014-06-21 22:52:31 -07:00
else if (requiresLibraryMenuRefresh) {
updateLibraryMenu();
requiresLibraryMenuRefresh = false;
}
return panel;
}
function getDashboardMenu(page) {
var panel = $('#dashboardPanel', page);
if (!panel.length) {
var html = '';
html += '<div data-role="panel" id="dashboardPanel" class="dashboardPanel" data-position="left" data-display="overlay" data-position-fixed="true" data-theme="b">';
html += '<div style="margin: 0 -1em;">';
html += '</div>';
html += '</div>';
$(document.body).append(html);
panel = $('#dashboardPanel').panel({}).trigger('create');
}
2013-12-27 14:10:06 -07:00
return panel;
}
2014-06-03 20:34:36 -07:00
function setLibraryMenuText(text) {
2014-06-03 20:34:36 -07:00
$('.libraryMenuButtonText').html('<span>' + text + '</span>');
}
2013-12-27 14:10:06 -07:00
2014-05-01 19:54:33 -07:00
function getTopParentId() {
2015-05-20 10:29:26 -07:00
return getParameterByName('topParentId') || null;
2014-05-01 19:54:33 -07:00
}
2014-03-13 02:00:47 -07:00
window.LibraryMenu = {
2014-05-01 19:54:33 -07:00
showLibraryMenu: showLibraryMenu,
getTopParentId: getTopParentId,
2014-06-03 20:34:36 -07:00
setText: setLibraryMenuText
2014-03-13 02:00:47 -07:00
};
2014-05-01 19:54:33 -07:00
2014-03-29 11:20:42 -07:00
function updateCastIcon() {
2014-05-01 19:54:33 -07:00
2014-03-29 11:20:42 -07:00
var info = MediaController.getPlayerInfo();
if (info.isLocalPlayer) {
$('.btnCast').addClass('btnDefaultCast').removeClass('btnActiveCast');
2014-06-21 22:52:31 -07:00
$('.headerSelectedPlayer').html('');
2014-03-29 11:20:42 -07:00
} else {
$('.btnCast').removeClass('btnDefaultCast').addClass('btnActiveCast');
2014-08-16 22:38:13 -07:00
$('.headerSelectedPlayer').html((info.deviceName || info.name));
2014-03-29 11:20:42 -07:00
}
}
2013-12-27 14:10:06 -07:00
2014-05-12 11:04:25 -07:00
function updateLibraryNavLinks(page) {
2014-05-01 19:54:33 -07:00
page = $(page);
var isLiveTvPage = page.hasClass('liveTvPage');
2014-05-02 21:20:04 -07:00
var isChannelsPage = page.hasClass('channelsPage');
2014-05-12 11:04:25 -07:00
var isEditorPage = page.hasClass('metadataEditorPage');
var isReportsPage = page.hasClass('reportsPage');
2014-12-30 23:24:49 -07:00
var isMySyncPage = page.hasClass('mySyncPage');
2014-05-03 16:38:23 -07:00
2014-12-30 23:24:49 -07:00
var id = isLiveTvPage || isChannelsPage || isEditorPage || isReportsPage || isMySyncPage || page.hasClass('allLibraryPage') ?
2014-05-01 19:54:33 -07:00
'' :
getTopParentId() || '';
2014-05-09 12:43:06 -07:00
$('.lnkMediaFolder').each(function () {
2014-05-01 19:54:33 -07:00
var itemId = this.getAttribute('data-itemid');
2014-05-02 21:20:04 -07:00
if (isChannelsPage && itemId == 'channels') {
$(this).addClass('selectedMediaFolder');
}
else if (isLiveTvPage && itemId == 'livetv') {
2014-05-01 19:54:33 -07:00
$(this).addClass('selectedMediaFolder');
}
2014-05-12 11:04:25 -07:00
else if (isEditorPage && itemId == 'editor') {
$(this).addClass('selectedMediaFolder');
}
else if (isReportsPage && itemId == 'reports') {
$(this).addClass('selectedMediaFolder');
}
2014-12-30 23:24:49 -07:00
else if (isMySyncPage && itemId == 'mysync') {
$(this).addClass('selectedMediaFolder');
}
2014-05-01 19:54:33 -07:00
else if (id && itemId == id) {
$(this).addClass('selectedMediaFolder');
}
else {
$(this).removeClass('selectedMediaFolder');
}
});
var context = getParameterByName('context');
2014-05-01 19:54:33 -07:00
if (context !== 'playlists') {
$('.scopedLibraryViewNav a', page).each(function () {
2014-05-01 19:54:33 -07:00
var src = this.href;
2014-05-01 19:54:33 -07:00
if (src.indexOf('#') != -1) {
return;
}
2014-05-01 19:54:33 -07:00
src = replaceQueryString(src, 'topParentId', id);
this.href = src;
});
}
2014-05-01 19:54:33 -07:00
}
2014-05-21 20:35:18 -07:00
function updateContextText(page) {
2015-05-20 09:28:55 -07:00
var name = $(page)[0].getAttribute('data-contextname');
2014-05-21 20:35:18 -07:00
if (name) {
$('.libraryMenuButtonText').html('<span>' + name + '</span>');
}
2014-06-21 22:52:31 -07:00
//else if ($(page).hasClass('type-interior')) {
// $('.libraryMenuButtonText').html('<span>' + 'Dashboard' + '</span>');
//}
else if ($(page).hasClass('allLibraryPage') || $(page).hasClass('type-interior')) {
2015-03-21 11:12:12 -07:00
$('.libraryMenuButtonText').html('<span class="logoLibraryMenuButtonText">EMBY</span>');
2014-05-21 20:35:18 -07:00
}
}
2014-06-21 22:52:31 -07:00
function onWebSocketMessage(e, data) {
var msg = data;
if (msg.MessageType === "UserConfigurationUpdated") {
if (msg.Data.Id == Dashboard.getCurrentUserId()) {
requiresLibraryMenuRefresh = true;
}
}
}
2015-05-20 09:28:55 -07:00
function buildViewMenuBar(page) {
2013-12-27 14:10:06 -07:00
2015-05-20 09:28:55 -07:00
if ($(page).hasClass('standalonePage')) {
$('.viewMenuBar').remove();
return;
}
2013-12-27 14:10:06 -07:00
2015-05-20 09:28:55 -07:00
if (requiresViewMenuRefresh) {
$('.viewMenuBar').remove();
}
2013-12-27 14:10:06 -07:00
2015-05-07 15:27:01 -07:00
var viewMenuBar = $('.viewMenuBar');
2014-05-21 20:35:18 -07:00
if (!$('.viewMenuBar').length) {
2013-12-27 14:10:06 -07:00
2015-05-18 15:23:03 -07:00
ConnectionManager.user(window.ApiClient).done(function (user) {
2013-12-27 14:10:06 -07:00
2014-05-21 20:35:18 -07:00
renderHeader(user);
2015-05-07 15:27:01 -07:00
updateViewMenuBarHeadroom(page, $('.viewMenuBar'));
2014-05-01 19:54:33 -07:00
2014-05-10 22:11:53 -07:00
updateCastIcon();
2014-05-14 11:04:26 -07:00
2014-05-10 22:11:53 -07:00
updateLibraryNavLinks(page);
2014-05-21 20:35:18 -07:00
updateContextText(page);
2015-05-20 09:28:55 -07:00
requiresViewMenuRefresh = false;
2014-05-10 22:11:53 -07:00
});
2014-05-21 20:35:18 -07:00
} else {
updateContextText(page);
updateLibraryNavLinks(page);
2015-05-07 15:27:01 -07:00
updateViewMenuBarHeadroom(page, viewMenuBar);
2015-05-20 09:28:55 -07:00
requiresViewMenuRefresh = false;
2014-05-01 19:54:33 -07:00
}
2014-03-29 11:20:42 -07:00
2015-05-20 09:28:55 -07:00
}
2014-10-25 11:32:58 -07:00
2015-05-20 09:28:55 -07:00
$(document).on('pageinit', ".page", function () {
2014-06-21 22:52:31 -07:00
2015-05-20 09:28:55 -07:00
var page = this;
$('.libraryViewNav', page).wrapInner('<div class="libraryViewNavInner"></div>');
$('.libraryViewNav a', page).each(function () {
this.innerHTML = '<span class="libraryViewNavLinkContent">' + this.innerHTML + '</span>';
});
}).on('pagebeforeshowready', ".page", function () {
var page = this;
2015-05-20 09:28:55 -07:00
buildViewMenuBar(page);
2015-05-20 09:28:55 -07:00
var jpage = $(page);
2015-05-08 20:48:43 -07:00
2015-05-20 09:28:55 -07:00
var isLibraryPage = jpage.hasClass('libraryPage');
2015-05-08 20:48:43 -07:00
2015-05-20 09:28:55 -07:00
if (isLibraryPage) {
$(document.body).addClass('libraryDocument').removeClass('dashboardDocument');
2015-05-08 20:48:43 -07:00
2015-05-20 09:28:55 -07:00
if (AppInfo.enableBottomTabs) {
$(page).addClass('noSecondaryNavPage');
2015-05-08 09:58:27 -07:00
2015-05-20 09:28:55 -07:00
$(function () {
2015-05-07 15:27:01 -07:00
2015-05-20 09:28:55 -07:00
$('.footer').addClass('footerOverBottomTabs');
});
} else {
$('.libraryViewNav', page).each(function () {
initHeadRoom(this);
});
}
}
else if (jpage.hasClass('type-interior')) {
$(document.body).addClass('dashboardDocument').removeClass('libraryDocument');
} else {
$(document.body).removeClass('dashboardDocument').removeClass('libraryDocument');
}
2014-03-14 21:14:07 -07:00
}).on('pageshow', ".libraryPage", function () {
var page = this;
var elem = $('.libraryViewNavInner .ui-btn-active:visible', page);
if (elem.length) {
elem[0].scrollIntoView();
2014-03-16 09:15:10 -07:00
// Scroll back up so in case vertical scroll was messed with
$(document).scrollTop(0);
2014-03-14 21:14:07 -07:00
}
2013-12-27 14:10:06 -07:00
});
2015-05-06 20:11:51 -07:00
function initHeadRoom(elem) {
if (!AppInfo.enableHeadRoom) {
return;
}
2015-05-08 20:48:43 -07:00
requirejs(["thirdparty/headroom"], function () {
// construct an instance of Headroom, passing the element
var headroom = new Headroom(elem);
// initialise
headroom.init();
});
2015-05-06 20:11:51 -07:00
}
2014-10-25 11:32:58 -07:00
function initializeApiClient(apiClient) {
2014-10-30 21:57:24 -07:00
2015-05-19 12:15:40 -07:00
requiresLibraryMenuRefresh = true;
2014-10-25 11:32:58 -07:00
$(apiClient).off('websocketmessage.librarymenu', onWebSocketMessage).on('websocketmessage.librarymenu', onWebSocketMessage);
}
2015-05-19 12:15:40 -07:00
Dashboard.ready(function () {
2015-05-18 15:23:03 -07:00
2015-05-19 12:15:40 -07:00
if (window.ApiClient) {
initializeApiClient(window.ApiClient);
}
2015-05-18 18:46:31 -07:00
2015-05-19 12:15:40 -07:00
$(ConnectionManager).on('apiclientcreated', function (e, apiClient) {
initializeApiClient(apiClient);
2015-05-18 18:46:31 -07:00
2015-05-19 12:15:40 -07:00
}).on('localusersignedin localusersignedout', function () {
requiresLibraryMenuRefresh = true;
2015-05-20 09:28:55 -07:00
requiresViewMenuRefresh = true;
2015-05-19 12:15:40 -07:00
});
2014-10-30 21:57:24 -07:00
});
2014-05-01 19:54:33 -07:00
$(function () {
2014-03-29 09:58:49 -07:00
$(MediaController).on('playerchange', function () {
2014-03-29 11:20:42 -07:00
updateCastIcon();
2014-03-29 09:58:49 -07:00
});
});
2015-05-06 20:11:51 -07:00
})(window, document, jQuery, window.devicePixelRatio);
2014-06-03 20:34:36 -07:00
$.fn.createHoverTouch = function () {
var preventHover = false;
var timerId;
function startTimer(elem) {
stopTimer();
timerId = setTimeout(function () {
$(elem).trigger('hovertouch');
2014-06-07 14:06:01 -07:00
}, 300);
2014-06-03 20:34:36 -07:00
}
function stopTimer(elem) {
if (timerId) {
clearTimeout(timerId);
timerId = null;
}
}
return $(this).on('mouseenter', function () {
if (preventHover === true) {
2014-06-07 12:46:24 -07:00
preventHover = false;
2014-06-03 20:34:36 -07:00
return;
}
startTimer(this);
}).on('mouseleave', function () {
stopTimer(this);
}).on('touchstart', function () {
preventHover = true;
}).on('click', function () {
preventHover = true;
if (preventHover) {
$(this).trigger('hovertouch');
2014-06-24 14:45:21 -07:00
stopTimer(this);
preventHover = false;
2014-06-03 20:34:36 -07:00
}
});
};