1;(function () { 2 SotbitSmartSearchSelect = function (params) { 3 this.wrap = document.getElementById(params.wrap); 4 this.btnAdd = this.wrap.querySelector('[data-type="add"]'); 5 this.input = this.wrap.querySelector('[data-type="input"]'); 6 this.items = params.items || []; 7 this.inputName = params.inputName || 'searchselect'; 8 this.onBeforeAdd = params.onBeforeAdd || null; 9 10 return this; 11 } 12 13 SotbitSmartSearchSelect.prototype = { 14 init: function () { 15 this.createItemsWrap(); 16 this.initAdd(); 17 this.renderItems(); 18 return this; 19 }, 20 21 createItemsWrap: function () { 22 this.itemsWrap = BX.create('DIV', {props: {className: 'smartselect-items-wrap'}}); 23 this.wrap.appendChild(this.itemsWrap); 24 }, 25 26 initAdd: function () { 27 this.wrap.addEventListener('submit', (e) => { 28 e.preventDefault(); 29 // this.actionAdd(); 30 }) 31 32 33 if (!this.btnAdd) { 34 return; 35 } 36 37 this.btnAdd.addEventListener('click', () => { 38 this.actionAdd(); 39 }) 40 }, 41 42 actionAdd: async function (scipEvents = false) { 43 const value = this.input.value.trim(); 44 if (value.length === 0) { 45 return; 46 } 47 48 if (!scipEvents && typeof this.onBeforeAdd === 'function') { 49 const resultCallback = await (this.onBeforeAdd)(value); 50 if (resultCallback === false) { 51 return; 52 } 53 } 54 55 this.renderItem(value); 56 57 this.input.value = ''; 58 }, 59 60 renderItems: function () { 61 if (this.items.length === 0) { 62 return; 63 } 64 65 this.items.forEach(item => this.renderItem(item)); 66 }, 67 68 renderItem: function (item) { 69 const element = BX.create('span', { 70 dataset: { 71 type: 'item-value' 72 }, 73 text: item, 74 }); 75 76 element.appendChild(BX.create('input', { 77 attrs : {name : this.inputName + '[]', type: "hidden"}, 78 props : { 79 value : item 80 }, 81 events: { 82 click: this.deleteItem.bind(this) 83 }, 84 })); 85 86 element.appendChild(BX.create('i', { 87 html: "×", 88 events: { 89 click: this.deleteItem.bind(this) 90 }, 91 })); 92 93 this.itemsWrap.appendChild(element); 94 95 96 }, 97 98 deleteItem: function (e) { 99 e.target.parentNode.remove(); 100 }, 101 102 getValues: function () { 103 const items = this.itemsWrap.querySelectorAll('[data-type="item-value"]'); 104 return Array.from(items).map(item => item.firstChild.textContent); 105 } 106 } 107})();
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.