require-cookie.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. /**
  6. * @api
  7. */
  8. define([
  9. 'jquery',
  10. 'jquery/ui'
  11. ], function ($) {
  12. 'use strict';
  13. $.widget('mage.requireCookie', {
  14. options: {
  15. event: 'click',
  16. noCookieUrl: 'enable-cookies',
  17. triggers: ['.action.login', '.action.submit']
  18. },
  19. /**
  20. * Constructor
  21. * @private
  22. */
  23. _create: function () {
  24. this._bind();
  25. },
  26. /**
  27. * This method binds elements found in this widget.
  28. * @private
  29. */
  30. _bind: function () {
  31. var events = {};
  32. $.each(this.options.triggers, function (index, value) {
  33. events['click ' + value] = '_checkCookie';
  34. });
  35. this._on(events);
  36. },
  37. /**
  38. * This method set the url for the redirect.
  39. * @param {jQuery.Event} event
  40. * @private
  41. */
  42. _checkCookie: function (event) {
  43. if (navigator.cookieEnabled) {
  44. return;
  45. }
  46. event.preventDefault();
  47. window.location = this.options.noCookieUrl;
  48. }
  49. });
  50. return $.mage.requireCookie;
  51. });