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