action-link.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'jquery/ui'
  8. ], function ($) {
  9. 'use strict';
  10. $.widget('mage.actionLink', {
  11. /**
  12. * Button creation
  13. * @protected
  14. */
  15. _create: function () {
  16. this._bind();
  17. },
  18. /**
  19. * Bind handler on button click
  20. * @protected
  21. */
  22. _bind: function () {
  23. var keyCode = $.ui.keyCode;
  24. this._on({
  25. /**
  26. * @param {jQuery.Event} e
  27. */
  28. mousedown: function (e) {
  29. this._stopPropogation(e);
  30. },
  31. /**
  32. * @param {jQuery.Event} e
  33. */
  34. mouseup: function (e) {
  35. this._stopPropogation(e);
  36. },
  37. /**
  38. * @param {jQuery.Event} e
  39. */
  40. click: function (e) {
  41. this._stopPropogation(e);
  42. this._triggerEvent();
  43. },
  44. /**
  45. * @param {jQuery.Event} e
  46. */
  47. keydown: function (e) {
  48. switch (e.keyCode) {
  49. case keyCode.ENTER:
  50. case keyCode.NUMPAD_ENTER:
  51. this._stopPropogation(e);
  52. this._triggerEvent();
  53. break;
  54. }
  55. },
  56. /**
  57. * @param {jQuery.Event} e
  58. */
  59. keyup: function (e) {
  60. switch (e.keyCode) {
  61. case keyCode.ENTER:
  62. case keyCode.NUMPAD_ENTER:
  63. this._stopPropogation(e);
  64. break;
  65. }
  66. }
  67. });
  68. },
  69. /**
  70. * @param {Object} e - event object
  71. * @private
  72. */
  73. _stopPropogation: function (e) {
  74. e.stopImmediatePropagation();
  75. e.preventDefault();
  76. },
  77. /**
  78. * @private
  79. */
  80. _triggerEvent: function () {
  81. $(this.options.related || this.element)
  82. .trigger(this.options.event, this.options.eventData ? [this.options.eventData] : [{}]);
  83. }
  84. });
  85. return $.mage.actionLink;
  86. });