Guest User

Untitled

a guest
Jul 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. lib/web/mage/menu.js
  2.  
  3. this._on({
  4. /**
  5. * Prevent focus from sticking to links inside menu after clicking
  6. * them (focus should always stay on UL during navigation).
  7. */
  8. 'mousedown .ui-menu-item > a': function (event) {
  9. event.preventDefault();
  10. },
  11.  
  12. /**
  13. * Prevent focus from sticking to links inside menu after clicking
  14. * them (focus should always stay on UL during navigation).
  15. */
  16. '**click** .ui-state-disabled > a': function (event) {
  17. event.preventDefault();
  18. },
  19.  
  20. /**
  21. * @param {jQuer.Event} event
  22. */
  23. 'click .ui-menu-item:has(a)': function (event) {
  24. var target = $(event.target).closest('.ui-menu-item');
  25.  
  26. if (!this.mouseHandled && target.not('.ui-state-disabled').length) {
  27. this.select(event);
  28.  
  29. // Only set the mouseHandled flag if the event will bubble, see #9469.
  30. if (!event.isPropagationStopped()) {
  31. this.mouseHandled = true;
  32. }
  33.  
  34. // Open submenu on click
  35. if (target.has('.ui-menu').length) {
  36. this.expand(event);
  37. } else if (!this.element.is(':focus') &&
  38. $(this.document[0].activeElement).closest('.ui-menu').length
  39. ) {
  40. // Redirect focus to the menu
  41. this.element.trigger('focus', [true]);
  42.  
  43. // If the active item is on the top level, let it stay active.
  44. // Otherwise, blur the active item since it is no longer visible.
  45. if (this.active && this.active.parents('.ui-menu').length === 1) { //eslint-disable-line
  46. clearTimeout(this.timer);
  47. }
  48. }
  49. }
  50. },
  51. 'click .ui-menu-item': function (event) {
  52. var target = $(event.currentTarget),
  53. submenu = this.options.menus,
  54. ulElement,
  55. ulElementWidth,
  56. width,
  57. targetPageX,
  58. rightBound;
  59.  
  60. if (target.has(submenu)) {
  61. ulElement = target.find(submenu);
  62. ulElementWidth = ulElement.outerWidth(true);
  63. width = target.outerWidth() * 2;
  64. targetPageX = target.offset().left;
  65. rightBound = $(window).width();
  66.  
  67. if (ulElementWidth + width + targetPageX > rightBound) {
  68. ulElement.addClass('submenu-reverse');
  69. }
  70.  
  71. if (targetPageX - ulElementWidth < 0) {
  72. ulElement.removeClass('submenu-reverse');
  73. }
  74. }
  75.  
  76. // Remove ui-state-active class from siblings of the newly focused menu item
  77. // to avoid a jump caused by adjacent elements both having a class with a border
  78. target.siblings().children('.ui-state-active').removeClass('ui-state-active');
  79. this.focus(event, target);
  80. },
  81.  
  82. /**
  83. * @param {jQuery.Event} event
  84. */
  85. 'mouseleave': function (event) {
  86. this.collapseAll(event, true);
  87. },
  88.  
  89. /**
  90. * Mouse leave.
  91. */
  92. 'mouseleave .ui-menu': 'collapseAll'
  93. });
  94.  
  95. categoryParent = this.element.find('.all-category');
  96. html = $('html');
  97.  
  98. categoryParent.remove();
  99.  
  100. if (html.hasClass('nav-open')) {
  101. html.removeClass('nav-open');
  102. setTimeout(function () {
  103. html.removeClass('nav-before-open');
  104. }, 300);
  105. }
  106. }
Add Comment
Please, Sign In to add comment