From 147587da90392b78c0c4b040eebf47e5c6b36990 Mon Sep 17 00:00:00 2001 From: Florian Strohmaier Date: Fri, 17 Nov 2017 16:02:59 +0100 Subject: [PATCH] Allow to collapse/expand the sidebar via a toggle button at the bottom of the sidebar --- application/views/scripts/layout/menu.phtml | 4 + public/css/icinga/layout.less | 57 ++++++++++ public/css/icinga/menu.less | 116 ++++++++++++++++---- public/js/icinga/behavior/navigation.js | 13 ++- 4 files changed, 166 insertions(+), 24 deletions(-) diff --git a/application/views/scripts/layout/menu.phtml b/application/views/scripts/layout/menu.phtml index 5177c35de..1823f6739 100644 --- a/application/views/scripts/layout/menu.phtml +++ b/application/views/scripts/layout/menu.phtml @@ -14,3 +14,7 @@ if ($searchDashboard->search('dummy')->getPane('search')->hasDashlets()): ?> setCssClass('primary-nav')->setElementTag('nav')->setHeading(t('Navigation')); ?> + diff --git a/public/css/icinga/layout.less b/public/css/icinga/layout.less index fa08f0e06..10bae4718 100644 --- a/public/css/icinga/layout.less +++ b/public/css/icinga/layout.less @@ -235,3 +235,60 @@ html.no-js .controls > .tabs { #sidebar { z-index: 2; } + +// Collpased sidebar +#layout.sidebar-collapsed { + #header-logo { + background-image: url('../img/icinga-logo-compact.svg'); + } + + #main { + left: 3em; + } + + #sidebar { + width: 3em; + } + + #open-sidebar { + display: inline; + } + + #close-sidebar { + display: none; + } + + #menu { + .badge { + display: none; + } + + img.icon { + margin: 0 1.25em -.25em 0.25em; + font-size: 1.5em; + } + + .nav-item { + white-space: nowrap; + } + + .nav-level-1 > .nav-item i { + font-size: 1.5em; + margin-right: .5em; + } + } + + .search-input { + font-size: 1.25em; + } + + .search-reset { + display: none; + } + + .skip-links { + a, button { + width: 20em; + } + } +} diff --git a/public/css/icinga/menu.less b/public/css/icinga/menu.less index 3e898ee00..3fd0f315b 100644 --- a/public/css/icinga/menu.less +++ b/public/css/icinga/menu.less @@ -14,29 +14,43 @@ overflow: auto; } -#menu a { - &:focus { - color: @icinga-blue; - outline-offset: -3px; - } - - &:hover { - color: @icinga-blue; - text-decoration: none; - } -} - -#menu .active > a { - color: @icinga-blue; +#layout:not(.minimal-layout) #menu { + padding-bottom: 2.25em; } #menu .nav-item { vertical-align: middle; > a { - overflow: hidden; - text-overflow: ellipsis; + &:focus { + color: @icinga-blue; + outline: -3px; + } + + &:hover { + color: @icinga-blue; + text-decoration: none; + } } + + &.active { + > a { + color: @icinga-blue; + } + } +} + +#layout:not(.sidebar-collapsed) #menu .nav-item > a { + // Respect overflowing content + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +#layout.sidebar-collapsed #menu .nav-level-1 > .nav-item > a { + // Clip overflowing content + overflow: hidden; + width: 4em; } #menu .nav-level-1 > .nav-item { @@ -48,11 +62,6 @@ display: none; } - .nav-level-2 > li { - // Expand menu if active - display: block; - } - background-color: @body-bg-color; border-color: @icinga-blue; } @@ -87,6 +96,17 @@ display: block; } +#layout:not(.sidebar-collapsed) { + #menu .nav-level-1 > .nav-item { + &.active { + .nav-level-2 > li { + // Expand menu if active + display: block; + } + } + } +} + #menu img.icon { line-height: 1; margin: 0 0.2em; @@ -122,6 +142,7 @@ } // Hovered menu +#layout.sidebar-collapsed #menu .nav-level-1 > .nav-item:hover, #menu .nav-level-1 > .nav-item:not(.active):hover { > .nav-level-2 { &:before { @@ -138,8 +159,6 @@ color: @text-color-inverted; padding: @vertical-padding 0; position: fixed; - margin-left: 15.583em; - margin-top: -3.2em; width: 14em; > .nav-item { @@ -158,6 +177,22 @@ } } +#menu .nav-level-1 > .nav-item:not(.active):hover { + > .nav-level-2 { + // Position relative to parent + margin-left: 15.583em; + margin-top: -3.167em; + } +} + +#layout.sidebar-collapsed #menu .nav-level-1 > .nav-item:hover { + > .nav-level-2 { + // Position relative to parent + margin-left: 3.583em; + margin-top: -3.333em; + } +} + // Accessibility skip links .skip-links { position: relative; @@ -259,3 +294,38 @@ input[type=text].search-input { transform: none; } } + +// Toggle sidebar button +#toggle-sidebar { + // Reset button styles + background: none; + border: none; + padding: 0; + + color: @gray-light; + + position: absolute; + bottom: 0; + right: 0; + + i { + background: @body-bg-color; + border-radius: .25em 0 0 .25em; + font-size: 1.5em; + width: 2em; + } + + &:hover { + i { + color: @icinga-blue; + } + } +} + +#layout.minimal-layout #toggle-sidebar { + display: none; +} + +#open-sidebar { + display: none; +} diff --git a/public/js/icinga/behavior/navigation.js b/public/js/icinga/behavior/navigation.js index 2d0c57b2f..0a65fa3ae 100644 --- a/public/js/icinga/behavior/navigation.js +++ b/public/js/icinga/behavior/navigation.js @@ -12,6 +12,7 @@ this.on('click', '#menu tr[href]', this.linkClicked, this); this.on('rendered', '#menu', this.onRendered, this); this.on('mouseenter', '#menu .nav-level-1 > .nav-item', this.fixFlyoutPosition, this); + this.on('click', '#toggle-sidebar', this.toggleSidebar, this); /** * The DOM-Path of the active item @@ -219,6 +220,16 @@ } }; + /** + * Collapse or expand sidebar + * + * @param {Object} e Event + */ + Navigation.prototype.toggleSidebar = function(e) { + $('#layout').toggleClass('sidebar-collapsed'); + $(window).trigger('resize'); + }; + /** * Called when the history changes * @@ -255,4 +266,4 @@ Icinga.Behaviors.Navigation = Navigation; -}) (Icinga, jQuery); +})(Icinga, jQuery);