notices.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. 'mage/cookies'
  12. ], function ($) {
  13. 'use strict';
  14. $.widget('mage.cookieNotices', {
  15. /** @inheritdoc */
  16. _create: function () {
  17. if ($.mage.cookies.get(this.options.cookieName)) {
  18. this.element.hide();
  19. } else {
  20. this.element.show();
  21. }
  22. $(this.options.cookieAllowButtonSelector).on('click', $.proxy(function () {
  23. var cookieExpires = new Date(new Date().getTime() + this.options.cookieLifetime * 1000);
  24. $.mage.cookies.set(this.options.cookieName, JSON.stringify(this.options.cookieValue), {
  25. expires: cookieExpires
  26. });
  27. if ($.mage.cookies.get(this.options.cookieName)) {
  28. this.element.hide();
  29. } else {
  30. window.location.href = this.options.noCookiesUrl;
  31. }
  32. }, this));
  33. }
  34. });
  35. return $.mage.cookieNotices;
  36. });