1(function ($, Drupal) { 2 'use strict'; 3 4 const allowedFields = [ 5 'field_lead_firstname', 6 'field_lead_lastname', 7 'field_lead_email', 8 'field_lead_company_website', 9 'field_lead_mobilephone', 10 'field_lead_job_title' 11 ]; 12 13 Drupal.behaviors.form_autofill = { 14 attach: function (context, settings) { 15 if(typeof Drupal.webform !== 'undefined' && typeof Drupal.webform.intlTelInput !== 'undefined' && typeof Drupal.webform.intlTelInput.options !== 'undefined') { 16 //Drupal.webform.intlTelInput.options.excludeCountries = ['BY', 'CU', 'ER', 'RU', 'IR', 'LY', 'KP', 'SO', 'SD', 'SS', 'SY', 'VE', 'YE', 'ZW']; 17 Drupal.webform.intlTelInput.options.onlyCountries = [ 18 'AF', 'AX', 'AL', 'DZ', 'AS', 'AD', 'AO', 'AI', 'AG', 'AR', 'AM', 'AW', 'AU', 'AT', 'AZ', 'BS', 'BH', 'BD', 19 'BB', 'BE', 'BZ', 'BJ', 'BM', 'BT', 'BO', 'BQ', 'BA', 'BW', 'BV', 'BR', 'IO', 'BN', 'BG', 'BF', 'BI', 'KH', 20 'CM', 'CA', 'CV', 'KY', 'CF', 'TD', 'CL', 'CN', 'CC', 'CO', 'KM', 'CD', 'CG', 'CK', 'CR', 'CI', 'HR', 'CU', 21 'CW', 'CY', 'CZ', 'DK', 'DJ', 'DM', 'DO', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE', 'ET', 'FK', 'FJ', 'FI', 'FR', 22 'GF', 'PF', 'GA', 'GM', 'GE', 'DE', 'GH', 'GI', 'GR', 'GL', 'GD', 'GP', 'GU', 'GT', 'GN', 'GW', 'GY', 'HT', 23 'HM', 'HN', 'HK', 'HU', 'IS', 'IN', 'ID', 'IR', 'IQ', 'IE', 'IM', 'IL', 'IT', 'JM', 'JP', 'JE', 'JO', 'KZ', 24 'KE', 'KI', 'KW', 'KG', 'LA', 'LV', 'LB', 'LS', 'LR', 'LY', 'LI', 'LT', 'LU', 'MO', 'MK', 'MG', 'MW', 'MY', 25 'MV', 'ML', 'MT', 'MH', 'MQ', 'MR', 'MU', 'MX', 'FM', 'MD', 'MC', 'MN', 'ME', 'MS', 'MA', 'MZ', 'MM', 'NA', 26 'NR', 'NP', 'NL', 'NC', 'NZ', 'NI', 'NE', 'NG', 'NU', 'NF', 'KP', 'NO', 'OM', 'PK', 'PW', 'PS', 'PA', 'PG', 27 'PY', 'PE', 'PH', 'PN', 'PL', 'PT', 'PR', 'QA', 'XK', 'RO', 'RW', 'BL', 'KN', 'LC', 'PM', 'VC', 'WS', 'SM', 28 'ST', 'SA', 'SN', 'RS', 'SC', 'SL', 'SG', 'SX', 'SK', '
28SI', 'SB', 'SO', 'ZA', 'GS', 'KR', 'SS', 'ES', 'LK', 29 'SD', 'SR', 'SJ', 'SZ', 'SE', 'CH', 'SY', 'TW', 'TJ', 'TZ', 'TH', 'TL', 'TG', 'TO', 'TT', 'TN', 'TR', 'TM', 30 'TC', 'VI', 'UG', 'UA', 'AE', 'GB', 'US', 'UM', 'UY', 'UZ', 'VU', 'VA', 'VE', 'VN', 'WF', 'EH', 'YE', 'ZM', 'ZW' 31 ]; 32 } 33 34 $('form .form-submit', context).once().bind('mousedown', function() { 35 var $form = $(this).closest('form'); 36 var $name = $form.find('input[name="field_lead_firstname"]:not(.no-autofill)'); 37 if($name.length && $name.val().trim().length) { 38 var name = $name.val().trim(); 39 var data = JSON.parse(localStorage.getItem('form_autofill')); 40 if(data === null) { 41 data = Object(); 42 } else { 43 var keys = Object.keys(data); 44 if(keys.length === 3 && keys.indexOf(name) === -1) { 45 var key = Object.keys(data).shift(); 46 delete data[key]; 47 } 48 } 49 $form.find('input[type="text"], input[type="email"], input[type="tel"], input[type="url"], select').each(function() { 50 const $this = $(this); 51 const key = $this.attr('name'); 52 if(typeof key !== 'undefined' && key !== $name.attr('name') && allowedFields.includes(key)) { 53 if(typeof data[name] === 'undefined') { 54 data[name] = Object(); 55 } 56 data[name][key] = $this.val(); 57 } 58 }); 59 localStorage.setItem('form_autofill', JSON.stringify(data)); 60 } 61 }); 62 63 $('input[name="field_lead_firstname"]:not(.no-autofill)').once().bind('blur', function() { 64 var $this = $(this); 65 var $form = $this.closest('form'); 66 var data = JSON.parse(localStorage.getItem('form_autofill')); 67 if(data !== null) { 68 var name = $this.val().trim(); 69 if(typeof data[name] !== 'undefined') { 70 $.each(data[name], function(key, value) { 71 if(allowedFields.includes(key)) { 72 var $elem = $form.find('[name="'+key+'"]'); 73 if($elem.length) { 74 if($elem.prop('tagName') === 'SELECT') { 75 if($form.find('[name="'+key+'"] option[value="'+value+'"]').length) { 76 $form.find('[name="'+key+'"]').val(value); 77 $elem.trigger('change'); 78 } 79 } else { 80 if(value.length) { 81 if(key === 'field_lead_mobilephone') { 82 $elem.intlTelInput('setNumber', value); 83 } else { 84 $form.find('[name="'+key+'"]').val(value); 85 } 86 $form.find('[name="'+key+'"]').trigger('change'); 87 $form.find('[name="'+key+'"]').closest('.form-item').addClass('focus'); 88 } 89 if($elem.attr('type') !== 'undefined' && $elem.attr('type') === 'tel' && typeof data[name]['field_lead_country'] !== 'undefined') { 90 var country = data[name]['field_lead_country']; 91 var code = $('.country-list li[data-country="'+country+'"]').data('country-code'); 92 if(code !== 'undefined') { 93 $elem.intlTelInput('setCountry', code); 94 } 95 } 96 } 97 } 98 } 99 }); 100 } 101 } 102 }); 103 104 $(document).on('focus', '.select2-selection.select2-selection--single', function(e) { 105 $(this).closest(".select2-container").siblings('select:enabled').select2('open'); 106 }); 107 $('select.select2').on('select2:closing', function (e) { 108 $(e.target).data("select2").$selection.one('focus focusin', function(e) { 109 e.stopPropagation(); 110 }); 111 }); 112 } 113 }; 114 115 const SetCountry = (TargetField) => { 116 if(!$(TargetField).hasClass('no-auto-change') || ($(TargetField).hasClass('no-auto-change') && !$(TargetField).val())) { 117 let ISO = window.ts_country.iso; 118 const tel = $(TargetField).closest('form').find('input[type="tel"][data-webform-telephone-international-initial-country]'); 119 if(window.ts_country.source === 'direct' && tel.length) { 120 ISO = tel.data('webform-telephone-international-initial-country'); 121 } 122 let CountryOption = $(TargetField).find('option[data-country-code='+ISO.toLowerCase()+']'); 123 if(CountryOption.length > 0) { 124 $(TargetField).val(CountryOption.attr('value')).trigger('change'); 125 } 126 } 127 }; 128 $(document).on('countrychange', '[name="field_lead_mobilephone"]', function() { 129 let item = $(this); 130 let val = item.parents('form').find('select[name="field_lead_country"] option[data-country-code='+item.intlTelInput('getSelectedCountryData').iso2+']').val(); 131 if(typeof val !== 'undefined') { 132 item.parents('form').find('select[name="field_lead_country"]').val(val).trigger('change'); 133 } 134 }); 135 $(document).on('click', '.iti .iti__country', function() { 136 const item = $(this); 137 let val = item.parents('form').find('select[name="field_lead_country"] option[data-country-code='+item.data('country-code')+']').val(); 138 if(typeof val !== 'undefined') { 139 item.parents('form').find('select[name="field_lead_country"]').val(val).trigger('change'); 140 } 141 }); 142 $(document).ready(function() { 143 let ObservedSelects = []; 144 145 const Observer = new MutationObserver(() => { 146 $('select[name="field_lead_country"]').each((SelectIndex, SelectItem) => { 147 if(ObservedSelects.find(i => i.isSameNode(SelectItem)) === undefined) { 148 SetCountry(SelectItem); 149 ObservedSelects.push(SelectItem); 150 } 151 }); 152 }); 153 Observer.observe(document, { attributes: false, childList: true, subtree: true }); 154 }); 155 156} (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.