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