diff --git admin_menu.js admin_menu.js index 26c9b30..33478f4 100644 --- admin_menu.js +++ admin_menu.js @@ -185,6 +185,56 @@ Drupal.admin.behaviors.hover = function (context, $adminMenu) { }; /** + * With margin-top applied, this will reposition all absolute elements + * accordingly as well as the background. + */ +Drupal.admin.behaviors.repositionLayout = function (context, $adminMenu) { + if (Drupal.settings.admin_menu.margin_top) { + // Extend jQuery with ':absolute' and ':relative' selectors. + jQuery.extend(jQuery.expr[':'], { + absolute: 'jQuery(a).css("position") == "absolute"', + relative: 'jQuery(a).css("position") == "relative"' + }); + + var height = parseInt($adminMenu.height()); + + // Offset every absolute positioned element with our height. + $(':absolute:not(#admin-menu)').each(function () { + if (!$(this).parents(":relative").size()) { + var top = $(this).css('top'); + if (top != 'auto' && top != 'inherit') { + $(this).css('top', (parseInt(top) + height) + 'px'); + } + } + }); + + // Offset body background with our height. + if ($('body').css('background-image')) { + var background_position = $("body").css("background-position").split(' '); + var vertical_position = background_position[1]; + // Unlikely, but if the unit is something other than px, convert it. + var unit = vertical_position.match(/^[-+]?\d+\.?\d*([a-z%]+)?$/i); + if (unit && unit[1] != 'px' && vertical_position != '0%') { + unit = unit[1]; + if (unit == '%') { + vertical_position = $('body').height() * (parseInt(vertical_position) / 100); + } + else { + // Very unlikely that we get here. + return; + } + } + else { + vertical_position = parseInt(vertical_position); + } + // Add the offset + vertical_position += height; + $('body').css('background-position', background_position[0] + ' ' + vertical_position + 'px'); + } + } +}; + +/** * @} End of "defgroup admin_behaviors". */