/* Redmine - project management software * Copyright (C) 2006-2023 Jean-Philippe Lang * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // generic layout specific responsive stuff goes here function openFlyout() { $('html').addClass('flyout-is-active'); $('#main').on('click', function(e){ e.preventDefault(); e.stopPropagation(); closeFlyout(); }); } function closeFlyout() { $('html').removeClass('flyout-is-active'); $('#wrapper').off('click'); } function isMobile() { return $('.js-flyout-menu-toggle-button').is(":visible"); } function setupFlyout() { var mobileInit = false, desktopInit = false; /* click handler for mobile menu toggle */ $('.js-flyout-menu-toggle-button').on('click', function(e) { e.preventDefault(); e.stopPropagation(); if($('html').hasClass('flyout-is-active')) { closeFlyout(); } else { openFlyout(); } }); /* bind resize handler */ $(window).resize(function() { initMenu(); }) /* menu init function for dom detaching and appending on mobile / desktop view */ function initMenu() { var _initMobileMenu = function() { /* only init mobile menu, if it hasn't been done yet */ if(!mobileInit) { $('#main-menu > ul').detach().appendTo('.js-project-menu'); $('#top-menu > ul').detach().appendTo('.js-general-menu'); $('#sidebar > *').detach().appendTo('.js-sidebar'); $('#account > ul').detach().appendTo('.js-profile-menu'); mobileInit = true; desktopInit = false; } } var _initDesktopMenu = function() { if(!desktopInit) { $('.js-project-menu > ul').detach().appendTo('#main-menu'); $('.js-general-menu > ul').detach().appendTo('#top-menu'); $('.js-sidebar > *').detach().appendTo('#sidebar'); $('.js-profile-menu > ul').detach().appendTo('#account'); desktopInit = true; mobileInit = false; } } if(isMobile()) { _initMobileMenu(); } else { _initDesktopMenu(); } } // init menu on page load initMenu(); } $(document).ready(setupFlyout);