1window.IntecKosmosPanelMobile ??= class 2{ 3 constructor(root, data) { 4 if (root instanceof HTMLElement) 5 this.root = root; 6 7 this.data = data; 8 } 9 10 resolveStore(store, maxWaitTime = 5000) { 11 return new Promise(resolve => { 12 const startTime = Date.now(); 13 const interval = setInterval(() => { 14 if (!store.pending) { 15 resolve(); 16 clearInterval(interval); 17 } else if (Date.now() - startTime > maxWaitTime) { 18 clearInterval(interval); 19 reject(new Error('Too long...')); 20 } 21 }, 1000); 22 }); 23 } 24 25 init() { 26 const root = this.root; 27 const _ = application.libraries.load('_'); 28 const $ = application.libraries.load('$'); 29 const documentBody = $(document.body); 30 const Store = application.stores.basket.getStore(); 31 const StoreCompare = application.stores.compare.getStore(); 32 33 const panel = { 34 'area': $(window), 35 'items': this.root.querySelectorAll('[data-role="item"]'), 36 'compare': { 37 'use': this.data.compare.use, 38 'code': this.data.compare.code, 39 'key': this.data.compare.key, 40 'element': this.root.querySelector('[data-role="panel.compare"]') 41 }, 42 'basket': { 43 'use': this.data.basket, 44 'element': this.root.querySelector('[data-role="panel.basket"]'), 45 }, 46 'delay': { 47 'use': this.data.delay, 48 'element': this.root.querySelector('[data-role="panel.delayed"]'), 49 }, 50 'scroll': { 51 'content': $('[data-role="scrollbar"]', root), 52 'value': 0 53 }, 54 'getBasketCount': function (data) { 55 let result = { 56 'basket': 0, 57 'delay': 0 58 }; 59 60 _.each(data.items, function (item) { 61 if (item.basket.delay) 62 ++result.delay; 63 else 64 ++result.basket; 65 }); 66 67 return result; 68 }, 69 'setCounter': function (element, count) { 70 element.attr('data-state', count > 0 ? 'active' : 'disabled').html(count); 71 } 72 }; 73 74 if (panel.items instanceof NodeList) { 75 let fullPath = window.location.pathname + window.location.search; 76 panel.items.forEach((element) => { 77 element.parentNode.setAttribute('data-active', 'false'); 78 if (fullPath == element.getAttribute('href')) { 79 element.parentNode.setAttribute('data-active', 'true'); 80 return; 81 } 82 }); 83 } 84 85 if (this.data.scroll) { 86 panel.update = function () { 87 let scrollCurrent = panel.area.scrollTop(); 88 89 if (scrollCurrent > 100 && scrollCurrent > panel.scroll.value) { 90 $(root.firstChild).attr('data-in', false); 91 $(root.firstChild).stop().animate({ height: 0 }, 100); 92 } else { 93 $(root.firstChild).attr('data-in', true); 94 $(root.firstChild).css('height', 'auto'); 95 let targetHeight = $(root.firstChild).height(); 96 $(root.firstChild).stop().animate({ height: targetHeight }, 200); 97 } 98 99 panel.scroll.value = scrollCurrent; 100 }; 101 102 panel.area.on('scroll', _.throttle(function () { 103 if (documentBody.css('overflow') !== 'hidden') 104 panel.update(); 105 }, 150, { 106 'trailing': false, 107 'leading': true 108 })); 109 110 panel.update(); 111 } 112 113 if (panel.compare.use && panel.compare.element instanceof HTMLElement) { 114 this.resolveStore(StoreCompare).then(() => {
115 if (StoreCompare.items?.length > 0) { 116 panel.compare.element.innerHTML = StoreCompare.items?.length; 117 panel.compare.element.setAttribute("data-state", 'active'); 118 } 119 }); 120 121 StoreCompare.$onAction(({name, store, after}) => { 122 if (name !== 'doUpdate') { 123 after(() => { 124 panel.compare.element.innerHTML = store.items?.length; 125 126 if (store.items?.length > 0) 127 panel.compare.element.setAttribute("data-state", 'active'); 128 else 129 panel.compare.element.setAttribute("data-state", 'disabled'); 130 }); 131 } 132 }); 133 } 134 135 if (panel.basket.use && panel.basket.element instanceof HTMLElement) { 136 this.resolveStore(Store).then(() => { 137 if (Store.added?.length > 0) { 138 panel.basket.element.innerHTML = Store.added?.length; 139 panel.basket.element.setAttribute("data-state", 'active'); 140 } 141 }); 142 143 Store.$onAction(({ name, store, after }) => { 144 if (name !== 'doUpdate') { 145 after(() => { 146 panel.basket.element.innerHTML = store.added?.length; 147 148 if (store.added?.length > 0) 149 panel.basket.element.setAttribute("data-state", 'active'); 150 else 151 panel.basket.element.setAttribute("data-state", 'disabled'); 152 }); 153 } 154 }); 155 } 156 157 if (panel.delay.use && panel.delay.element instanceof HTMLElement) { 158 this.resolveStore(Store).then(() => { 159 if (Store.delayed?.length > 0) { 160 panel.delay.element.innerHTML = Store.delayed?.length; 161 panel.delay.element.setAttribute("data-state", 'active'); 162 } 163 }); 164 165 Store.$onAction(({ name, store, after }) => { 166 if (name !== 'doUpdate') { 167 after(() => { 168 panel.delay.element.innerHTML = store.delayed?.length; 169 170 if (Store.delayed?.length > 0) 171 panel.delay.element.setAttribute("data-state", 'active'); 172 else 173 panel.delay.element.setAttribute("data-state", 'disabled'); 174 }); 175 } 176 }); 177 } 178 } 179}
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.