1(function() { 2 'use strict'; 3 4 if (!!window.JCCatalogSectionComponent) 5 return; 6 7 window.JCCatalogSectionComponent = function(params) { 8 this.formPosting = false; 9 this.siteId = params.siteId || ''; 10 this.ajaxId = params.ajaxId || ''; 11 this.template = params.template || ''; 12 this.componentPath = params.componentPath || ''; 13 this.parameters = params.parameters || ''; 14 15 if (params.navParams) { 16 this.navParams = { 17 NavNum: params.navParams.NavNum || 1, 18 NavPageNomer: parseInt(params.navParams.NavPageNomer) || 1, 19 NavPageCount: parseInt(params.navParams.NavPageCount) || 1 20 }; 21 } 22 23 this.bigData = params.bigData || {enabled: false}; 24 this.container = document.querySelector('[data-entity="' + params.container + '"]'); 25 this.showMoreButton = null; 26 this.showMoreButtonMessage = null; 27 28 if (this.bigData.enabled && BX.util.object_keys(this.bigData.rows).length > 0) { 29 BX.cookie_prefix = this.bigData.js.cookiePrefix || ''; 30 BX.cookie_domain = this.bigData.js.cookieDomain || ''; 31 BX.current_server_time = this.bigData.js.serverTime; 32 33 BX.ready(BX.delegate(this.bigDataLoad, this)); 34 } 35 36 if (params.initiallyShowHeader) { 37 BX.ready(BX.delegate(this.showHeader, this)); 38 } 39 40 if (params.deferredLoad) { 41 BX.ready(BX.delegate(this.deferredLoad, this)); 42 } 43 44 if (params.lazyLoad) { 45 this.showMoreButton = document.querySelector('[data-use="show-more-' + this.navParams.NavNum + '"]'); 46 this.showMoreButtonMessage = this.showMoreButton.innerHTML; 47 BX.bind(this.showMoreButton, 'click', BX.proxy(this.showMore, this)); 48 } 49 50 if (params.loadOnScroll) { 51 BX.bind(window, 'scroll', BX.proxy(this.loadOnScroll, this)); 52 } 53 }; 54 55 window.JCCatalogSectionComponent.prototype = 56 { 57 checkButton: function() { 58 if (this.showMoreButton) { 59 if (this.navParams.NavPageNomer == this.navParams.NavPageCount) { 60 BX.remove(this.showMoreButton); 61 } else { 62 this.container.appendChild(this.showMoreButton); 63 } 64 } 65 }, 66 67 enableButton: function() { 68 if (this.showMoreButton) { 69 BX.removeClass(this.showMoreButton, 'disabled'); 70 this.showMoreButton.innerHTML = this.showMoreButtonMessage; 71 } 72 }, 73 74 disableButton: function() { 75 if (this.showMoreButton) { 76 BX.addClass(this.showMoreButton, 'disabled'); 77 this.showMoreButton.innerHTML = BX.message('BTN_MESSAGE_LAZY_LOAD_WAITER'); 78 } 79 }, 80 81 loadOnScroll: function() { 82 var scrollTop = BX.GetWindowScrollPos().scrollTop, 83 containerBottom = BX.pos(this.container).bottom; 84 85 if (scrollTop + window.innerHeight > containerBottom) { 86 this.showMore(); 87 } 88 }, 89 90 showMore: function() { 91 if (this.navParams.NavPageNomer < this.navParams.NavPageCount) { 92 var data = {}; 93 data['action'] = 'showMore'; 94 data['PAGEN_' + this.navParams.NavNum] = this.navParams.NavPageNomer + 1; 95 96 if (!this.formPosting) { 97 this.formPosting = true; 98 this.disableButton(); 99 this.sendRequest(data); 100 } 101 } 102 }, 103 104 bigDataLoad: function() { 105 var url = 'https://analytics.bitrix.info/crecoms/v1_0/recoms.php',
106 data = BX.ajax.prepareData(this.bigData.params); 107 108 if (data) { 109 url += (url.indexOf('?') !== -1 ? '&' : '?') + data; 110 } 111 112 var onReady = BX.delegate(function(result) { 113 this.sendRequest({ 114 action: 'deferredLoad', 115 bigData: 'Y', 116 items: result && result.items || [], 117 rid: result && result.id, 118 count: this.bigData.count, 119 rowsRange: this.bigData.rowsRange, 120 shownIds: this.bigData.shownIds 121 }); 122 }, this); 123 124 BX.ajax({ 125 method: 'GET', 126 dataType: 'json', 127 url: url, 128 timeout: 3, 129 onsuccess: onReady, 130 onfailure: onReady 131 }); 132 }, 133 134 deferredLoad: function() { 135 this.sendRequest({action: 'deferredLoad'}); 136 }, 137 138 sendRequest: function(data) { 139 var defaultData = { 140 siteId: this.siteId, 141 template: this.template, 142 parameters: this.parameters 143 }; 144 145 if (this.ajaxId) { 146 defaultData.AJAX_ID = this.ajaxId; 147 } 148 149 BX.ajax({ 150 url: this.componentPath + '/ajax.php' + (document.location.href.indexOf('clear_cache=Y') !== -1 ? '?clear_cache=Y' : ''), 151 method: 'POST', 152 dataType: 'json', 153 timeout: 60, 154 data: BX.merge(defaultData, data), 155 onsuccess: BX.delegate(function(result) { 156 if (!result || !result.JS) 157 return; 158 159 BX.ajax.processScripts( 160 BX.processHTML(result.JS).SCRIPT, 161 false, 162 BX.delegate(function() { 163 this.showAction(result, data); 164 }, this) 165 ); 166 }, this) 167 }); 168 }, 169 170 showAction: function(result, data) { 171 if (!data) 172 return; 173 174 switch (data.action) { 175 case 'showMore': 176 this.processShowMoreAction(result); 177 break; 178 case 'deferredLoad': 179 this.processDeferredLoadAction(result, data.bigData === 'Y'); 180 break; 181 } 182 }, 183 184 processShowMoreAction: function(result) { 185 this.formPosting = false; 186 this.enableButton(); 187 188 if (result) { 189 this.navParams.NavPageNomer++; 190 this.processItems(result.items); 191 this.processPagination(result.pagination); 192 this.processEpilogue(result.epilogue); 193 this.checkButton(); 194 } 195 }, 196 197 processDeferredLoadAction: function(result, bigData) { 198 if (!result) 199 return; 200 201 var position = bigData ? this.bigData.rows : {}; 202 203 this.processItems(result.items, BX.util.array_keys(position)); 204 }, 205 206 processItems: function(itemsHtml, position) { 207 if (!itemsHtml) 208 return; 209 210 var processed = BX.processHTML(itemsHtml, false), 211 temporaryNode = BX.create('DIV'); 212 213 var items, k, origRows; 214 215 temporaryNode.innerHTML = processed.HTML; 216 items = temporaryNode.querySelectorAll('[data-entity="items-row"]'); 217 218 if (items.length) { 219 this.showHeader(true); 220 221 for (k in items) { 222 if (items.hasOwnProperty(k)) { 223 origRows = position ? this.container.querySelectorAll('[data-entity="items-row"]') : false;
224 items[k].style.opacity = 0; 225 226 if (origRows && BX.type.isDomNode(origRows[position[k]])) { 227 origRows[position[k]].parentNode.insertBefore(items[k], origRows[position[k]]); 228 } else { 229 this.container.appendChild(items[k]); 230 } 231 } 232 } 233 234 new BX.easing({ 235 duration: 2000, 236 start: {opacity: 0}, 237 finish: {opacity: 100}, 238 transition: BX.easing.makeEaseOut(BX.easing.transitions.quad), 239 step: function(state) { 240 for (var k in items) { 241 if (items.hasOwnProperty(k)) { 242 items[k].style.opacity = state.opacity / 100; 243 } 244 } 245 }, 246 complete: function() { 247 for (var k in items) { 248 if (items.hasOwnProperty(k)) { 249 items[k].removeAttribute('style'); 250 } 251 } 252 } 253 }).animate(); 254 } 255 256 BX.ajax.processScripts(processed.SCRIPT); 257 }, 258 259 processPagination: function(paginationHtml) { 260 if (!paginationHtml) 261 return; 262 263 var pagination = document.querySelectorAll('[data-pagination-num="' + this.navParams.NavNum + '"]'); 264 for (var k in pagination) { 265 if (pagination.hasOwnProperty(k)) { 266 pagination[k].innerHTML = paginationHtml; 267 } 268 } 269 }, 270 271 processEpilogue: function(epilogueHtml) { 272 if (!epilogueHtml) 273 return; 274 275 var processed = BX.processHTML(epilogueHtml, false); 276 BX.ajax.processScripts(processed.SCRIPT); 277 }, 278 279 showHeader: function(animate) { 280 var parentNode = BX.findParent(this.container, {attr: {'data-entity': 'parent-container'}}), 281 header; 282 283 if (parentNode && BX.type.isDomNode(parentNode)) { 284 header = parentNode.querySelector('[data-entity="header"]'); 285 286 if (header && header.getAttribute('data-showed') != 'true') { 287 header.style.display = ''; 288 289 if (animate) { 290 new BX.easing({ 291 duration: 2000, 292 start: {opacity: 0}, 293 finish: {opacity: 100}, 294 transition: BX.easing.makeEaseOut(BX.easing.transitions.quad), 295 step: function(state) { 296 header.style.opacity = state.opacity / 100; 297 }, 298 complete: function() { 299 header.removeAttribute('style'); 300 header.setAttribute('data-showed', 'true'); 301 } 302 }).animate(); 303 } else { 304 header.style.opacity = 100; 305 } 306 } 307 } 308 } 309 }; 310})();
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.