diff --git admin_menu.js admin_menu.js index 87432c4..3e187a6 100644 --- admin_menu.js +++ admin_menu.js @@ -47,4 +47,75 @@ $(document).ready(function() { uls.css({left: '-999em', display: 'none'}); }, 400); }); + + // If margin-top is applied, we reposition all absolute positioned elements + // as well as the background image, if set, so they don't overlap + // with us. + 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($('#admin-menu').height()); + // 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); + } + // Add the offset + vertical_position += height; + $('body').css('background-position', background_position[0] + ' ' + vertical_position + 'px'); + } + } + + // This will also adjust all other 'fixed' positioned elements accordingly so + // they don't overlap with us. + // For optimal results, this should came after other JS files. + if (Drupal.settings.admin_menu.position_fixed) { + // Extend jQuery with ':fixed' selector. + jQuery.extend(jQuery.expr[':'], { + fixed: 'jQuery(a).css("position") == "fixed"', + }); + var height = parseInt($('#admin-menu').height()); + // Offset fixed 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($(':fixed:not(#admin-menu)'), function (element) { + return !$(element).parents('#admin-menu').size(); + })).each(function () { + var top = $(this).css('top'); + if (top != 'auto' && top != 'inherit') { + $(this).css('top', (parseInt(top) + height) + 'px'); + } + }); + } });