button.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. (function (factory) {
  6. 'use strict';
  7. if (typeof define === 'function' && define.amd) {
  8. define([
  9. 'jquery',
  10. 'jquery/ui'
  11. ], factory);
  12. } else {
  13. factory(jQuery);
  14. }
  15. }(function ($) {
  16. 'use strict';
  17. $.widget('ui.button', $.ui.button, {
  18. options: {
  19. eventData: {},
  20. waitTillResolved: true
  21. },
  22. /**
  23. * Button creation.
  24. * @protected
  25. */
  26. _create: function () {
  27. if (this.options.event) {
  28. this.options.target = this.options.target || this.element;
  29. this._bind();
  30. }
  31. this._super();
  32. },
  33. /**
  34. * Bind handler on button click.
  35. * @protected
  36. */
  37. _bind: function () {
  38. this.element
  39. .off('click.button')
  40. .on('click.button', $.proxy(this._click, this));
  41. },
  42. /**
  43. * Button click handler.
  44. * @protected
  45. */
  46. _click: function () {
  47. var options = this.options;
  48. $(options.target).trigger(options.event, [options.eventData]);
  49. }
  50. });
  51. return $.ui.button;
  52. }));