From 87515725961890aa6ffe19a6a43910200e8ce72d Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sat, 9 Mar 2013 23:28:21 -0500 Subject: [PATCH] VRFS-274 hide friends panel when showing search results --- app/assets/javascripts/sidebar.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/sidebar.js b/app/assets/javascripts/sidebar.js index 97a48ebd0..9f58ec25a 100644 --- a/app/assets/javascripts/sidebar.js +++ b/app/assets/javascripts/sidebar.js @@ -65,7 +65,6 @@ error: app.ajaxError }); - hidePanels(); return false; } @@ -122,7 +121,9 @@ $('div[layout=sidebar] div[user-id=' + val.id + ']').find('#btn-connect-friend').click(sendFriendRequest); $('#sidebar-search-header').show(); + hidePanels(); }); + $('#sidebar-search-results').height(getHeight() + 'px'); }, error: app.ajaxError }); @@ -130,11 +131,34 @@ } function hidePanels() { - //$('[layout-panel="expanded"]').hide(); $('[layout-panel="contents"]').hide(); $('[layout-panel="contents"]').css({"height": "1px"}); } + function getHeight() { + // TODO: refactor this - copied from layout.js + var sidebarHeight = $(context).height() - 75 - 2 * 60 + $('[layout-sidebar-expander]').height(); + var combinedHeaderHeight = $('[layout-panel="contents"]').length * 36; + var searchHeight = $('.sidebar .search').first().height(); + var expanderHeight = $('[layout-sidebar-expander]').height(); + var expandedPanelHeight = sidebarHeight - (combinedHeaderHeight + expanderHeight + searchHeight); + return expandedPanelHeight; + } + + function showFriendsPanel() { + + var $expandedPanelContents = $('[layout-id="panelFriends"] [layout-panel="contents"]'); + var expandedPanelHeight = getHeight(); + + // hide all other contents + $('[layout-panel="contents"]').hide(); + $('[layout-panel="contents"]').css({"height": "1px"}); + + // show the appropriate contens + $expandedPanelContents.show(); + $expandedPanelContents.animate({"height": expandedPanelHeight + "px"}, 400); + } + // TODO: same code is in searchResults.js - REFACTOR function sendFriendRequest(evt) { evt.stopPropagation(); @@ -161,10 +185,12 @@ emptySearchResults(); $('#search-input').val(''); $('#sidebar-search-header').hide(); + showFriendsPanel(); } function emptySearchResults() { $('#sidebar-search-results').empty(); + $('#sidebar-search-results').height('0px'); } // TODO