diff --git admin_menu.js admin_menu.js index 87432c4..b90b70a 100644 --- admin_menu.js +++ admin_menu.js @@ -47,4 +47,50 @@ $(document).ready(function() { uls.css({left: '-999em', display: 'none'}); }, 400); }); + + // This requires that a margin-top is active and was added. + if (Drupal.settings.admin_menu.margin_top) { + // Extend jQuery with ':absolute' selector. + jQuery.extend(jQuery.expr[':'], { + absolute: 'jQuery(a).css("position")=="absolute"', + relative: 'jQuery(a).css("position")=="relative"' + }); + var height = parseInt($('body').css('margin-top')); + // Offset every absolute positioned element with our height. + // We also filter out all #admin-menu's children. In newer versions of + // jQuery this is as simple as .not($("#admin-menu *")) + $(jQuery.grep($(':absolute:not(#admin-menu)'), function (element) { + return !$(element).parents('#admin-menu').size(); + })).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 is the unit something other than px? + var unit = vertical_position.match(/^[-+]?\d+\.?\d*([a-z%]+)?$/i); + if (unit && unit[1] != 'px' && vertical_position != '0%') { + unit = unit[1]; + // Percentage? + if (unit == '%') { + vertical_position = $('body').height() * (parseInt(vertical_position) / 100); + } + // Very very unlikely that we get here + else { + return; + } + } + else { + vertical_position = parseInt(vertical_position); + } + vertical_position += height; + $('body').css('background-position', background_position[0] + ' ' + vertical_position + 'px'); + } + } });