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