(function (window, document, $, devicePixelRatio) { function renderHeader() { var html = '
'; html += ''; html += ''; html += ''; html += '
EMBY
'; html += '
'; html += ''; html += ''; html += '
'; html += '
'; html += ''; html += ''; html += ''; html += '
'; html += '
'; html += ''; //if (AppInfo.isNativeApp && $.browser.android) //{ // html += ''; //} if (!$.browser.mobile && !AppInfo.isTouchPreferred) { html += ''; } html += '
'; html += '
'; $(document.body).append(html); $('.viewMenuBar').lazyChildren(); $(document).trigger('headercreated'); bindMenuEvents(); } function addUserToHeader(user) { var header = $('.viewMenuBar'); if (user.localUser) { $('.btnCast', header).show(); $('.headerSearchButton', header).show(); requirejs(['voice/voice'], function () { if (VoiceInputManager.isSupported()) { $('.headerVoiceButton', header).show(); } else { $('.headerVoiceButton', header).hide(); } }); } else { $('.btnCast', header).hide(); $('.headerVoiceButton', header).hide(); $('.headerSearchButton', header).hide(); } if (user.canManageServer) { $('.dashboardEntryHeaderButton', header).show(); } else { $('.dashboardEntryHeaderButton', header).hide(); } } function bindMenuEvents() { if (AppInfo.isTouchPreferred) { $('.libraryMenuButton').on('click', showLibraryMenu); $('.dashboardMenuButton').on('click', showDashboardMenu); } else { $('.libraryMenuButton').createHoverTouch().on('hovertouch', showLibraryMenu); $('.dashboardMenuButton').createHoverTouch().on('hovertouch', showDashboardMenu); } // Have to wait for document ready here because otherwise // we may see the jQM redirect back and forth problem $(initViewMenuBarHeadroom); //$('.headerButtonViewMenu').off('click', onViewButtonClick).on('click', onViewButtonClick); } //function onViewButtonClick() { // var html = '
'; // html += '
'; // $(document.body).append(html); // var elem = $('.appViewMenuPanel').panel({}).trigger('create').panel("open").on("panelclose", function () { // $(this).off("panelclose").remove(); // }); //} function initViewMenuBarHeadroom() { // 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 += '
'; html += Globalize.translate('HeaderAdmin'); html += '
'; html += '' + Globalize.translate('ButtonMetadataManager') + ''; html += '' + Globalize.translate('ButtonReports') + ''; html += '' + Globalize.translate('ButtonServer') + ''; html += '
'; html += '
'; html += '
'; if (Dashboard.isConnectMode()) { html += '' + Globalize.translate('ButtonSelectServer') + ''; } html += '' + Globalize.translate('ButtonSignOut') + ''; html += '
'; return html; } function showLibraryMenu() { var page = $.mobile.activePage; var panel; ConnectionManager.user(window.ApiClient).done(function (user) { panel = getLibraryMenu(user); updateLibraryNavLinks(page); panel = $(panel).panel('toggle').off('mouseleave.librarymenu'); if (!AppInfo.isTouchPreferred) { panel.on('mouseleave.librarymenu', function () { $(this).panel("close"); }); } }); } function showDashboardMenu() { var page = $.mobile.activePage; var panel = getDashboardMenu(page); panel = $(panel).panel('toggle').off('mouseleave.librarymenu'); if (!AppInfo.isTouchPreferred) { panel.on('mouseleave.librarymenu', function () { $(this).panel("close"); }); } } function updateLibraryMenu(panel) { var apiClient = window.ApiClient; if (!apiClient) { $('.adminMenuOptions').hide(); $('.syncViewMenu').hide(); $('.userMenuOptions').hide(); return; } var userId = Dashboard.getCurrentUserId(); apiClient.getUserViews(userId).done(function (result) { var items = result.Items; var html = ''; html += '
'; html += Globalize.translate('HeaderMedia'); html += '
'; 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; var requiresViewMenuRefresh = false; function getLibraryMenu(user) { var panel = $('#libraryPanel'); if (!panel.length) { var html = ''; html += '
'; html += ''; html += '
'; $(document.body).append(html).trigger('libraryMenuCreated'); panel = $('#libraryPanel').panel({}).lazyChildren().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') || 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 jPage = $(page); var name = jPage.attr('data-contextname'); if (name) { $('.libraryMenuButtonText').html('' + name + ''); } else if (jPage.hasClass('allLibraryPage') || jPage.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; } } } function buildViewMenuBar(page) { if ($(page).hasClass('standalonePage')) { $('.viewMenuBar').hide(); return; } if (requiresViewMenuRefresh) { $('.viewMenuBar').remove(); } var viewMenuBar = $('.viewMenuBar').show(); if (!$('.viewMenuBar').length) { renderHeader(); updateViewMenuBarHeadroom(page, $('.viewMenuBar')); updateCastIcon(); updateLibraryNavLinks(page); updateContextText(page); requiresViewMenuRefresh = false; ConnectionManager.user(window.ApiClient).done(addUserToHeader); } else { updateContextText(page); updateLibraryNavLinks(page); updateViewMenuBarHeadroom(page, viewMenuBar); requiresViewMenuRefresh = false; } } // The first time we create the view menu bar, wait until doc ready + login validated // Otherwise we run into the jQM redirect back and forth problem var updateViewMenuBarBeforePageShow = false; $(document).on('pageinit', ".page", function () { var page = this; $(function () { onPageInitDocumentReady(page); }); }).on('pagebeforeshowready', ".page", function () { var page = this; if (updateViewMenuBarBeforePageShow) { onPageBeforeShowDocumentReady(page); } }).one('pageshowready', ".page", function () { var page = this; $(function () { onPageBeforeShowDocumentReady(page); updateViewMenuBarBeforePageShow = true; }); }).on('pageshowready', ".page", function () { var page = this; onPageShowDocumentReady(page); }); function onPageInitDocumentReady(page) { $('.libraryViewNav', page).wrapInner('
'); $('.libraryViewNav a', page).each(function () { this.innerHTML = '' + this.innerHTML + ''; }); } function onPageBeforeShowDocumentReady(page) { buildViewMenuBar(page); var jpage = $(page); var isLibraryPage = jpage.hasClass('libraryPage'); if (isLibraryPage) { $(document.body).addClass('libraryDocument').removeClass('dashboardDocument'); if (AppInfo.enableBottomTabs) { $(page).addClass('noSecondaryNavPage'); $(function () { $('.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'); } } function onPageShowDocumentReady(page) { 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; } requirejs(["thirdparty/headroom"], function () { // construct an instance of Headroom, passing the element var headroom = new Headroom(elem); // initialise headroom.init(); }); } function initializeApiClient(apiClient) { requiresLibraryMenuRefresh = true; $(apiClient).off('websocketmessage.librarymenu', onWebSocketMessage).on('websocketmessage.librarymenu', onWebSocketMessage); } Dashboard.ready(function () { if (window.ApiClient) { initializeApiClient(window.ApiClient); } $(ConnectionManager).on('apiclientcreated', function (e, apiClient) { initializeApiClient(apiClient); }).on('localusersignedin localusersignedout', function () { requiresLibraryMenuRefresh = true; requiresViewMenuRefresh = true; }); }); $(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; } }); };