(function (window, document, $, devicePixelRatio) { function renderHeader(user) { var html = '
'; if (($.browser.safari && window.navigator.standalone) || Dashboard.isRunningInCordova()) { html += '
'; } html += ''; html += ''; html += '
EMBY
'; if (user.localUser) { html += '
'; html += ''; html += ''; html += ''; html += '
'; } html += '
'; var btnCastVisible = user.localUser ? '' : 'visibility:hidden;'; if (!AppInfo.enableHeaderImages) { html += ''; } else { html += ''; } if (user.localUser) { html += ''; } if (user.name) { html += ''; if (user.imageUrl && AppInfo.enableUserImage) { var userButtonHeight = 26; var url = user.imageUrl; if (user.supportsImageParams) { url += "&height=" + (userButtonHeight * Math.max(devicePixelRatio || 1, 2)); } html += ''; } else { html += '
'; } html += '
'; } if (user.canManageServer) { html += '
'; } html += '
'; html += '
'; $(document.body).prepend(html); $('.viewMenuBar').trigger('create'); $(document).trigger('headercreated'); bindMenuEvents(); } function bindMenuEvents() { if (AppInfo.isTouchPreferred) { $('.libraryMenuButton').on('click', function () { showLibraryMenu(false); }); $('.dashboardMenuButton').on('click', function () { showDashboardMenu(false); }); } else { $('.libraryMenuButton').createHoverTouch().on('hovertouch', showLibraryMenu); $('.dashboardMenuButton').createHoverTouch().on('hovertouch', showDashboardMenu); } // grab an element var viewMenuBar = document.getElementsByClassName("viewMenuBar")[0]; initHeadRoom(viewMenuBar); } function updateViewMenuBarHeadroom(page, viewMenuBar) { if ($(page).hasClass('libraryPage')) { viewMenuBar.removeClass('headroomDisabled'); } else { viewMenuBar.addClass('headroomDisabled'); } } function getItemHref(item, context) { return LibraryBrowser.getHref(item, context); } function getViewsHtml() { var html = ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '' + Globalize.translate('ButtonDashboard') + ''; html += '' + Globalize.translate('ButtonMetadataManager') + ''; html += '' + Globalize.translate('ButtonReports') + ''; html += '
'; html += '' + Globalize.translate('ButtonSync') + ''; return html; } function showLibraryMenu() { var page = $.mobile.activePage; var panel; ConnectionManager.user().done(function (user) { panel = getLibraryMenu(user); updateLibraryNavLinks(page); $(panel).panel('toggle').off('mouseleave.librarymenu').on('mouseleave.librarymenu', function () { $(this).panel("close"); }); }); } function showDashboardMenu() { var page = $.mobile.activePage; var panel = getDashboardMenu(page); $(panel).panel('toggle').off('mouseleave.librarymenu').on('mouseleave.librarymenu', function () { $(this).panel("close"); }); } function updateLibraryMenu(panel) { var apiClient = ConnectionManager.currentApiClient(); if (!apiClient) { $('.adminMenuOptions').hide(); $('.syncViewMenu').hide(); return; } var userId = Dashboard.getCurrentUserId(); apiClient.getUserViews(userId).done(function (result) { var items = result.Items; var html = items.map(function (i) { var iconCssClass = 'fa'; var itemId = i.Id; if (i.CollectionType == "channels") { itemId = "channels"; } else if (i.CollectionType == "livetv") { itemId = "livetv"; } if (i.Type == 'Channel') { } 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'; } return '' + i.Name + ''; }).join(''); var elem = $('.libraryMenuOptions').html(html); $('.sidebarLink', elem).on('click', function () { var section = $('.sectionName', this)[0]; var text = section ? section.innerHTML : this.innerHTML; $('.libraryMenuButtonText').html(text); }); }); Dashboard.getCurrentUser().done(function (user) { if (user.Policy.IsAdministrator) { $('.adminMenuOptions').show(); } else { $('.adminMenuOptions').hide(); } if (user.Policy.EnableSync) { $('.syncViewMenu').show(); } else { $('.syncViewMenu').hide(); } }); } var requiresLibraryMenuRefresh = false; function getLibraryMenu(user) { var panel = $('#libraryPanel'); if (!panel.length) { var html = ''; html += '
'; html += ''; html += '
'; $(document.body).append(html); panel = $('#libraryPanel').panel({}).trigger('create'); updateLibraryMenu(); } else if (requiresLibraryMenuRefresh) { updateLibraryMenu(); requiresLibraryMenuRefresh = false; } return panel; } function getDashboardMenu(page) { var panel = $('#dashboardPanel', page); if (!panel.length) { var html = ''; html += '
'; html += '
'; html += '
'; html += '
'; $(document.body).append(html); panel = $('#dashboardPanel').panel({}).trigger('create'); } return panel; } function setLibraryMenuText(text) { $('.libraryMenuButtonText').html('' + text + ''); } function getTopParentId() { return getParameterByName('topParentId') /*|| sessionStore.getItem('topParentId')*/ || null; } window.LibraryMenu = { showLibraryMenu: showLibraryMenu, getTopParentId: getTopParentId, setText: setLibraryMenuText }; function updateCastIcon() { var info = MediaController.getPlayerInfo(); if (info.isLocalPlayer) { $('.btnCast').addClass('btnDefaultCast').removeClass('btnActiveCast'); $('.headerSelectedPlayer').html(''); } else { $('.btnCast').removeClass('btnDefaultCast').addClass('btnActiveCast'); $('.headerSelectedPlayer').html((info.deviceName || info.name)); } } function updateLibraryNavLinks(page) { page = $(page); var isLiveTvPage = page.hasClass('liveTvPage'); var isChannelsPage = page.hasClass('channelsPage'); var isEditorPage = page.hasClass('metadataEditorPage'); var isReportsPage = page.hasClass('reportsPage'); var isMySyncPage = page.hasClass('mySyncPage'); var id = isLiveTvPage || isChannelsPage || isEditorPage || isReportsPage || isMySyncPage || page.hasClass('allLibraryPage') ? '' : getTopParentId() || ''; $('.lnkMediaFolder').each(function () { var itemId = this.getAttribute('data-itemid'); if (isChannelsPage && itemId == 'channels') { $(this).addClass('selectedMediaFolder'); } else if (isLiveTvPage && itemId == 'livetv') { $(this).addClass('selectedMediaFolder'); } else if (isEditorPage && itemId == 'editor') { $(this).addClass('selectedMediaFolder'); } else if (isReportsPage && itemId == 'reports') { $(this).addClass('selectedMediaFolder'); } else if (isMySyncPage && itemId == 'mysync') { $(this).addClass('selectedMediaFolder'); } else if (id && itemId == id) { $(this).addClass('selectedMediaFolder'); } else { $(this).removeClass('selectedMediaFolder'); } }); var context = getParameterByName('context'); if (context !== 'playlists') { $('.scopedLibraryViewNav a', page).each(function () { var src = this.href; if (src.indexOf('#') != -1) { return; } src = replaceQueryString(src, 'topParentId', id); this.href = src; }); } } function updateContextText(page) { var name = page.getAttribute('data-contextname'); if (name) { $('.libraryMenuButtonText').html('' + name + ''); } //else if ($(page).hasClass('type-interior')) { // $('.libraryMenuButtonText').html('' + 'Dashboard' + ''); //} else if ($(page).hasClass('allLibraryPage') || $(page).hasClass('type-interior')) { $('.libraryMenuButtonText').html('EMBY'); } } function onWebSocketMessage(e, data) { var msg = data; if (msg.MessageType === "UserConfigurationUpdated") { if (msg.Data.Id == Dashboard.getCurrentUserId()) { requiresLibraryMenuRefresh = true; } } } $(document).on('pageinit', ".page", function () { var page = this; $('.libraryViewNav', page).wrapInner('
'); $('.libraryViewNav a', page).each(function () { this.innerHTML = '' + this.innerHTML + ''; }); }).on('pagebeforeshow', ".page:not(.standalonePage)", function () { var page = this; var viewMenuBar = $('.viewMenuBar'); if (!$('.viewMenuBar').length) { ConnectionManager.user().done(function (user) { renderHeader(user); updateViewMenuBarHeadroom(page, $('.viewMenuBar')); updateCastIcon(); updateLibraryNavLinks(page); updateContextText(page); }); } else { updateContextText(page); updateLibraryNavLinks(page); updateViewMenuBarHeadroom(page, viewMenuBar); } var jpage = $(page); if (jpage.hasClass('libraryPage')) { $(document.body).addClass('libraryDocument').removeClass('dashboardDocument'); } else if (jpage.hasClass('type-interior')) { $(document.body).addClass('dashboardDocument').removeClass('libraryDocument'); } else { $(document.body).removeClass('dashboardDocument').removeClass('libraryDocument'); } }).on('pagebeforeshow', ".libraryPage", function () { var page = this; if (AppInfo.enableBottomTabs) { $('.libraryViewNav', page).addClass('bottomLibraryViewNav'); $(page).addClass('noSecondaryNavPage'); } else { $('.libraryViewNav', page).each(function () { initHeadRoom(this); }); } }).on('pageshow', ".libraryPage", function () { var page = this; var elem = $('.libraryViewNavInner .ui-btn-active:visible', page); if (elem.length) { elem[0].scrollIntoView(); // Scroll back up so in case vertical scroll was messed with $(document).scrollTop(0); } }); function initHeadRoom(elem) { if (!AppInfo.enableHeadRoom) { return; } // construct an instance of Headroom, passing the element var headroom = new Headroom(elem); // initialise headroom.init(); } function initializeApiClient(apiClient) { $(apiClient).off('websocketmessage.librarymenu', onWebSocketMessage).on('websocketmessage.librarymenu', onWebSocketMessage); } $(ConnectionManager).on('apiclientcreated', function (e, apiClient) { initializeApiClient(apiClient); }); $(function () { $(MediaController).on('playerchange', function () { updateCastIcon(); }); }); })(window, document, jQuery, window.devicePixelRatio); $.fn.createHoverTouch = function () { var preventHover = false; var timerId; function startTimer(elem) { stopTimer(); timerId = setTimeout(function () { $(elem).trigger('hovertouch'); }, 300); } function stopTimer(elem) { if (timerId) { clearTimeout(timerId); timerId = null; } } return $(this).on('mouseenter', function () { if (preventHover === true) { preventHover = false; return; } startTimer(this); }).on('mouseleave', function () { stopTimer(this); }).on('touchstart', function () { preventHover = true; }).on('click', function () { preventHover = true; if (preventHover) { $(this).trigger('hovertouch'); stopTimer(this); preventHover = false; } }); };