admin.menu.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. (function($) {
  2. Drupal.behaviors.adminToolbarMenu = {};
  3. Drupal.behaviors.adminToolbarMenu.attach = function(context) {
  4. if (jQuery().drilldown) {
  5. $('#admin-toolbar div.admin-block:has(ul.menu):not(.admin-toolbar-menu)')
  6. .addClass('admin-toolbar-menu')
  7. .each(function() {
  8. var menu = $(this);
  9. var trail = '#admin-toolbar div.admin-tab.' + $(this).attr('id').split('block-')[1] + ' span';
  10. var rootTitle = $(trail).text();
  11. if ($('a:has(span.menu-description)', menu).size() > 0) {
  12. menu.addClass('admin-toolbar-menu-hover');
  13. $('a:has(span.menu-description)', menu).hover(
  14. function() {
  15. $('<a></a>')
  16. .attr('class', $(this).attr('class'))
  17. .addClass('menu-hover')
  18. .addClass('overlay-exclude')
  19. .append($('span.menu-description', this).clone())
  20. .appendTo(menu)
  21. .show();
  22. },
  23. function() {
  24. $(menu)
  25. .children('a.menu-hover')
  26. .remove();
  27. }
  28. );
  29. }
  30. // Replace the standard trail click handler with one that only
  31. // adjusts menu if the admin tab is active. Otherwise, switch
  32. // to that admin tab.
  33. menu.bind('refresh.drilldown', function() {
  34. $(trail + ' a').unbind('click').click(function() {
  35. if ($(this).parents('div.admin-tab').is('.admin-tab-active')) {
  36. var settings = {'activeLink': $(this).data('original'), 'trail': trail};
  37. // If the clicked link does not reference the current
  38. // active menu, set it to be active.
  39. if (settings.activeLink.siblings('ul.drilldown-active-menu').size() === 0) {
  40. menu.drilldown('setActive', settings);
  41. return false;
  42. }
  43. // Otherwise, pass-through and allow the link to be clicked.
  44. return menu.drilldown('goTo', settings);
  45. }
  46. $(this).parents('div.admin-tab').click();
  47. return false;
  48. });
  49. });
  50. // Init drilldown plugin.
  51. menu.drilldown('init', {
  52. activePath: Drupal.settings.activePath,
  53. trail: trail,
  54. rootTitle: rootTitle
  55. });
  56. });
  57. }
  58. };
  59. })(jQuery);