1/** 2 * Events 3 * 4 * idxSearch_beforeSubmit(e: { 5 * forwardEvent: [original event], 6 * searchForm: [form node], 7 * searchTrigger: [node which triggered submission], 8 * searchTriggerSiblings: [node of siblings] 9 * }) 10 * 11 */ 12 13if ('undefined' === typeof brainappealIndexedSearch) { 14 var brainappealIndexedSearch = {}; 15} 16if ('undefined' === typeof brainappealIndexedSearch.searchScreen) { 17 brainappealIndexedSearch.common = { 18 formSelector: '.brainappeal-indexed-search-form', 19 20 run: function () { 21 let me = brainappealIndexedSearch.common, 22 forms = document.querySelectorAll(me.formSelector), i; 23 24 me.polyfill(); 25 26 for (i = 0; i < forms.length; i++) { 27 let form = forms[i]; 28 29 // form submission 30 form.addEventListener('submit', function (e) { 31 me.submitPreProcess(this, e); 32 me.setFormSubmitting(form, e); 33 }); 34 35 // feature 'autoSubmitOnSelectorChange' 36 if (me.enabled(form, 'autoSubmitOnSelectorChange')) { 37 let autoSubmits = form.querySelectorAll('select, input[type=radio]'); 38 for (j = 0; j < autoSubmits.length; ++j) { 39 autoSubmits[j].addEventListener('change', function (e) { 40 me.submitForm(form, e); 41 }); 42 } 43 } 44 } 45 }, 46 47 submitPreProcess: function(form, e) { 48 // input.remove-before-submit: remove name and value before submission 49 let elementsWithoutValue = form.querySelectorAll('input.remove-before-submit'), j; 50 for (j = 0; j < elementsWithoutValue.length; ++j) { 51 elementsWithoutValue[j].removeAttribute("name"); 52 elementsWithoutValue[j].removeAttribute("value"); 53 } 54 }, 55 56 submitForm: function (form, e) { 57 if (!this.isFormSubmitting(form)) { 58 this.setFormSubmitting(form, e); 59 form.submit(); 60 } 61 }, 62 63 setFormSubmitting: function (form, e) { 64 if (this.enabled(form, 'submitPreventDefault')) { 65 console.log(this.getDatasetValue(form, 'submitPreventDefault')); 66 e.preventDefault(); 67 } 68 let submitter, siblings; 69 form.dataset.isSubmitting = true; 70 this.modifyCssClasses(form, form.dataset, 'submitForm'); 71 if ( 72 'undefined' !== typeof e 73 && 'undefined' !== typeof e['submitter'] 74 ) { 75 submitter = e.submitter; 76 siblings = this.getSiblings(submitter); 77 this.modifyCssClasses(submitter, form.dataset, 'submitTrigger'); 78 for (let i = 0; i < siblings.length; i++) { 79 this.modifyCssClasses(siblings[i], form.dataset, 'submitTriggerSiblings'); 80 } 81 } 82 this.fireEvent( 83 'beforeSubmit', { 84 forwardEvent: e, 85 searchTrigger: submitter, 86 searchTriggerSiblings: siblings, 87 searchForm: form 88 }, 89 form 90 ); 91 }, 92 93 isFormSubmitting: function (form) { 94 return this.enabled(form, 'isSubmitting'); 95 }, 96 97 enabled: function (form, name) { 98 let val = +this.getDatasetValue(form, name); 99 return !!val; 100 }, 101 102 getDatasetValue(form, name) { 103 if ('undefined' !== typeof form.dataset[name]) { 104 return form.dataset[name]; 105 } else { 106 return false; 107 } 108 }, 109 fireEvent: function(eventName, data, target) { 110 target.dispatchEvent( 111 new CustomEvent( 112 'idxSearch_' + eventName, data 113 ) 114 ); 115 }, 116 117 modifyCssClasses: function (element, dataset, dataName) { 118 let modify = function (postfix, element, dataset, dataName) { 119 if ( 120 'undefined' !== typeof dataset[dataName + postfix] 121 && '' !== dataset[dataName + postfix] 122 ) { 123 let i, classes = dataset[dataName + postfix].split(" "); 124 for (i = 0; i < classes.length; i++) { 125 if ('Addclass' === postfix) { 126 element.classList.add(classes[i]); 127 } else { 128 element.classList.remove(classes[i]); 129 } 130 } 131 } 132 }; 133 modify('Addclass', element, dataset, dataName); 134 modify('Removeclass', element, dataset, dataName); 135 }, 136 137 getSiblings: function (el) { 138 let siblings = []; 139 if (!el.parentNode) { 140 return siblings; 141 } 142 let sibling = el.parentNode.firstChild; 143 while (sibling) { 144 if (sibling.nodeType === 1 && sibling !== el) { 145 siblings.push(sibling); 146 } 147 sibling = sibling.nextSibling; 148 } 149 return siblings; 150 }, 151 152 polyfill: function () { 153 154 // CustomEvent 155 if (typeof window.CustomEvent === "function") return false; //If not IE 156 function CustomEvent(event, params) { 157 params = params || {bubbles: false, cancelable: false, detail: undefined}; 158 var evt = document.createEvent('CustomEvent'); 159 evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); 160 return evt; 161 } 162 163 CustomEvent.prototype = window.Event.prototype; 164 window.CustomEvent = CustomEvent; 165 } 166 } 167} 168(function (root, factory) { 169 if (typeof define === 'function' && define.amd) { 170 define(factory); 171 } else if (typeof exports === 'object') { 172 module.exports = factory(); 173 } else { 174 root.BrainappealIndexedSearchCommon = factory(); 175 } 176}(this, function () { 177 let domReady = function (e) { 178 let t = document; 179 "loading" != t.readyState ? e() : t.addEventListener ? t.addEventListener("DOMContentLoaded", e) : t.attachEvent("onreadystatechange", function () { 180 "complete" == t.readyState && e() 181 }) 182 }; 183 domReady( 184 brainappealIndexedSearch.common.run 185 ); 186}));
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.