1(($, Drupal) => { 2 Drupal.behaviors.analyticsFormLSConfirmation = { 3 attach: (context) => { 4 Drupal.analytics = Drupal?.analytics ?? {}; 5 6 Drupal.analytics.lsNewPageConfirmation = { 7 /** 8 * Init Form Confirmation using Local Storage key 9 * if the Form Confirmation Message on new page and with no form. 10 * 11 * @param {Element} form 12 * @param {Object} options 13 */ 14 init(form, options) { 15 if (options?.newPageConfirmationSettings?.lsKey) { 16 const path = window.location.pathname; 17 const lsKey = options.newPageConfirmationSettings.lsKey; 18 const formPaths = options?.newPageConfirmationSettings?.formPaths; 19 const $form = $(form); 20 const $submitButton = $form.find(options?.submitButtonSelector ?? 'input[type="submit"]'); 21 22 if (formPaths?.includes(path)) { 23 if (options?.ajax) { 24 $submitButton.on('click', () => { 25 localStorage.setItem(lsKey, '1'); 26 }); 27 } else { 28 $form.on('submit', () => { 29 localStorage.setItem(lsKey, '1'); 30 }); 31 } 32 } 33 } 34 }, 35 36 /** 37 * Check if form completed using Local Storage and Confirmation path 38 * if there are no form on Confirmation page. 39 * 40 * @param {Object} options 41 */ 42 check(options) { 43 if (options?.newPageConfirmation && options?.newPageConfirmationSettings?.lsKey) { 44 const path = window.location.pathname; 45 const lsKey = options.newPageConfirmationSettings.lsKey; 46 const confirmationPaths = options?.newPageConfirmationSettings?.confirmationPaths; 47 48 if (confirmationPaths?.includes(path) && localStorage.getItem(lsKey)) { 49 window.onload = () => { 50 $(document).trigger('form_complete', { 51 form_name: options?.formName, 52 form_type: options?.formType, 53 }); 54 } 55 localStorage.removeItem(lsKey); 56 } 57 } 58 }, 59 60 /** 61 * Delete Local Storage key. 62 * 63 * @param {Object} options 64 */ 65 deleteKey(options) { 66 const lsKey = options?.newPageConfirmationSettings?.lsKey; 67 const deleteLSKeyOnError = options?.newPageConfirmationSettings?.deleteLSKeyOnError ?? true; 68 69 if (lsKey && deleteLSKeyOnError) { 70 localStorage.removeItem(lsKey); 71 } 72 } 73 } 74 } 75 } 76})(jQuery, Drupal);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.