1/* 2 * @file: otsuka_sfmc_preprocess.js 3 * @description: clientside javascript for parsing out query string values and storing to local storage, preprocess SFMC webform 4 */ 5 6(function ($, Drupal) { 7 'use strict'; 8 9 /** 10 * This Drupal Behavior automatically hides required or preset SFMC object 11 * fields from the webform to prevent users from changing the values. 12 **/ 13 Drupal.behaviors.OtsukaSfmcRegistrationPreprocess = { 14 attach: function (context, settings) { 15 if ($('body').find('.hidden-sfmc-value').length > 0) { 16 $('.hidden-sfmc-value').each(function () { 17 $(this).parent('.form-item').addClass('sfmc-conceal'); 18 }); 19 } 20 } 21 }; 22 23 Drupal.behaviors.OtsukaSfmcRegistrationStorage = { 24 attach: function (context, settings) { 25 if (settings.otsuka_sfmc_registration) { 26 const queryString = window.location.search; 27 const urlParams = new URLSearchParams(queryString); 28 29 // Set local storage values 30 Object.keys(settings.otsuka_sfmc_registration).forEach(function (key) { 31 var param = urlParams.get(key); 32 33 if (param !== null) { 34 window.localStorage.setItem(settings.otsuka_sfmc_registration[key], param); 35 } 36 }); 37 38 // Update input values 39 Object.keys(settings.otsuka_sfmc_registration).forEach(function (key) { 40 var value = window.localStorage.getItem(settings.otsuka_sfmc_registration[key]); 41 42 if (value !== null) { 43 $('input[name="' + settings.otsuka_sfmc_registration[key] + '"]', context).val(value); 44 } 45 }); 46 } 47 } 48 }; 49 50})(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.