Loading commerce_avatax.libraries.yml +1 −2 Original line number Diff line number Diff line Loading @@ -6,9 +6,8 @@ address: - core/jquery - core/drupal - core/drupalSettings - core/jquery.once - core/once - core/drupal.dialog.ajax - core/jquery.form css: theme: css/commerce_avatax.theme.css: {} js/commerce_avatax.address.js +168 −163 Original line number Diff line number Diff line (function($, Drupal, drupalSettings) { var isValidating = false; function submitForm($form) { isValidating = false; Drupal.commerceAvatax = { isValidating: false, submitForm: function submitForm($form) { this.isValidating = false; $form.find(":input.button--primary").click(); } function getConfirmationDialog(content, title, buttons) { }, getConfirmationDialog: function getConfirmationDialog(content, title, buttons) { return Drupal.dialog($('<div class="address-suggestions">' + content + '</div>'), { title: title, dialogClass: 'address-format-modal', Loading @@ -17,23 +16,27 @@ maxWidth: "80%", draggable: false, close: function close(event) { isValidating = false; this.isValidating = false; Drupal.dialog(event.target).close(); Drupal.detachBehaviors(event.target, null, 'unload'); $(event.target).remove(); } }) }); } }; Drupal.behaviors.commerceAvatax = { attach: function attach(context) { if (!drupalSettings.commerceAvatax || !drupalSettings.commerceAvatax.address || !drupalSettings.commerceAvatax.country) { if (!drupalSettings.commerceAvatax || !drupalSettings.commerceAvatax.address || !drupalSettings.commerceAvatax.country) { return; } var $form = $('.avatax-form', context).closest('form'); $form.once('.avatax-form-processed').each(function () { $form.on('submit.commerce_avatax', function () { if (!$form.attr('id')) { return; } $(once($form.attr('id'), 'form')).on('submit.commerce_avatax', function () { var allowFormSubmit = true; // Get data from module. var address = drupalSettings.commerceAvatax.address; Loading @@ -45,8 +48,9 @@ return allowFormSubmit; } // Check if this submit handler is already performing validation and triggered again by another module. if (isValidating) { // Check if this submit handler is already performing validation and // triggered again by another module. if (Drupal.commerceAvatax.isValidating) { return false; } Loading @@ -58,12 +62,16 @@ }); } // If country code matches those which we need to validate. if (drupalSettings.commerceAvatax.countries.hasOwnProperty(address.country_code) && $('.address-format-modal').length === 0) { // Stop here if the address doesn't match countries that we're supposed // to validate. if (!drupalSettings.commerceAvatax.countries.hasOwnProperty(address.country_code) || $('.address-format-modal').length > 0) { return allowFormSubmit; } // Do not submit form automatically, we need to attempt address validation. allowFormSubmit = false; // Start validating field. isValidating = true; Drupal.commerceAvatax.isValidating = true; $.ajax({ async: true, Loading @@ -72,13 +80,19 @@ data: JSON.stringify(address), dataType: 'json', success: function success(response) { if (response.output) { if (!response.output) { // The address had no suggestions. $addressSuggestionEl.val('original'); allowFormSubmit = true; Drupal.commerceAvatax.submitForm($form); return; } var actions = [{ text: Drupal.t('Let me change the address'), class: 'button button--primary', id: 'button-again', click: function click() { isValidating = false; Drupal.commerceAvatax.isValidating = false; confirmationDialog.close(); } }, { Loading @@ -88,7 +102,7 @@ click: function click() { $addressSuggestionEl.val('original'); confirmationDialog.close(); submitForm($form); Drupal.commerceAvatax.submitForm($form); } }]; Loading @@ -111,7 +125,7 @@ $inlineForm.find('[name*="' + i + ']"]').val(response.suggestion[i]); }); confirmationDialog.close(); submitForm($form); Drupal.commerceAvatax.submitForm($form); } }, { text: Drupal.t('Use as entered'), Loading @@ -120,7 +134,7 @@ click: function click() { $addressSuggestionEl.val('original'); confirmationDialog.close(); submitForm($form); Drupal.commerceAvatax.submitForm($form); } }, { Loading @@ -128,21 +142,14 @@ class: 'button', id: 'button-again', click: function click(event) { isValidating = false; Drupal.commerceAvatax.isValidating = false; confirmationDialog.close(); } }]; } var confirmationDialog = getConfirmationDialog(response.output, Drupal.t('Confirm your shipping address'), actions); var confirmationDialog = Drupal.commerceAvatax.getConfirmationDialog(response.output, Drupal.t('Confirm your shipping address'), actions); confirmationDialog.showModal(); } else { // The address had no suggestions. $addressSuggestionEl.val('original'); allowFormSubmit = true; submitForm($form); } }, error: function error() { var actions = [{ Loading @@ -159,10 +166,10 @@ click: function click(event) { $addressSuggestionEl.val('original'); confirmationDialog.close() submitForm($form); Drupal.commerceAvatax.submitForm($form); } }]; var confirmationDialog = getConfirmationDialog( var confirmationDialog = Drupal.commerceAvatax.getConfirmationDialog( Drupal.t('We could not validate the address entered. Please check that you have entered the correct address'), Drupal.t('Confirm your shipping address'), actions Loading @@ -170,11 +177,9 @@ confirmationDialog.showModal(); }, }); } return allowFormSubmit; }); }); }, detach: function (context, settings, trigger) { Loading Loading
commerce_avatax.libraries.yml +1 −2 Original line number Diff line number Diff line Loading @@ -6,9 +6,8 @@ address: - core/jquery - core/drupal - core/drupalSettings - core/jquery.once - core/once - core/drupal.dialog.ajax - core/jquery.form css: theme: css/commerce_avatax.theme.css: {}
js/commerce_avatax.address.js +168 −163 Original line number Diff line number Diff line (function($, Drupal, drupalSettings) { var isValidating = false; function submitForm($form) { isValidating = false; Drupal.commerceAvatax = { isValidating: false, submitForm: function submitForm($form) { this.isValidating = false; $form.find(":input.button--primary").click(); } function getConfirmationDialog(content, title, buttons) { }, getConfirmationDialog: function getConfirmationDialog(content, title, buttons) { return Drupal.dialog($('<div class="address-suggestions">' + content + '</div>'), { title: title, dialogClass: 'address-format-modal', Loading @@ -17,23 +16,27 @@ maxWidth: "80%", draggable: false, close: function close(event) { isValidating = false; this.isValidating = false; Drupal.dialog(event.target).close(); Drupal.detachBehaviors(event.target, null, 'unload'); $(event.target).remove(); } }) }); } }; Drupal.behaviors.commerceAvatax = { attach: function attach(context) { if (!drupalSettings.commerceAvatax || !drupalSettings.commerceAvatax.address || !drupalSettings.commerceAvatax.country) { if (!drupalSettings.commerceAvatax || !drupalSettings.commerceAvatax.address || !drupalSettings.commerceAvatax.country) { return; } var $form = $('.avatax-form', context).closest('form'); $form.once('.avatax-form-processed').each(function () { $form.on('submit.commerce_avatax', function () { if (!$form.attr('id')) { return; } $(once($form.attr('id'), 'form')).on('submit.commerce_avatax', function () { var allowFormSubmit = true; // Get data from module. var address = drupalSettings.commerceAvatax.address; Loading @@ -45,8 +48,9 @@ return allowFormSubmit; } // Check if this submit handler is already performing validation and triggered again by another module. if (isValidating) { // Check if this submit handler is already performing validation and // triggered again by another module. if (Drupal.commerceAvatax.isValidating) { return false; } Loading @@ -58,12 +62,16 @@ }); } // If country code matches those which we need to validate. if (drupalSettings.commerceAvatax.countries.hasOwnProperty(address.country_code) && $('.address-format-modal').length === 0) { // Stop here if the address doesn't match countries that we're supposed // to validate. if (!drupalSettings.commerceAvatax.countries.hasOwnProperty(address.country_code) || $('.address-format-modal').length > 0) { return allowFormSubmit; } // Do not submit form automatically, we need to attempt address validation. allowFormSubmit = false; // Start validating field. isValidating = true; Drupal.commerceAvatax.isValidating = true; $.ajax({ async: true, Loading @@ -72,13 +80,19 @@ data: JSON.stringify(address), dataType: 'json', success: function success(response) { if (response.output) { if (!response.output) { // The address had no suggestions. $addressSuggestionEl.val('original'); allowFormSubmit = true; Drupal.commerceAvatax.submitForm($form); return; } var actions = [{ text: Drupal.t('Let me change the address'), class: 'button button--primary', id: 'button-again', click: function click() { isValidating = false; Drupal.commerceAvatax.isValidating = false; confirmationDialog.close(); } }, { Loading @@ -88,7 +102,7 @@ click: function click() { $addressSuggestionEl.val('original'); confirmationDialog.close(); submitForm($form); Drupal.commerceAvatax.submitForm($form); } }]; Loading @@ -111,7 +125,7 @@ $inlineForm.find('[name*="' + i + ']"]').val(response.suggestion[i]); }); confirmationDialog.close(); submitForm($form); Drupal.commerceAvatax.submitForm($form); } }, { text: Drupal.t('Use as entered'), Loading @@ -120,7 +134,7 @@ click: function click() { $addressSuggestionEl.val('original'); confirmationDialog.close(); submitForm($form); Drupal.commerceAvatax.submitForm($form); } }, { Loading @@ -128,21 +142,14 @@ class: 'button', id: 'button-again', click: function click(event) { isValidating = false; Drupal.commerceAvatax.isValidating = false; confirmationDialog.close(); } }]; } var confirmationDialog = getConfirmationDialog(response.output, Drupal.t('Confirm your shipping address'), actions); var confirmationDialog = Drupal.commerceAvatax.getConfirmationDialog(response.output, Drupal.t('Confirm your shipping address'), actions); confirmationDialog.showModal(); } else { // The address had no suggestions. $addressSuggestionEl.val('original'); allowFormSubmit = true; submitForm($form); } }, error: function error() { var actions = [{ Loading @@ -159,10 +166,10 @@ click: function click(event) { $addressSuggestionEl.val('original'); confirmationDialog.close() submitForm($form); Drupal.commerceAvatax.submitForm($form); } }]; var confirmationDialog = getConfirmationDialog( var confirmationDialog = Drupal.commerceAvatax.getConfirmationDialog( Drupal.t('We could not validate the address entered. Please check that you have entered the correct address'), Drupal.t('Confirm your shipping address'), actions Loading @@ -170,11 +177,9 @@ confirmationDialog.showModal(); }, }); } return allowFormSubmit; }); }); }, detach: function (context, settings, trigger) { Loading