redirect-url.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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.redirectUrl', {
  11. options: {
  12. event: 'click',
  13. url: undefined
  14. },
  15. /**
  16. * This method binds elements found in this widget.
  17. * @private
  18. */
  19. _bind: function () {
  20. var handlers = {};
  21. handlers[this.options.event] = '_onEvent';
  22. this._on(handlers);
  23. },
  24. /**
  25. * This method constructs a new widget.
  26. * @private
  27. */
  28. _create: function () {
  29. this._bind();
  30. },
  31. /**
  32. * This method set the url for the redirect.
  33. * @private
  34. */
  35. _onEvent: function () {
  36. if (this.options.url) {
  37. location.href = this.options.url;
  38. } else {
  39. location.href = this.element.val();
  40. }
  41. }
  42. });
  43. return $.mage.redirectUrl;
  44. });