From 949808e839f25bc38fefd0bc8b4f125c520b28da Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 14 Jan 2015 18:03:08 +1100 Subject: [PATCH] Customising AdaptiveMenu for the admin tab panel The AdaptiveMenu was design for a menu filling the screen width. Our menu is in a skeleton structure. The new file overwrites the spree version and takes the container width as reference. --- .../assets/javascripts/jquery.adaptivemenu.js | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 vendor/assets/javascripts/jquery.adaptivemenu.js diff --git a/vendor/assets/javascripts/jquery.adaptivemenu.js b/vendor/assets/javascripts/jquery.adaptivemenu.js new file mode 100644 index 0000000000..8df8b98c65 --- /dev/null +++ b/vendor/assets/javascripts/jquery.adaptivemenu.js @@ -0,0 +1,62 @@ +/* + * Original from spree/core/vendor/assets/javascripts/jquery.adaptivemenu.js + */ + +/* + * Used for the spree admin tab bar (Orders, Products, Reports etc.). + * Using parent's width instead of window width. + */ +jQuery.fn.AdaptiveMenu = function(options){ + + var options = jQuery.extend({ + text: "More...", + accuracy:0, + 'class':null, + 'classLinckMore':null + },options); + + var menu = this; + var li = $(menu).find("li"); + + var width = 0; + var widthLi = []; + $.each( li , function(i, l){ + width += $(l).width(); + widthLi.push( width ); + }); + + var buildingMenu = function(){ + var windowWidth = $(menu.parent()).width() - options.accuracy; + for(var i = 0; i windowWidth ) + $( li[i] ).hide(); + else + $( li[i] ).show(); + } + $(menu).find('#more').remove(); + var hideLi = $(li).filter(':not(:visible)'); + var lastLi = $(li).filter(':visible').last(); + if ( hideLi.length > 0 ){ + var more = $("
  • ") + .css({"display":"inline-block","white-space":"nowrap"}) + .addClass(options.classLinckMore) + .attr({"id":"more"}) + .html(options.text) + .click(function(){$(this).find('li').toggle()}); + + var ul = $("
      ") + .css({"position":"absolute"}) + .addClass(options.klass) + .html(hideLi.clone()).prepend(lastLi.clone().hide()); + + more.append(ul); + + lastLi.hide().before(more); + } + } + + jQuery(window).resize(buildingMenu); + + jQuery(window).ready(buildingMenu); + +};