diff options
author | Jacob Schatz <jschatz@gitlab.com> | 2016-06-21 17:56:21 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-06-21 18:58:05 +0300 |
commit | 61b59fea1ce2b703e4f01a415a8a066b8a879d6c (patch) | |
tree | ac44b7ef6c669e869db369e5fe875521ec92d128 /app/assets | |
parent | 1bf82c2b7fe0ec16b9d0f969db4b4dba4a5db1de (diff) |
Merge branch '18743-sidebar-pin-tooltip' into 'master'
Resolve "Tooltip for pinning sidebar"
## What does this MR do?
Adds tooltip to show whether sidebar is pinned/unpinned
## What are the relevant issue numbers?
Closes #18743
## Screenshots (if relevant)
![Screen_Shot_2016-06-17_at_12.14.25_PM](/uploads/162f52084a770012cdc621122acd6c6c/Screen_Shot_2016-06-17_at_12.14.25_PM.png)
![Screen_Shot_2016-06-17_at_12.14.35_PM](/uploads/d9296720aeada972441f48d9a3d2f7f8/Screen_Shot_2016-06-17_at_12.14.35_PM.png)
See merge request !4759
Diffstat (limited to 'app/assets')
-rw-r--r-- | app/assets/javascripts/application.js.coffee | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 4529c514555..397892d15c0 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -268,17 +268,33 @@ $ -> .on 'click', '.js-nav-pin', (e) -> e.preventDefault() + $pinBtn = $(e.currentTarget) + $page = $ '.page-with-sidebar' + $topNav = $ '.navbar-fixed-top' + $tooltip = $ "##{$pinBtn.attr('aria-describedby')}" + doPinNav = not $page.is('.page-sidebar-pinned') + tooltipText = 'Pin navigation' + $(this).toggleClass 'is-active' - if $.cookie('pin_nav') is 'true' - $.cookie 'pin_nav', 'false', { path: '/' } - $('.page-with-sidebar') - .removeClass('page-sidebar-pinned') - .toggleClass('page-sidebar-collapsed page-sidebar-expanded') - $('.navbar-fixed-top') - .removeClass('header-pinned-nav') - .toggleClass('header-collapsed header-expanded') + if doPinNav + $page.addClass('page-sidebar-pinned') + $topNav.addClass('header-pinned-nav') else - $.cookie 'pin_nav', 'true', { path: '/' } - $('.page-with-sidebar').addClass('page-sidebar-pinned') - $('.navbar-fixed-top').addClass('header-pinned-nav') + $tooltip.remove() # Remove it immediately when collapsing the sidebar + $page.removeClass('page-sidebar-pinned') + .toggleClass('page-sidebar-collapsed page-sidebar-expanded') + $topNav.removeClass('header-pinned-nav') + .toggleClass('header-collapsed header-expanded') + + # Save settings + $.cookie 'pin_nav', doPinNav, { path: '/' } + + if $.cookie('pin_nav') is 'true' or doPinNav + tooltipText = 'Unpin navigation' + + # Update tooltip text immediately + $tooltip.find('.tooltip-inner').text(tooltipText) + + # Persist tooltip title + $pinBtn.attr('title', tooltipText).tooltip('fixTitle') |