Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

52 строки
1.8 KiB

  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'domReady!'
  8. ], function ($) {
  9. 'use strict';
  10. /* Form with auto submit feature */
  11. $('form[data-auto-submit="true"]').trigger('submit');
  12. //Add form keys.
  13. $(document).on(
  14. 'submit',
  15. 'form',
  16. function (e) {
  17. var formKeyElement,
  18. existingFormKeyElement,
  19. isKeyPresentInForm,
  20. isActionExternal,
  21. baseUrl = window.BASE_URL,
  22. form = $(e.target),
  23. formKey = $('input[name="form_key"]').val(),
  24. formMethod = form.prop('method'),
  25. formAction = form.prop('action');
  26. isActionExternal = formAction.indexOf(baseUrl) !== 0;
  27. existingFormKeyElement = form.find('input[name="form_key"]');
  28. isKeyPresentInForm = existingFormKeyElement.length;
  29. /* Verifies that existing auto-added form key is a direct form child element,
  30. protection from a case when one form contains another form. */
  31. if (isKeyPresentInForm && existingFormKeyElement.attr('auto-added-form-key') === '1') {
  32. isKeyPresentInForm = form.find('> input[name="form_key"]').length;
  33. }
  34. if (formKey && !isKeyPresentInForm && !isActionExternal && formMethod !== 'get') {
  35. formKeyElement = document.createElement('input');
  36. formKeyElement.setAttribute('type', 'hidden');
  37. formKeyElement.setAttribute('name', 'form_key');
  38. formKeyElement.setAttribute('value', formKey);
  39. formKeyElement.setAttribute('auto-added-form-key', '1');
  40. form.get(0).appendChild(formKeyElement);
  41. }
  42. }
  43. );
  44. });