From 254a63dcf7dcfe824eb0b7227e2cd63fac027f85 Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Tue, 3 Feb 2015 13:11:33 -0800
Subject: [PATCH] Improve collapsing sidebar

---
 app/assets/javascripts/sidebar.js.coffee      | 11 +++-
 .../stylesheets/sections/nav_sidebar.scss     | 62 +++++++------------
 app/helpers/application_helper.rb             |  8 +++
 app/views/layouts/_collapse_button.html.haml  |  4 +-
 app/views/layouts/_page.html.haml             |  4 +-
 5 files changed, 41 insertions(+), 48 deletions(-)

diff --git a/app/assets/javascripts/sidebar.js.coffee b/app/assets/javascripts/sidebar.js.coffee
index d1b165a2311..5013bcdacd0 100644
--- a/app/assets/javascripts/sidebar.js.coffee
+++ b/app/assets/javascripts/sidebar.js.coffee
@@ -27,10 +27,15 @@ $(window).resize ->
 
 $(document).on("click", '.toggle-nav-collapse', (e) ->
   e.preventDefault()
-  if $('.page-with-sidebar').hasClass('collapsed')
-    $('.page-with-sidebar').removeClass('collapsed')
+  collapsed = 'page-sidebar-collapsed'
+  expanded = 'page-sidebar-expanded'
+
+  if $('.page-with-sidebar').hasClass(collapsed)
+    $('.page-with-sidebar').removeClass(collapsed).addClass(expanded)
+    $('.toggle-nav-collapse i').removeClass('fa-angle-right').addClass('fa-angle-left')
     $.cookie("collapsed_nav", "false", { path: '/' })
   else
-    $('.page-with-sidebar').addClass('collapsed')
+    $('.page-with-sidebar').removeClass(expanded).addClass(collapsed)
+    $('.toggle-nav-collapse i').removeClass('fa-angle-left').addClass('fa-angle-right')
     $.cookie("collapsed_nav", "true", { path: '/' })
 )
diff --git a/app/assets/stylesheets/sections/nav_sidebar.scss b/app/assets/stylesheets/sections/nav_sidebar.scss
index 0c278aec3f5..b35043821da 100644
--- a/app/assets/stylesheets/sections/nav_sidebar.scss
+++ b/app/assets/stylesheets/sections/nav_sidebar.scss
@@ -1,5 +1,3 @@
-
-
 .page-with-sidebar {
   background: #F5F5F5;
 
@@ -101,16 +99,14 @@
 }
 
 @mixin expanded-sidebar {
-  .page-with-sidebar {
-    padding-left: $sidebar_width;
-  }
+  padding-left: $sidebar_width;
 
   .sidebar-wrapper {
     width: $sidebar_width;
 
     .nav-sidebar {
       margin-top: 20px;
-      position: relative;
+      position: fixed;
       top: 45px;
       width: $sidebar_width;
     }
@@ -122,9 +118,7 @@
 }
 
 @mixin folded-sidebar {
-  .page-with-sidebar {
-    padding-left: 50px;
-  }
+  padding-left: 50px;
 
   .sidebar-wrapper {
     width: 52px;
@@ -150,47 +144,33 @@
   }
 }
 
-.collapse-nav {
-  position: relative;
-  top: 50px;
-  width: 230px;
-  text-align: right;
-  padding-right: 21px;
+.collapse-nav a {
+  position: fixed;
+  bottom: 15px;
+  padding: 10px;
+  background: #DDD;
 }
 
-.page-with-sidebar.collapsed {
-
-  .collapse-nav {
-    width: 53px;
+@media (max-width: $screen-md-max) {
+  .page-sidebar-collapsed {
+    @include folded-sidebar;
   }
 
-  padding-left: 50px;
-
-  .sidebar-wrapper {
-    width: 52px;
-    overflow-x: hidden;
-
-    .nav-sidebar {
-      width: 52px;
-    }
-    
-    .nav-sidebar li a > span {
-      display: none;
-    }
+  .page-sidebar-expanded {
+    @include folded-sidebar;
   }
-}
 
-
-@media (max-width: $screen-md-max) {
-  @include folded-sidebar;
+  .collapse-nav {
+    display: none;
+  }
 }
 
 @media(min-width: $screen-md-max) {
-  @include expanded-sidebar;
-}
+  .page-sidebar-collapsed {
+    @include folded-sidebar;
+  }
 
-@media (max-width: $screen-md-max) {
-  .collapse-nav {
-    display: none;
+  .page-sidebar-expanded {
+    @include expanded-sidebar;
   }
 }
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 1fbb44ee442..e45f4650309 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -315,4 +315,12 @@ module ApplicationHelper
       profile_key_path(key)
     end
   end
+
+  def nav_sidebar_class
+    if nav_menu_collapsed?
+      "page-sidebar-collapsed"
+    else
+      "page-sidebar-expanded"
+    end
+  end
 end
diff --git a/app/views/layouts/_collapse_button.html.haml b/app/views/layouts/_collapse_button.html.haml
index 52c19f1d99d..b3b338b55bb 100644
--- a/app/views/layouts/_collapse_button.html.haml
+++ b/app/views/layouts/_collapse_button.html.haml
@@ -1,4 +1,4 @@
 - if nav_menu_collapsed?
-  = link_to icon('plus-square'), '#', class: 'toggle-nav-collapse'
+  = link_to icon('angle-right'), '#', class: 'toggle-nav-collapse'
 - else
-  = link_to icon('minus-square'), '#', class: 'toggle-nav-collapse'
+  = link_to icon('angle-left'), '#', class: 'toggle-nav-collapse'
diff --git a/app/views/layouts/_page.html.haml b/app/views/layouts/_page.html.haml
index e20aec89110..98a3d2278a3 100644
--- a/app/views/layouts/_page.html.haml
+++ b/app/views/layouts/_page.html.haml
@@ -1,10 +1,10 @@
 - if defined?(sidebar)
-  .page-with-sidebar{:class => ("collapsed" if nav_menu_collapsed?)}
+  .page-with-sidebar{ class: nav_sidebar_class }
     = render "layouts/broadcast"
     .sidebar-wrapper
       = render(sidebar)
       .collapse-nav
-        = render :partial => 'layouts/collapse_button'
+        = render partial: 'layouts/collapse_button'
     .content-wrapper
       .container-fluid
         .content
-- 
2.30.9