From fe1f1fa2fda56f4a1ad5f18241f9d05d676ff4ab Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 1 Feb 2012 22:18:02 +0000 Subject: [PATCH] smart show/hide of sidebar if it has content --- Netdisco/public/javascripts/netdisco.js | 22 ++++++++++++++++++++++ Netdisco/views/device.tt | 8 +++++++- Netdisco/views/search.tt | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Netdisco/public/javascripts/netdisco.js b/Netdisco/public/javascripts/netdisco.js index 3840d64a..e7025392 100644 --- a/Netdisco/public/javascripts/netdisco.js +++ b/Netdisco/public/javascripts/netdisco.js @@ -12,6 +12,22 @@ function do_search (event, tab) { $(this).val( $(form).find("input[name=q]").val() ); }); + // hide or show sidebars depending on previous state, + // and whether the sidebar contains any content (detected by TT) + if (has_sidebar[tab] == 0) { + $('.sidebar, #sidebar_toggle_img_out').hide(); + $('.content').css('margin-right', '10px !important'); + } + else { + if (sidebar_hidden) { + $('#sidebar_toggle_img_out').show(); + } + else { + $('.content').css('margin-right', '220px !important'); + $('.sidebar').show(); + } + } + // get the form params var query = $(form).serialize(); @@ -53,6 +69,10 @@ function do_search (event, tab) { ); } +// keep track of which tabs have a sidebar, for when switching tab +var has_sidebar = {}; +var sidebar_hidden = 0; + // the history.js plugin is great, but fires statechange at pushState // so we have these semaphpores to help avoid messing the History. @@ -121,6 +141,7 @@ $(document).ready(function() { $('.device_label_right').toggle(); } ); + sidebar_hidden = 1; } ); $('#sidebar_toggle_img_out').click( @@ -133,6 +154,7 @@ $(document).ready(function() { $(window).scrollTop(0); } ); + sidebar_hidden = 0; } ); diff --git a/Netdisco/views/device.tt b/Netdisco/views/device.tt index d9d276bd..34c3fa0d 100644 --- a/Netdisco/views/device.tt +++ b/Netdisco/views/device.tt @@ -14,7 +14,13 @@
[% FOREACH tab IN vars.tabs %] [% END %]
diff --git a/Netdisco/views/search.tt b/Netdisco/views/search.tt index 7e424211..05d76b55 100644 --- a/Netdisco/views/search.tt +++ b/Netdisco/views/search.tt @@ -16,8 +16,10 @@ [% TRY %] [% INCLUDE "sidebar/search/${tab.id}.tt" %] + [% CATCH %] + [% END %]