diff mbox

[Branch,~linaro-validation/lava-server/trunk] Rev 293: Fix the menu and sub-menu pop-up sizing behavior.

Message ID 20111129093714.13982.29715.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Zygmunt Krynicki Nov. 29, 2011, 9:37 a.m. UTC
------------------------------------------------------------
revno: 293
committer: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
branch nick: lava-server
timestamp: Fri 2011-11-18 15:53:14 +0100
message:
  Fix the menu and sub-menu pop-up sizing behavior.
  
  Apart from properly taking into account for the width of the border don't force
  the width to something that would not fit the contents anyway. Simplify and
  document the algorithm and reasoning.
modified:
  lava_server/templates/layouts/content.html


--
lp:lava-server
https://code.launchpad.net/~linaro-validation/lava-server/trunk

You are subscribed to branch lp:lava-server.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-server/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_server/templates/layouts/content.html'
--- lava_server/templates/layouts/content.html	2011-11-18 13:57:11 +0000
+++ lava_server/templates/layouts/content.html	2011-11-18 14:53:14 +0000
@@ -137,6 +137,11 @@ 
           // the default link action from firing
           event.preventDefault();
 
+          // Find the sub menu 
+          var self = $(this);
+          current_menu = self;
+          current_sub_menu = self.next(".lava-panel-menu");
+          
           // The top absolute position of the menu.
           // Defaults to the bottom border of the panel
           // with the border size (2px) substracted to make
@@ -145,35 +150,19 @@ 
 
           // The left absolute position of the menu.
           // defaults to the offset of the indicator span
-          var _left = $(this).offset().left
-
-          // Check how much horizontal space we have so that the menu
-          // does not resize the page. The idea is to get the width of
-          // the panel and remove the left offset of the indicator box.
-          // If the box would be squeezed (smaller than minimum size) then
-          // let's keep the size to minimum and move the left offset
-          // to compensate;
-          var avail_width = $("#lava-panel").outerWidth(true) - $(this).offset().left;
-
-          var orig_width = $(this).next(".lava-panel-menu").width();
-          var menu_width = $(this).outerWidth(false);
-          var sub_menu_width = $(this).next(".lava-panel-menu").outerWidth(true);
-          var _width = menu_width - 4;
-
-          // Center the sub-menu if it is wider than the menu itself
-          if (sub_menu_width > menu_width) {
-            _left -= (sub_menu_width - menu_width) / 2;
-            _width = sub_menu_width;
-          }
-          // Relocate the sub-menu if we ran out of space
-          if (_width > avail_width) {
-            _width = sub_menu_width; 
-            _left = $("#lava-panel").outerWidth(true) - sub_menu_width - 4;
-          }
-          // Show the sub menu 
-          var self = $(this);
-          current_menu = self;
-          current_sub_menu = self.next(".lava-panel-menu");
+          var _left = $(this).offset().left;
+
+          // Same with the right menu, the right margin
+          var _width = $(this).width();
+
+          // Adjust the width to consider the border of the pop-up menu.
+          var width_adj = current_sub_menu.outerWidth() - current_sub_menu.width();
+          _width -= width_adj;
+
+          // Don't set the width if it would make the menu too short.
+          if (_width < current_sub_menu.width()) {
+            _width = null;
+          }
 
           // Add an 'active' class to the current menu, this showes up as a nice gradient
           current_menu