admin_toolbar.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. (function ($, Drupal) {
  2. Drupal.behaviors.adminToolbar = {
  3. attach: function (context, settings) {
  4. $('a.toolbar-icon', context).removeAttr('title');
  5. $('.toolbar-tray li.menu-item--expanded, .toolbar-tray ul li.menu-item--expanded .menu-item', context).hoverIntent({
  6. over: function () {
  7. // At the current depth, we should delete all "hover-intent" classes.
  8. // Other wise we get unwanted behaviour where menu items are expanded while already in hovering other ones.
  9. $(this).parent().find('li').removeClass('hover-intent');
  10. $(this).addClass('hover-intent');
  11. },
  12. out: function () {
  13. $(this).removeClass('hover-intent');
  14. },
  15. timeout: 250
  16. });
  17. // Make the toolbar menu navigable with keyboard.
  18. $('ul.toolbar-menu li.menu-item--expanded a', context).on('focusin', function () {
  19. $('li.menu-item--expanded', context).removeClass('hover-intent');
  20. $(this).parents('li.menu-item--expanded').addClass('hover-intent');
  21. });
  22. $('ul.toolbar-menu li.menu-item a', context).keydown(function (e) {
  23. if ((e.shiftKey && (e.keyCode || e.which) == 9)) {
  24. if ($(this).parent('.menu-item').prev().hasClass('menu-item--expanded')) {
  25. $(this).parent('.menu-item').prev().addClass('hover-intent');
  26. }
  27. }
  28. });
  29. $('.toolbar-menu:first-child > .menu-item:not(.menu-item--expanded) a, .toolbar-tab > a', context).on('focusin', function () {
  30. $('.menu-item--expanded').removeClass('hover-intent');
  31. });
  32. $('.toolbar-menu:first-child > .menu-item', context).on('hover', function () {
  33. $(this, 'a').css("background: #fff;");
  34. });
  35. $('ul:not(.toolbar-menu)', context).on({
  36. mousemove: function () {
  37. $('li.menu-item--expanded').removeClass('hover-intent');
  38. },
  39. hover: function () {
  40. $('li.menu-item--expanded').removeClass('hover-intent');
  41. }
  42. });
  43. }
  44. };
  45. })(jQuery, Drupal);