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

382 lines
11 KiB
JavaScript
Raw Normal View History

2013-12-27 14:10:06 -07:00
(function (window, document, $) {
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
2014-05-31 07:30:59 -07:00
//html += '<a href="index.html" class="headerButton headerButtonLeft headerHomeButton">';
//html += '<img src="css/images/items/folders/home.png" />';
//html += '</a>';
2014-05-29 12:34:20 -07:00
html += '<button type="button" data-role="none" title="Menu" class="headerButton libraryMenuButton headerButtonLeft">';
2014-05-28 07:21:07 -07:00
html += '<img src="css/images/menu.png" />';
2014-05-21 20:35:18 -07:00
html += '</button>';
2014-05-28 07:21:07 -07:00
html += '<div class="libraryMenuButtonText headerButton"><span>MEDIA</span><span class="mediaBrowserAccent">BROWSER</span></div>';
2013-12-27 14:10:06 -07:00
html += '<div class="viewMenuSecondary">';
2014-05-10 22:11:53 -07:00
html += '<a href="nowplaying.html" class="headerButton headerButtonRight headerRemoteButton"><img src="css/images/remote.png" /></a>';
2014-02-23 10:29:02 -07:00
2014-05-10 22:11:53 -07:00
html += '<button id="btnCast" class="btnCast btnDefaultCast headerButton headerButtonRight" type="button" data-role="none"><div class="btnCastImage"></div></button>';
html += '<button onclick="Search.showSearchPanel($.mobile.activePage);" type="button" data-role="none" class="headerButton headerButtonRight headerSearchButton"><img src="css/images/headersearch.png" /></button>';
if (user.Configuration.IsAdministrator) {
html += '<a href="dashboard.html" class="headerButton headerButtonRight headerSettingsButton"><img src="css/images/items/folders/settings.png" /></a>';
}
html += '<a class="headerButton headerButtonRight" href="#" onclick="Dashboard.showUserFlyout(this);">';
2013-12-27 14:10:06 -07:00
if (user.PrimaryImageTag) {
var url = ApiClient.getUserImageUrl(user.Id, {
2014-05-10 22:11:53 -07:00
height: 18,
2013-12-27 14:10:06 -07:00
tag: user.PrimaryImageTag,
type: "Primary"
});
html += '<img src="' + url + '" />';
} else {
html += '<img src="css/images/currentuserdefaultwhite.png" />';
}
html += '</a>';
html += '</div>';
html += '</div>';
2014-05-21 20:35:18 -07:00
$(document.body).prepend(html);
2014-02-23 13:35:58 -07:00
2014-05-21 20:35:18 -07:00
$(document).trigger('headercreated');
2014-05-29 12:34:20 -07:00
2014-06-03 20:34:36 -07:00
$('.libraryMenuButton').createHoverTouch().on('hovertouch', showLibraryMenu);
2013-12-27 14:10:06 -07:00
}
2014-05-01 19:54:33 -07:00
function getItemHref(item) {
2013-12-27 14:10:06 -07:00
2014-05-06 19:28:19 -07:00
return LibraryBrowser.getHref(item);
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="adminMenuOptions">';
html += '<div class="libraryMenuDivider"></div>';
2014-06-07 12:46:24 -07:00
//html += '<a class="viewMenuLink viewMenuTextLink lnkMediaFolder dashboardViewMenu" data-itemid="dashboard" href="dashboard.html">Dashboard</a>';
2014-05-14 13:20:19 -07:00
html += '<a class="viewMenuLink viewMenuTextLink lnkMediaFolder editorViewMenu" data-itemid="editor" href="edititemmetadata.html">Metadata Manager</a>';
html += '<a class="viewMenuLink viewMenuTextLink lnkMediaFolder reportsViewMenu" data-itemid="reports" href="reports.html">Reports</a>';
html += '</div>';
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-05-17 14:23:48 -07:00
var panel = getLibraryMenu();
updateLibraryNavLinks($.mobile.activePage);
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
2014-05-14 13:20:19 -07:00
var userId = Dashboard.getCurrentUserId();
2014-05-03 16:38:23 -07:00
2014-06-04 19:32:40 -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) {
var viewMenuCssClass = (i.CollectionType || 'general') + 'ViewMenu';
2014-06-07 12:46:24 -07:00
var itemId = i.Id;
if (i.CollectionType == "channels") {
itemId = "channels";
}
else if (i.CollectionType == "livetv") {
itemId = "livetv";
}
return '<a data-itemid="' + itemId + '" class="lnkMediaFolder viewMenuLink viewMenuTextLink ' + viewMenuCssClass + '" href="' + getItemHref(i) + '">' + i.Name + '</a>';
2014-05-14 13:20:19 -07:00
}).join('');
2014-05-21 20:35:18 -07:00
var elem = $('.libraryMenuOptions').html(html);
$('.viewMenuTextLink', elem).on('click', function () {
$('.libraryMenuButtonText').html(this.innerHTML);
});
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-05-14 13:20:19 -07:00
if (user.Configuration.IsAdministrator) {
$('.adminMenuOptions').show();
} else {
$('.adminMenuOptions').hide();
}
2013-12-27 14:10:06 -07:00
});
}
2014-05-14 11:04:26 -07:00
function getLibraryMenu(user, channelCount, items, liveTvInfo) {
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">';
2014-05-09 12:43:06 -07:00
html += '<div style="margin: 0 -1em;">';
2014-05-21 20:35:18 -07:00
html += '<a class="lnkMediaFolder viewMenuLink viewMenuTextLink homeViewMenu" href="index.html">Home</a>';
html += '<div class="libraryMenuDivider"></div>';
2014-05-14 11:04:26 -07:00
html += getViewsHtml(user, channelCount, items, liveTvInfo);
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
2014-05-12 11:04:25 -07:00
panel = $('#libraryPanel').panel({}).trigger('create');
2014-05-17 14:23:48 -07:00
updateLibraryMenu();
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() {
return getParameterByName('topParentId') || sessionStorage.getItem('topParentId') || null;
}
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');
} else {
$('.btnCast').removeClass('btnDefaultCast').addClass('btnActiveCast');
}
}
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-05-03 16:38:23 -07:00
2014-05-12 11:04:25 -07:00
var id = isLiveTvPage || isChannelsPage || isEditorPage || isReportsPage || page.hasClass('allLibraryPage') ?
2014-05-01 19:54:33 -07:00
'' :
getTopParentId() || '';
sessionStorage.setItem('topParentId', id);
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-05-01 19:54:33 -07:00
else if (id && itemId == id) {
$(this).addClass('selectedMediaFolder');
}
else {
$(this).removeClass('selectedMediaFolder');
}
});
$('.scopedLibraryViewNav a', page).each(function () {
var src = this.href;
if (src.indexOf('#') != -1) {
return;
}
src = replaceQueryString(src, 'topParentId', id);
this.href = src;
});
}
2014-05-21 20:35:18 -07:00
function updateContextText(page) {
var name = page.getAttribute('data-contextname');
if (name) {
$('.libraryMenuButtonText').html('<span>' + name + '</span>');
}
else if ($(page).hasClass('allLibraryPage')) {
$('.libraryMenuButtonText').html('<span>MEDIA</span><span class="mediaBrowserAccent">BROWSER</span>');
}
}
2014-03-13 02:00:47 -07:00
$(document).on('pageinit', ".libraryPage", function () {
2013-12-27 14:10:06 -07:00
2014-03-13 02:00:47 -07:00
var page = this;
2013-12-28 09:58:13 -07:00
2014-03-13 02:00:47 -07:00
$('.libraryViewNav', page).wrapInner('<div class="libraryViewNavInner"></div>');
2014-03-13 02:00:47 -07:00
$('.libraryViewNav a', page).each(function () {
2013-12-27 14:10:06 -07:00
2014-03-13 02:00:47 -07:00
this.innerHTML = '<span class="libraryViewNavLinkContent">' + this.innerHTML + '</span>';
2013-12-27 14:10:06 -07:00
2014-03-13 02:00:47 -07:00
});
2013-12-27 14:10:06 -07:00
2014-05-10 22:11:53 -07:00
}).on('pagebeforeshow', ".libraryPage", function () {
2013-12-27 14:10:06 -07:00
var page = this;
2014-05-21 20:35:18 -07:00
if (!$('.viewMenuBar').length) {
2013-12-27 14:10:06 -07:00
2014-05-10 22:11:53 -07:00
Dashboard.getCurrentUser().done(function (user) {
2013-12-27 14:10:06 -07:00
2014-05-21 20:35:18 -07:00
renderHeader(user);
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);
2014-05-10 22:11:53 -07:00
});
2014-05-21 20:35:18 -07:00
} else {
updateContextText(page);
updateLibraryNavLinks(page);
2014-05-01 19:54:33 -07:00
}
2014-03-29 11:20:42 -07:00
}).on('pagebeforeshow', ".page", function () {
var page = this;
if ($(page).hasClass('libraryPage')) {
$('.viewMenuBar').show();
} else {
$('.viewMenuBar').hide();
}
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
}
2014-05-01 19:54:33 -07:00
2014-05-16 10:11:07 -07:00
2013-12-27 14:10:06 -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
});
});
2014-06-03 20:34:36 -07:00
})(window, document, jQuery);
$.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');
}
});
};