1var SG = SG || {}; 2SG.modules = SG.modules || {}; 3(function() { 4 SG.modules.formDataManager = SG.modules.formDataManager || { 5 init:function(){ 6 self.manageNotYetManagedFormsNotInModal(); 7 8 var mutationObserver = new MutationObserver(function(mutations) { 9 mutations.forEach(function(mutation) { 10 if (mutation.type === 'attributes' 11 && mutation.attributeName === 'class' 12 && mutation.oldValue.indexOf('active') > -1 13 ){ 14 console.log(mutation.target); 15 self.manageNotYetManagedFormsInModal(mutation.target); 16 } 17 }); 18 }); 19 document.querySelectorAll('.modalFW').forEach(function(element, index){ 20 mutationObserver.observe(element, { 21 attributes: true, 22 attributeOldValue: true, 23 characterDataOldValue: true 24 }); 25 }); 26 }, 27 manageNotYetManagedFormsNotInModal:function(){ 28 document.querySelectorAll('form:not([data-fdm="true"]):not(.modalFW form)').forEach(function(element,index){ 29 self.fillFirstAppearanceField(element); 30 self.applyFormListeners(element); 31 element.setAttribute('data-fdm','true'); 32 }); 33 }, 34 manageNotYetManagedFormsInModal:function(modal){ 35 modal.querySelectorAll('form:not([data-fdm="true"])').forEach(function(element,index){ 36 self.fillFirstAppearanceField(element); 37 self.applyFormListeners(element); 38 element.setAttribute('data-fdm','true'); 39 }); 40 }, 41 applyFormListeners:function(form){ 42 form.addEventListener('keydown',self.formKeyDownCallback); 43 form.addEventListener('keyup',self.formKeyDownCallback); 44 form.addEventListener('click',self.formKeyDownCallback); 45 }, 46 formKeyDownCallback:function(e){ 47 var form = self.getParentForm(e.target); 48 self.fillFirstInteractionField(form); 49 }, 50 fillFirstAppearanceField:function(form){ 51 var field = form.querySelector('[name="fdm[first_appearance]"]'); 52 if(field){ 53 field.value = Date.now(); 54 } 55 }, 56 fillFirstInteractionField:function(form){ 57 var firstInteractionField = form.querySelector('[name="fdm[first_interaction]"]'); 58 if(firstInteractionField 59 && 0 == firstInteractionField.value.length){ 60 firstInteractionField.value = Date.now(); 61 } 62 form.removeEventListener('keydown',self.formKeyDownCallback); 63 form.removeEventListener('keyup',self.formKeyDownCallback); 64 form.removeEventListener('click',self.formKeyDownCallback); 65 }, 66 getParentForm:function(element){ 67 if('FORM' == element.nodeName) 68 return element; 69 70 if('undefined' !== typeof element.form) 71 return element.form; 72 73 return self.getParentForm(element.parentNode); 74 } 75 } 76 var self = SG.modules.formDataManager; 77})(); 78window.onload = () => { 79 SG.modules.formDataManager.init(); 80}
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.