1(function ($, Drupal) { 2 'use strict'; 3 4 /** 5 * Behavior description. 6 */ 7 let flag = false; 8 let iti = null; 9 let preferredCountries = ['us', 'ca', 'gb']; 10 let initialCountry = 'us'; 11 if(drupalSettings.path.currentLanguage === 'uk') { 12 preferredCountries = ['ua']; 13 initialCountry = 'ua'; 14 } else if(drupalSettings.path.currentLanguage === 'ru') { 15 preferredCountries = ['kz']; 16 initialCountry = 'kz'; 17 } 18 let DataSent = false; 19 20 const QueryParams = [ 21 { k: 'activity', f: 'field_lead_marketingactivity' }, 22 { k: 'utm_campaign', f: 'field_lead_utmcampaign' }, 23 { k: 'utm_medium', f: 'field_lead_utmmedium' }, 24 { k: 'utm_source', f: 'field_lead_utmsource' }, 25 { k: 'utm_content', f: 'field_lead_utmcontent' }, 26 ] 27 28 Drupal.behaviors.form_creatio = { 29 attach: function (context, settings) { 30 const bpmRef = $.cookie('bpmRef'); 31 const bpmHref = $.cookie('bpmHref'); 32 const bpmTrackingId = $.cookie('bpmTrackingId'); 33 if(typeof bpmRef !== 'undefined' && bpmRef.length) { 34 $('form input[name="field_lead_bpmref"]', context).once('form_creatio_set_value').val(bpmRef); 35 } 36 if(typeof bpmHref !== 'undefined') { 37 $('form input[name="field_lead_bpmhref"]').once('form_creatio_set_value').val(bpmHref); 38 } 39 if(typeof bpmTrackingId !== 'undefined') { 40 $('form input[name="field_lead_bpmsessionid"]').once('form_creatio_set_value').val(bpmTrackingId); 41 } 42 43 $('.form-item', context).each(function() { 44 const item = $(this); 45 if(item.find('input').length && item.find('input').val().length) { 46 item.addClass('focus'); 47 } 48 }); 49 50 $('.form-item .error').once('onceEachError').each(function() { 51 const item = $(this).closest('.form-item'); 52 const form = item.closest('form'); 53 const label = item.find('label:not(.error)').html(); 54 const messages = []; 55 const messagesError = form.find('.messages--error').length ? form.find('.messages--error') : $('.region-content > div[data-drupal-messages] .messages--error'); 56 if(messagesError.find('.messages__list').length) { 57 messagesError.find('.messages__item').each(function() { 58 const message = $(this); 59 messages[messages.length] = message.text().trim(); 60 }); 61 } else { 62 const message = messagesError.find('div[role="alert"]'); 63 message.find('h2').remove(); 64 messages[messages.length] = message.text().trim(); 65 } 66 67 if(messages.length) { 68 setInputError(messages, label, item); 69 } 70 }); 71 72 $('form input.form-tel', context).each(function() { 73 const input = $(this); 74 if(!input.closest('.iti').length) { 75 iti = window.intlTelInput(input[0], { 76 utilsScript: 'https://cdn.jsdelivr.net/gh/jackocnr/[email protected]/build/js/utils.js', 77 nationalMode: false, 78 preferredCountries: preferredCountries, 79 excludeCountries: ['BY', 'CU', 'ER', 'RU', 'IR', 'LY', 'KP', 'SO', 'SD', 'SS', 'SY', 'VE', 'YE', 'ZW'], 80 initialCountry: initialCountry 81 }); 82 } else { 83 iti = window.intlTelInputGlobals.instances[0]; 84 } 85 setTimeout(() => { 86 input.val(''); 87 }, 1); 88 }); 89 90 $('input.form-tel', context).bind('input keyup', function() { 91 const input = $(this); 92 let value = input.val(); 93 value = value.replace(/[^+()\s\-\d]+/g, ''); 94 value = value.substring(0, 1) + value.substring(1).replace(/\+/g, ''); 95 input.val(value); 96 }).bind('focus', function() { 97 const input = $(this); 98 if(!input.val().length && typeof iti.getSelectedCountryData().dialCode !== 'undefined') { 99 input.val('+'+iti.getSelectedCountryData().dialCode); 100 } 101 }).bind('open:countrydropdown', function() { 102 $(this).addClass('focus'); 103 }).bind('close:countrydropdown', function() { 104 $(this).removeClass('focus'); 105 }); 106 107 const country = $('select[name="field_lead_country"]', context); 108 if(country.length && typeof window.intlTelInputGlobals !== 'undefined') { 109 country.find('option').each(function() { 110 const option = $(this); 111 let val = option.val(); 112 if(val.length) { 113 if(val === 'USA') { 114 val = 'United States'; 115 } else if(val === 'UAE') { 116 val = 'United Arab Emirates'; 117 } 118 119 $.each(window.intlTelInputGlobals.getCountryData(), function(index, value) { 120 if(value.name.indexOf(val) > -1) { 121 option.attr('data-country-code', value.iso2); 122 option.attr('data-dial-code', value.dialCode); 123 } 124 }); 125 } 126 }); 127 } 128 129 $(document).on('click', '.iti .iti__country', function() { 130 const item = $(this); 131 let val = $('select[name="field_lead_country"] option[data-country-code="'+item.data('country-code')+'"]').val(); 132 if(typeof val !== 'undefined') { 133 $('select[name="field_lead_country"]').val(val).trigger('change'); 134 } 135 }); 136 137 $('form select').once().each((index, item) => { 138 const select = $(item); 139 const closeOnSelect = select.attr('multiple') === undefined; 140 select.select2({ 141 closeOnSelect: closeOnSelect, 142 dropdownPosition: 'below', 143 dropdownParent: select.closest('.js-form-type-select'), 144 minimumResultsForSearch: 10, 145 placeholder: null, 146 templateResult: formatState 147 }).on('select2:open', function() { 148 const $this = $(this); 149 $this.closest('.form-item').addClass('open'); 150 }).on('select2:open', function() { 151 const $this = $(this); 152 if(typeof $this.data('search') !== 'undefined' && $this.data('search') === 1) { 153 $('.select2-search').addClass('select2-search_show'); 154 } 155 $this.closest('.form-item').addClass('open'); 156 }).on('select2:close', function() { 157 const $this = $(this); 158 $this.closest('.form-item').removeClass('open'); 159 }).bind('change', function() { 160 const $this = $(this); 161 const $formItem = $this.closest('.form-item'); 162 if($this.val() === '') { 163 $formItem.removeClass('focus'); 164 } else { 165 $formItem.addClass('focus'); 166 if($this.hasClass('required')) { 167 $this.removeClass('error'); 168 } 169 } 170 171 if($this.attr('name') === 'field_lead_country' && iti !== null && flag) { 172 const inputTel = $this.closest('form').find('input.form-tel'); 173 if(inputTel.length) { 174 for(const [key, item] of Object.entries(window.intlTelInputGlobals.instances)) {
175 if(inputTel.attr('id') === item.a.id) { 176 iti = item; 177 } 178 } 179 } 180 181 let countryCode = $this.find('option:selected').data('country-code'), val; 182 const dialCode = $this.find('option:selected').data('dial-code'); 183 const input = $this.closest('form').find('input.form-tel'); 184 if(typeof countryCode === 'undefined' && typeof dialCode === 'undefined') { 185 countryCode = ''; 186 val = '+'; 187 } else { 188 if(typeof iti.getSelectedCountryData().dialCode === 'undefined') { 189 val = '+'+dialCode; 190 } else { 191 try { 192 val = input.val().replace('+'+iti.getSelectedCountryData().dialCode, '+'+dialCode); 193 } 194 catch (e) { 195 196 } 197 } 198 } 199 iti.setCountry(countryCode); 200 input.val(val); 201 } 202 203 flag = true; 204 }); 205 206 if(!select.closest('.view-filters').length && !select.closest('.views-exposed-form').length && !select.closest('.checkout').length) { 207 select.trigger('change'); 208 } 209 }); 210 211 $('form .form-type-select:has(select[multiple]) label').once('clickSelectLabel').bind('click', (e) => { 212 const el = $(e.target).closest('.form-type-select'); 213 const select2 =el.find('.select2'); 214 if(select2.length) { 215 el.toggleClass('opened'); 216 if(el.hasClass('opened')) { 217 el.find('select').select2('open'); 218 } 219 } 220 }); 221 222 $('.form-item input', context).bind('focus', function() { 223 const $this = $(this); 224 $this.closest('.form-item').addClass('focus'); 225 }).bind('blur', function() { 226 const $this = $(this); 227 if(!$this.val().length) { 228 $this.closest('.form-item').removeClass('focus'); 229 } 230 }); 231 232 $('.form-type-managed-file').each(function() { 233 const elem = $(this); 234 if(elem.find('.file').length) { 235 elem.addClass('with-file'); 236 } 237 }); 238 239 $('.webform-submission-form .form-actions .form-submit').bind('mousedown', function() { 240 if(!$(this).closest('.creatio-footer-newsletter').length) { 241 const actions = $(this).closest('.form-actions'); 242 if(!actions.find('.form-loader').length) { 243 $(this).addClass('hover'); 244 actions.append('<div class="form-loader"></div>'); 245 if(actions.closest('.ui-dialog').length && actions.closest('.ui-dialog').find('.ui-dialog-buttonset').length) { 246 actions.closest('.ui-dialog').find('.ui-dialog-buttonset').append('<div class="form-loader"></div>'); 247 } 248 } 249 } 250 }); 251 252 $('form:not(.checkout):not(.webform-submission-form) .form-actions .form-submit', context).bind('mousedown', function() { 253 if(!$(this).closest('.views-exposed-form').length) { 254 const actions = $(this).closest('.form-actions'); 255 if(!actions.find('.form-loader').length) { 256 actions.append('<div class="form-loader"></div>'); 257 } 258 } 259 }); 260 261 $('form').find('[type="tel"], [type="text"], [type="email"], textarea, select').once('formInputChange').bind('change', (e) => { 262 const el = $(e.target); 263 el.toggleClass('not-empty', !!el.val().length && el.val() !== '+'); 264 }); 265 $('form:not([id^=views-exposed-form]):not(.checkout)').find('[type="tel"], [type="text"], [type="email"], textarea, select').trigger('change'); 266 } 267 }; 268 269 $(window).on('dialog:aftercreate', function(d, e, s) { 270 const { search: SearchString } = window.location 271 if(SearchString !== '') { 272 const SearchParams = new URLSearchParams(SearchString) 273 274 let Elem = s[0] 275 if(Elem !== undefined && Elem !== null) { 276 QueryParams.map(QueryParam => { 277 const QueryVal = SearchParams.get(QueryParam.k) 278 if(typeof QueryVal === 'string' && QueryVal.length > 0) { 279 let QueryElem = $(Elem).find('form input[name="' + QueryParam.f + '"]'); 280 if (QueryElem.length) { QueryElem.attr('value', QueryVal); } 281 } 282 }) 283 } 284 } 285 }); 286 287 $(document).ajaxComplete((event, xhr, settings) => { 288 const dialog = $('.ui-dialog_creatio:not(.creatio-popup)'); 289 if(dialog.length) { 290 const text = dialog.find('.webform-submission-form .form-actions').next(); 291 if(text.hasClass('form-type-processed-text')) { 292 if(!dialog.find('.ui-dialog-buttonpane .form-type-processed-text').length) { 293 dialog.find('.ui-dialog-buttonpane').append(text[0].outerHTML); 294 } 295 text.remove(); 296 } 297 298 const pdf = dialog.find('.ts-download-pdf'); 299 if(pdf.length && !dialog.find('.ui-dialog-buttonpane .ts-link').length) { 300 const actions = dialog.find('.ui-dialog-buttonpane .form-actions'); 301 if(actions.length && !actions.find('.button').text().length) { 302 actions.remove(); 303 } 304 dialog.find('.ui-dialog-buttonpane').append(pdf.html()); 305 pdf.remove(); 306 } 307 } 308 309 // SENDING DATA TO 'dataLayer' AFTER SUBMIT SECOND-STEP OF TRIAL FORM 310 let TrialError = $('.trial .trial-message'); 311 let TrialSlider = $('.trial .trial-slider'); 312 setTimeout(() => { 313 if(window.location.pathname.includes('/trial') && !DataSent) {
314 if(TrialError.length > 0 || TrialSlider.length > 0) { 315 let ParamsObj = {}; 316 let Params = window.location.search.substr(1).split('&'); 317 Params.map(param => { 318 let Param = param.split('='); 319 ParamsObj[Param[0]] = Param[1]; 320 }); 321 322 if(ParamsObj.product !== undefined && ParamsObj.product.length > 0) { 323 let FormName = ''; 324 ParamsObj.product.includes('studio') && (FormName = 'trial_studio'); 325 ParamsObj.product.includes('sales') && (FormName = 'trial_sales'); 326 ParamsObj.product.includes('marketing') && (FormName = 'trial_marketing'); 327 ParamsObj.product.includes('service') && (FormName = 'trial_service'); 328 ParamsObj.product.includes('ent-marketing-service') && (FormName = 'trial_crm'); 329 330 dataLayer.push ({ 'event': 'send_form', 'form_name': FormName, }); 331 DataSent = true; 332 } 333 } 334 } 335 }, 500); 336 }); 337 338 function formatState(state) { 339 const desc = $(state.element).data('desc'); 340 if(typeof desc === 'undefined') { 341 return state.text; 342 } else { 343 return $('<div class="option"><div class="option__title">'+state.text+'</div><div class="option__desc">'+desc+'</div></div>'); 344 } 345 } 346 347 function setInputError(messages, label, item) { 348 if(!item.find('label.error').length) { 349 let error = ''; 350 351 messages.forEach(message => { 352 if(message.indexOf(label) > -1) { 353 error = message.replace(label, '').trim(); 354 const firstLetter = error.substring(0, 1).toUpperCase(); 355 error = firstLetter + error.substring(1); 356 } else if(!error.length && item.find('input').length && item.find('input').val().length && message.indexOf(item.find('input').val()) > -1) { 357 error = message; 358 } 359 }); 360 361 if(error.length) { 362 if(error.substring(error.length-1) === '.') { 363 error = error.substring(0, error.length-1); 364 } 365 item.append('<label class="error">'+error+'</label>'); 366 } 367 } 368 } 369 370} (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.