1function JCSmartFilter(ajaxURL, viewMode, params) { 2 this.ajaxURL = ajaxURL; 3 this.form = null; 4 this.timer = null; 5 this.cacheKey = ''; 6 this.cache = []; 7 this.popups = []; 8 this.viewMode = viewMode; 9 10 const urlParts = this.ajaxURL.split('filter/')[0].split('?'); 11 12 this.baseUrl = urlParts[0]; 13 this.getParams = urlParts[1]; 14 15 if (params && params.SEF_SET_FILTER_URL) { 16 params.SEF_SET_FILTER_URL = this.getCorrectUrl(params.SEF_SET_FILTER_URL); 17 this.bindUrlToButton('set_filter', params.SEF_SET_FILTER_URL); 18 //todo maytoni ÑÑи ÑÑÑлки не иÑполÑзÑеÑÑÑ, надо ÑазобÑаÑÑÑÑ Ð·Ð°Ñем они вообÑе и ÑдалиÑÑ ÐµÑли не надо 19 this.sef = true; 20 } 21 if (params && params.SEF_DEL_FILTER_URL) { 22 params.SEF_DEL_FILTER_URL = this.getCorrectUrl(params.SEF_DEL_FILTER_URL); 23 this.bindUrlToButton('del_filter', params.SEF_DEL_FILTER_URL); 24 } 25} 26 27JCSmartFilter.prototype.keyup = function (input) { 28 BX.addClass(BX('filter'), "loading"); 29 if (!!this.timer) { 30 clearTimeout(this.timer); 31 } 32 let priceMin = BX(window.filterName + '_P1_MIN').value; 33 let priceMax = BX(window.filterName + '_P1_MAX').value; 34 if (window.maxPrice == priceMax && window.minPrice == priceMin) { 35 BX(window.filterName + '_P1_MIN').setAttribute('disabled', 'disabled'); 36 BX(window.filterName + '_P1_MAX').setAttribute('disabled', 'disabled'); 37 } 38 39 this.timer = setTimeout(BX.delegate(function () { 40 this.reload(input); 41 }, this), 500); 42}; 43JCSmartFilter.prototype.deletePathUrl = function (pathUrl) { 44 45 let currentUrl = location.pathname; 46 currentUrl = currentUrl.replace(pathUrl, ''); 47 if (currentUrl.lastIndexOf('/filter/apply/') > 0) { 48 currentUrl = currentUrl.replace('filter/apply/', ''); 49 } 50 location.href = currentUrl; 51 52} 53JCSmartFilter.prototype.getCorrectUrl = function (pathUrl) { 54 if (this.getParams) { 55 return this.baseUrl + 'filter/' + pathUrl.split('/filter/')[1] + this.getParams; 56 } else { 57 return this.baseUrl + 'filter/' + pathUrl.split('/filter/')[1]; 58 } 59} 60 61JCSmartFilter.prototype.checkCusmtopRadio = function (input) { 62 let input_name = input.getAttribute("name"); 63 let inputs = document.querySelectorAll('input[name=' + input_name + ']:checked'); 64 65 if (!!this.timer) { 66 clearTimeout(this.timer); 67 } 68 let min = 0; 69 let max = 0; 70 inputs.forEach(function (item) { 71 min = item.getAttribute("data-min"); 72 max = item.getAttribute("data-max"); 73 }); 74 75 let id = input.getAttribute("data-id"); 76 BX(id + '_MIN').value = min; 77 BX(id + '_MAX').value = max; 78 79 let priceMin = BX(window.filterName + '_P1_MIN').value; 80 let priceMax = BX(window.filterName + '_P1_MAX').value; 81 if (window.maxPrice == priceMax && window.minPrice == priceMin) { 82 BX(window.filterName + '_P1_MIN').setAttribute('disabled', 'disabled'); 83 BX(window.filterName + '_P1_MAX').setAttribute('disabled', 'disabled'); 84 } 85 86 var event = new Event('change'); 87 document.querySelector('#' + id + '_MIN').dispatchEvent(event); 88 89 90}; 91 92JCSmartFilter.prototype.selectLED = function (input, LEDid) { 93 let parent = input.parentElement.parentElement; 94 parent.querySelectorAll('input').forEach(function (item) { 95 if (item.getAttribute('name') != 'checkbox-LED') 96 item.removeAttribute('checked'); 97 }); 98 document.querySelector(LEDid).click(); 99} 100 101JCSmartFilter.prototype.checkCusmtopRadioCalssIp = function (input) { 102 if (!!this.timer) { 103 clearTimeout(this.timer); 104 } 105 106 let priceMin = BX(window.filterName + '_P1_MIN').value; 107 let priceMax = BX(window.filterName + '_P1_MAX').value; 108 if (window.maxPrice == priceMax && window.minPrice == priceMin) { 109 BX(window.filterName + '_P1_MIN').setAttribute('disabled', 'disabled'); 110 BX(window.filterName + '_P1_MAX').setAttribute('disabled', 'disabled'); 111 } 112 113 let id = input.getAttribute("data-id"); 114 let ips = input.getAttribute("data-value"); 115 116 let arIps = ips.split(","); 117 118 let allCheck = document.querySelectorAll('[data-ip]'); 119 allCheck.forEach(function (check) { 120 check.removeAttribute('checked'); 121 }); 122 123 124 setTimeout(function () { 125 var event = new Event('click'); 126 arIps.forEach(function (ip) { 127 let check = document.querySelector('[data-ip="' + ip + '"]'); 128 if (check) { 129 check.click(); 130 } 131 }); 132 }, 1000); 133}; 134 135 136JCSmartFilter.prototype.click = function (checkbox) { 137 BX.addClass(BX('filter'), "loading"); 138 if (!!this.timer) { 139 clearTimeout(this.timer); 140 } 141 142 let priceMin = BX(window.filterName + '_P1_MIN').value; 143 let priceMax = BX(window.filterName + '_P1_MAX').value; 144 if (window.maxPrice == priceMax && window.minPrice == priceMin) { 145 BX(window.filterName + '_P1_MIN').setAttribute('disabled', 'disabled'); 146 BX(window.filterName + '_P1_MAX').setAttribute('disabled', 'disabled'); 147 } 148 149 this.timer = setTimeout(BX.delegate(function () { 150 this.reload(checkbox); 151 }, this), 500); 152}; 153 154JCSmartFilter.prototype.reload = function (input) { 155 if (this.cacheKey !== '') { 156 //Postprone backend query 157 if (!!this.timer) { 158 clearTimeout(this.timer); 159 } 160 this.timer = setTimeout(BX.delegate(function () { 161 this.reload(input); 162 }, this), 1000); 163 return; 164 } 165 this.cacheKey = '|'; 166 167 this.position = BX.pos(input, true); 168 this.form = BX.findParent(input, {'tag': 'form'}); 169 if (this.form) { 170 var values = []; 171 values[0] = {name: 'ajax', value: 'y'}; 172 173 this.gatherInputsValues(values, BX.findChildren(this.form, {'tag': new RegExp('^(input|select)$', 'i')}, true)); 174 175 for (var i = 0; i < values.length; i++) 176 this.cacheKey += values[i].name + ':' + values[i].value + '|'; 177 178 if (this.cache[this.cacheKey]) { 179 this.curFilterinput = input; 180 this.postHandler(this.cache[this.cacheKey], true); 181 } else { 182 if (this.sef) { 183 var set_filter = BX('set_filter'); 184 set_filter.disabled = true; 185 } 186 187 this.curFilterinput = input; 188 BX.ajax.loadJSON( 189 this.ajaxURL, 190 this.values2post(values), 191 BX.delegate(this.postHandler, this) 192 ); 193 } 194 } 195}; 196 197JCSmartFilter.prototype.updateItem = function (PID, arItem) { 198 if (arItem.PROPERTY_TYPE === 'N' || arItem.PRICE) { 199 var trackBar = window['trackBar' + PID]; 200 if (!trackBar && arItem.ENCODED_ID) 201 trackBar = window['trackBar' + arItem.ENCODED_ID]; 202 203 if (trackBar && arItem.VALUES) { 204 if (arItem.VALUES.MIN) { 205 if (arItem.VALUES.MIN.FILTERED_VALUE) 206 trackBar.setMinFilteredValue(arItem.VALUES.MIN.FILTERED_VALUE); 207 else 208 trackBar.setMinFilteredValue(arItem.VALUES.MIN.VALUE); 209 } 210 211 if (arItem.VALUES.MAX) { 212 if (arItem.VALUES.MAX.FILTERED_VALUE) 213 trackBar.setMaxFilteredValue(arItem.VALUES.MAX.FILTERED_VALUE); 214 else 215 trackBar.setMaxFilteredValue(arItem.VALUES.MAX.VALUE); 216 } 217 } 218 } else if (arItem.VALUES) { 219 for (var i in arItem.VALUES) { 220 if (arItem.VALUES.hasOwnProperty(i)) { 221 var value = arItem.VALUES[i]; 222 var control = BX(value.CONTROL_ID); 223 224 if (!!control) { 225 var label = document.querySelector('[data-role="label_' + value.CONTROL_ID + '"]'); 226 if (value.DISABLED) { 227 if (label) 228 BX.addClass(label, 'disabled'); 229 else 230 BX.addClass(control.parentNode, 'disabled'); 231 } else { 232 if (label) 233 BX.removeClass(label, 'disabled'); 234 else 235 BX.removeClass(control.parentNode, 'disabled'); 236 } 237 238 if (value.hasOwnProperty('ELEMENT_COUNT')) { 239 label = document.querySelector('[data-role="count_' + value.CONTROL_ID + '"]'); 240 if (label) 241 label.innerHTML = value.ELEMENT_COUNT; 242 } 243 } 244 } 245 } 246 } 247}; 248 249JCSmartFilter.prototype.postHandler = function (result, fromCache) { 250 var hrefFILTER, url, curProp; 251 var modef = BX('modef'); 252 var modef_num = BX('modef_num'); 253 254 if (!!result && !!result.ITEMS) { 255 for (var popupId in this.popups) { 256 if (this.popups.hasOwnProperty(popupId)) { 257 this.popups[popupId].destroy(); 258 } 259 } 260 this.popups = []; 261 262 for (var PID in result.ITEMS) { 263 if (result.ITEMS.hasOwnProperty(PID)) { 264 this.updateItem(PID, result.ITEMS[PID]); 265 } 266 } 267 268 result.FILTER_URL = this.getCorrectUrl(result.FILTER_URL); 269 result.FILTER_AJAX_URL = this.getCorrectUrl(result.FILTER_AJAX_URL); 270 result.SEF_SET_FILTER_URL = this.getCorrectUrl(result.SEF_SET_FILTER_URL); 271 result.SEF_DEL_FILTER_URL = this.getCorrectUrl(result.SEF_DEL_FILTER_URL); 272 273 274 if (!!modef && !!modef_num) { 275 276 //modef_num.innerHTML = result.ELEMENT_COUNT; 277 hrefFILTER = BX.findChildren(modef, {tag: 'A'}, true); 278 279 if (result.FILTER_URL && hrefFILTER) { 280 hrefFILTER[0].href = BX.util.htmlspecialcharsback(result.FILTER_URL); 281 } 282 283 if (result.FILTER_AJAX_URL && result.COMPONENT_CONTAINER_ID) { 284 BX.unbindAll(hrefFILTER[0]); 285 BX.bind(hrefFILTER[0], 'click', function (e) { 286 url = BX.util.htmlspecialcharsback(result.FILTER_AJAX_URL); 287 BX.ajax.insertToNode(url, result.COMPONENT_CONTAINER_ID); 288 return BX.PreventDefault(e); 289 }); 290 } 291 292 if (result.INSTANT_RELOAD && result.COMPONENT_CONTAINER_ID) { 293 //this.bindUrlToButton('set_filter', result.SEF_SET_FILTER_URL); 294 295 url = BX.util.htmlspecialcharsback(result.FILTER_AJAX_URL); 296 this.bindUrlToButton('set_filter', url); 297 BX.ajax.insertToNode(url, result.COMPONENT_CONTAINER_ID); 298 } else { 299 if (modef.style.display === 'none') { 300 //modef.style.display = 'inline-block'; 301 } 302 303 if (this.viewMode == "VERTICAL") { 304 curProp = BX.findChild(BX.findParent(this.curFilterinput, {'class': 'bx-filter-parameters-box'}), {'class': 'bx-filter-container-modef'}, true, false); 305 //curProp.appendChild(modef); 306 } 307 308 if (result.SEF_SET_FILTER_URL) { 309 this.bindUrlToButton('set_filter', result.SEF_SET_FILTER_URL); 310 } 311 } 312 } 313 } 314 315 if (this.sef) { 316 var set_filter = BX('set_filter'); 317 set_filter.disabled = false;
318 } 319 320 if (!fromCache && this.cacheKey !== '') { 321 this.cache[this.cacheKey] = result; 322 } 323 this.cacheKey = ''; 324 325 document.querySelectorAll('.tooltip').forEach((item) => item.remove()); 326 327 setTimeout(function () { 328 329 window.popup.open('#filter'); 330 331 let links = document.querySelectorAll('[data-popup]'); 332 links.forEach((link) => { 333 link.addEventListener("click", (evt) => { 334 evt.preventDefault(); 335 window.popup.open(link.getAttribute("data-popup")) 336 }) 337 }); 338 document.querySelector('#modef_num').innerHTML = result.ELEMENT_COUNT; 339 BX(window.filterName + '_P1_MIN').removeAttribute('disabled'); 340 BX(window.filterName + '_P1_MAX').removeAttribute('disabled'); 341 try { 342 window.initNoUiSlider(); 343 window.initNoUiSliderPrice(); 344 window.initShowMore(); 345 window.iinitTolltip(); 346 } catch (error) { 347 } 348 349 BX.removeClass(BX('filter'), "loading"); 350 }, 2000); 351 352}; 353 354JCSmartFilter.prototype.bindUrlToButton = function (buttonId, url) { 355 var button = BX(buttonId); 356 if (button) { 357 var proxy = function (j, func) { 358 return function () { 359 return func(j); 360 } 361 }; 362 363 if (button.type == 'submit') 364 button.type = 'button'; 365 366 367 368 BX.bind(button, 'click', proxy(url, function (url) { 369 370 window.popup.open('#filter'); 371 if(button.id === 'del_filter') 372 window.location.href = url; 373 return false; 374 })); 375 } 376}; 377 378JCSmartFilter.prototype.gatherInputsValues = function (values, elements) { 379 if (elements) { 380 for (var i = 0; i < elements.length; i++) { 381 var el = elements[i]; 382 if (el.disabled || !el.type) 383 continue; 384 385 switch (el.type.toLowerCase()) { 386 case 'text': 387 case 'number': 388 case 'textarea': 389 case 'password': 390 case 'hidden': 391 case 'select-one': 392 if (el.value.length) 393 values[values.length] = {name: el.name, value: el.value}; 394 break; 395 case 'radio': 396 case 'checkbox': 397 if (el.checked) 398 values[values.length] = {name: el.name, value: el.value}; 399 break; 400 case 'select-multiple': 401 for (var j = 0; j < el.options.length; j++) { 402 if (el.options[j].selected) 403 values[values.length] = {name: el.name, value: el.options[j].value}; 404 } 405 break; 406 default: 407 break; 408 } 409 } 410 } 411}; 412 413JCSmartFilter.prototype.values2post = function (values) { 414 var post = []; 415 var current = post; 416 var i = 0; 417 418 while (i < values.length) { 419 var p = values[i].name.indexOf('['); 420 if (p == -1) { 421 current[values[i].name] = values[i].value; 422 current = post; 423 i++; 424 } else { 425 var name = values[i].name.substring(0, p); 426 var rest = values[i].name.substring(p + 1); 427 if (!current[name]) 428 current[name] = []; 429 430 var pp = rest.indexOf(']'); 431 if (pp == -1) { 432 //Error - not balanced brackets 433 current = post; 434 i++; 435 } else if (pp == 0) { 436 //No index specified - so take the next integer 437 current = current[name]; 438 values[i].name = '' + current.length; 439 } else { 440 //Now index name becomes and name and we go deeper into the array 441 current = current[name]; 442 values[i].name = rest.substring(0, pp) + rest.substring(pp + 1); 443 } 444 } 445 } 446 return post; 447}; 448 449JCSmartFilter.prototype.hideFilterProps = function (element) { 450 var obj = element.parentNode, 451 filterBlock = obj.querySelector("[data-role='bx_filter_block']"), 452 propAngle = obj.querySelector("[data-role='prop_angle']"); 453 454 if (BX.hasClass(obj, "bx-active")) { 455 new BX.easing({ 456 duration: 300, 457 start: {opacity: 1, height: filterBlock.offsetHeight}, 458 finish: {opacity: 0, height: 0}, 459 transition: BX.easing.transitions.quart, 460 step: function (state) { 461 filterBlock.style.opacity = state.opacity; 462 filterBlock.style.height = state.height + "px"; 463 }, 464 complete: function () { 465 filterBlock.setAttribute("style", ""); 466 BX.removeClass(obj, "bx-active"); 467 } 468 }).animate(); 469 470 BX.addClass(propAngle, "fa-angle-down"); 471 BX.removeClass(propAngle, "fa-angle-up"); 472 } else { 473 filterBlock.style.display = "block"; 474 filterBlock.style.opacity = 0; 475 filterBlock.style.height = "auto"; 476 477 var obj_children_height = filterBlock.offsetHeight; 478 filterBlock.style.height = 0; 479 480 new BX.easing({ 481 duration: 300, 482 start: {opacity: 0, height: 0}, 483 finish: {opacity: 1, height: obj_children_height}, 484 transition: BX.easing.transitions.quart, 485 step: function (state) { 486 filterBlock.style.opacity = state.opacity; 487 filterBlock.style.height = state.height + "px"; 488 }, 489 complete: function () { 490 } 491 }).animate(); 492 493 BX.addClass(obj, "bx-active"); 494 BX.removeClass(propAngle, "fa-angle-down"); 495 BX.addClass(propAngle, "fa-angle-up"); 496 } 497}; 498 499JCSmartFilter.prototype.showDropDownPopup = function (element, popupId) { 500 var contentNode = element.querySelector('[data-role="dropdownContent"]'); 501 this.popups["smartFilterDropDown" + popupId] = BX.PopupWindowManager.create("smartFilterDropDown" + popupId, element, { 502 autoHide: true, 503 offsetLeft: 0, 504 offsetTop: 3,
505 overlay: false, 506 draggable: {restrict: true}, 507 closeByEsc: true, 508 content: BX.clone(contentNode) 509 }); 510 this.popups["smartFilterDropDown" + popupId].show(); 511}; 512 513JCSmartFilter.prototype.selectDropDownItem = function (element, controlId) { 514 this.keyup(BX(controlId)); 515 516 var wrapContainer = BX.findParent(BX(controlId), {className: "bx-filter-select-container"}, false); 517 518 var currentOption = wrapContainer.querySelector('[data-role="currentOption"]'); 519 currentOption.innerHTML = element.innerHTML; 520 BX.PopupWindowManager.getCurrentPopup().close(); 521}; 522 523BX.namespace("BX.Iblock.SmartFilter"); 524BX.Iblock.SmartFilter = (function () { 525 /** @param {{ 526 leftSlider: string, 527 rightSlider: string, 528 tracker: string, 529 trackerWrap: string, 530 minInputId: string, 531 maxInputId: string, 532 minPrice: float|int|string, 533 maxPrice: float|int|string, 534 curMinPrice: float|int|string, 535 curMaxPrice: float|int|string, 536 fltMinPrice: float|int|string|null, 537 fltMaxPrice: float|int|string|null, 538 precision: int|null, 539 colorUnavailableActive: string, 540 colorAvailableActive: string, 541 colorAvailableInactive: string 542 }} arParams 543 */ 544 var SmartFilter = function (arParams) { 545 if (typeof arParams === 'object') { 546 this.leftSlider = BX(arParams.leftSlider); 547 this.rightSlider = BX(arParams.rightSlider); 548 this.tracker = BX(arParams.tracker); 549 this.trackerWrap = BX(arParams.trackerWrap); 550 551 this.minInput = BX(arParams.minInputId); 552 this.maxInput = BX(arParams.maxInputId); 553 554 this.minPrice = parseFloat(arParams.minPrice); 555 this.maxPrice = parseFloat(arParams.maxPrice); 556 557 this.curMinPrice = parseFloat(arParams.curMinPrice); 558 this.curMaxPrice = parseFloat(arParams.curMaxPrice); 559 560 this.fltMinPrice = arParams.fltMinPrice ? parseFloat(arParams.fltMinPrice) : parseFloat(arParams.curMinPrice); 561 this.fltMaxPrice = arParams.fltMaxPrice ? parseFloat(arParams.fltMaxPrice) : parseFloat(arParams.curMaxPrice); 562 563 this.precision = arParams.precision || 0; 564 565 this.priceDiff = this.maxPrice - this.minPrice; 566 567 this.leftPercent = 0; 568 this.rightPercent = 0; 569 570 this.fltMinPercent = 0; 571 this.fltMaxPercent = 0; 572 573 this.colorUnavailableActive = BX(arParams.colorUnavailableActive);//gray 574 this.colorAvailableActive = BX(arParams.colorAvailableActive);//blue 575 this.colorAvailableInactive = BX(arParams.colorAvailableInactive);//light blue 576 577 this.isTouch = false; 578 579 this.init(); 580 581 if ('ontouchstart' in document.documentElement) { 582 this.isTouch = true; 583 584 BX.bind(this.leftSlider, "touchstart", BX.proxy(function (event) { 585 this.onMoveLeftSlider(event) 586 }, this)); 587 588 BX.bind(this.rightSlider, "touchstart", BX.proxy(function (event) { 589 this.onMoveRightSlider(event) 590 }, this)); 591 } else { 592 BX.bind(this.leftSlider, "mousedown", BX.proxy(function (event) { 593 this.onMoveLeftSlider(event) 594 }, this)); 595 596 BX.bind(this.rightSlider, "mousedown", BX.proxy(function (event) { 597 this.onMoveRightSlider(event) 598 }, this)); 599 } 600 601 BX.bind(this.minInput, "keyup", BX.proxy(function (event) { 602 this.onInputChange(); 603 }, this)); 604 605 BX.bind(this.maxInput, "keyup", BX.proxy(function (event) { 606 this.onInputChange(); 607 }, this)); 608 } 609 }; 610 611 SmartFilter.prototype.init = function () { 612 var priceDiff; 613 614 if (this.curMinPrice > this.minPrice) { 615 priceDiff = this.curMinPrice - this.minPrice; 616 this.leftPercent = (priceDiff * 100) / this.priceDiff; 617 618 } 619 620 this.setMinFilteredValue(this.fltMinPrice); 621 622 if (this.curMaxPrice < this.maxPrice) { 623 priceDiff = this.maxPrice - this.curMaxPrice; 624 this.rightPercent = (priceDiff * 100) / this.priceDiff; 625 626 //this.rightSlider.style.right = this.rightPercent + "%"; 627 //this.colorUnavailableActive.style.right = this.rightPercent + "%"; 628 } 629 630 this.setMaxFilteredValue(this.fltMaxPrice); 631 }; 632 633 SmartFilter.prototype.setMinFilteredValue = function (fltMinPrice) { 634 this.fltMinPrice = parseFloat(fltMinPrice); 635 if (this.fltMinPrice >= this.minPrice) { 636 var priceDiff = this.fltMinPrice - this.minPrice; 637 this.fltMinPercent = (priceDiff * 100) / this.priceDiff; 638 639 } else { 640 641 } 642 }; 643 644 SmartFilter.prototype.setMaxFilteredValue = function (fltMaxPrice) { 645 this.fltMaxPrice = parseFloat(fltMaxPrice); 646 if (this.fltMaxPrice <= this.maxPrice) { 647 var priceDiff = this.maxPrice - this.fltMaxPrice; 648 this.fltMaxPercent = (priceDiff * 100) / this.priceDiff; 649 650 } else { 651 652 } 653 }; 654 655 SmartFilter.prototype.getXCoord = function (elem) { 656 var box = elem.getBoundingClientRect(); 657 var body = document.body; 658 var docElem = document.documentElement; 659 660 var scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft; 661 var clientLeft = docElem.clientLeft || body.clientLeft || 0; 662 var left = box.left + scrollLeft - clientLeft; 663 664 return Math.round(left); 665 }; 666 667 SmartFilter.prototype.getPageX = function (e) { 668 e = e || window.event; 669 var pageX = null; 670 671 if (this.isTouch && event.targetTouches[0] != null) { 672 pageX = e.targetTouches[0].pageX; 673 } else if (e.pageX != null) { 674 pageX = e.pageX; 675 } else if (e.clientX != null) { 676 var html = document.documentElement; 677 var body = document.body; 678 679 pageX = e.clientX + (html.scrollLeft || body && body.scrollLeft || 0); 680 pageX -= html.clientLeft || 0; 681 } 682 683 return pageX; 684 }; 685 686 SmartFilter.prototype.recountMinPrice = function () { 687 var newMinPrice = (this.priceDiff * this.leftPercent) / 100; 688 newMinPrice = (this.minPrice + newMinPrice).toFixed(this.precision); 689 690 if (newMinPrice != this.minPrice) 691 this.minInput.value = newMinPrice; 692 else 693 this.minInput.value = ""; 694 /** @global JCSmartFilter smartFilter */ 695 smartFilter.keyup(this.minInput); 696 }; 697 698 SmartFilter.prototype.recountMaxPrice = function () { 699 var newMaxPrice = (this.priceDiff * this.rightPercent) / 100; 700 newMaxPrice = (this.maxPrice - newMaxPrice).toFixed(this.precision); 701 702 if (newMaxPrice != this.maxPrice) 703 this.maxInput.value = newMaxPrice; 704 else 705 this.maxInput.value = ""; 706 /** @global JCSmartFilter smartFilter */ 707 smartFilter.keyup(this.maxInput); 708 }; 709 710 SmartFilter.prototype.onInputChange = function () { 711 var priceDiff; 712 if (this.minInput.value) { 713 var leftInputValue = this.minInput.value; 714 if (leftInputValue < this.minPrice) 715 leftInputValue = this.minPrice; 716 717 if (leftInputValue > this.maxPrice) 718 leftInputValue = this.maxPrice; 719 720 priceDiff = leftInputValue - this.minPrice; 721 this.leftPercent = (priceDiff * 100) / this.priceDiff; 722 723 this.makeLeftSliderMove(false); 724 } 725 726 if (this.maxInput.value) { 727 var rightInputValue = this.maxInput.value; 728 if (rightInputValue < this.minPrice) 729 rightInputValue = this.minPrice; 730 731 if (rightInputValue > this.maxPrice) 732 rightInputValue = this.maxPrice; 733 734 priceDiff = this.maxPrice - rightInputValue; 735 this.rightPercent = (priceDiff * 100) / this.priceDiff; 736 737 this.makeRightSliderMove(false); 738 } 739 }; 740 741 SmartFilter.prototype.makeLeftSliderMove = function (recountPrice) { 742 recountPrice = (recountPrice !== false); 743 744 745 var areBothSlidersMoving = false;
746 if (this.leftPercent + this.rightPercent >= 100) { 747 areBothSlidersMoving = true; 748 this.rightPercent = 100 - this.leftPercent; 749 //this.rightSlider.style.right = this.rightPercent + "%"; 750 this.colorUnavailableActive.style.right = this.rightPercent + "%"; 751 } 752 753 754 if (recountPrice) { 755 this.recountMinPrice(); 756 if (areBothSlidersMoving) 757 this.recountMaxPrice(); 758 } 759 }; 760 761 SmartFilter.prototype.countNewLeft = function (event) { 762 var pageX = this.getPageX(event); 763 764 var trackerXCoord = this.getXCoord(this.trackerWrap); 765 var rightEdge = this.trackerWrap.offsetWidth; 766 767 var newLeft = pageX - trackerXCoord; 768 769 if (newLeft < 0) 770 newLeft = 0; 771 else if (newLeft > rightEdge) 772 newLeft = rightEdge; 773 774 return newLeft; 775 }; 776 777 SmartFilter.prototype.onMoveLeftSlider = function (e) { 778 if (!this.isTouch) { 779 this.leftSlider.ondragstart = function () { 780 return false; 781 }; 782 } 783 784 if (!this.isTouch) { 785 document.onmousemove = BX.proxy(function (event) { 786 this.leftPercent = ((this.countNewLeft(event) * 100) / this.trackerWrap.offsetWidth); 787 this.makeLeftSliderMove(); 788 }, this); 789 790 document.onmouseup = function () { 791 document.onmousemove = document.onmouseup = null; 792 }; 793 } else { 794 document.ontouchmove = BX.proxy(function (event) { 795 this.leftPercent = ((this.countNewLeft(event) * 100) / this.trackerWrap.offsetWidth); 796 this.makeLeftSliderMove(); 797 }, this); 798 799 document.ontouchend = function () { 800 document.ontouchmove = document.touchend = null; 801 }; 802 } 803 804 return false; 805 }; 806 807 SmartFilter.prototype.makeRightSliderMove = function (recountPrice) { 808 recountPrice = (recountPrice !== false); 809 810 811 var areBothSlidersMoving = false; 812 if (this.leftPercent + this.rightPercent >= 100) { 813 areBothSlidersMoving = true; 814 this.leftPercent = 100 - this.rightPercent; 815 this.leftSlider.style.left = this.leftPercent + "%"; 816 this.colorUnavailableActive.style.left = this.leftPercent + "%"; 817 } 818 819 820 if (recountPrice) { 821 this.recountMaxPrice(); 822 if (areBothSlidersMoving) 823 this.recountMinPrice(); 824 } 825 }; 826 827 SmartFilter.prototype.onMoveRightSlider = function (e) { 828 if (!this.isTouch) { 829 this.rightSlider.ondragstart = function () { 830 return false; 831 }; 832 } 833 834 if (!this.isTouch) { 835 document.onmousemove = BX.proxy(function (event) { 836 this.rightPercent = 100 - (((this.countNewLeft(event)) * 100) / (this.trackerWrap.offsetWidth)); 837 this.makeRightSliderMove(); 838 }, this); 839 840 document.onmouseup = function () { 841 document.onmousemove = document.onmouseup = null; 842 }; 843 } else { 844 document.ontouchmove = BX.proxy(function (event) { 845 this.rightPercent = 100 - (((this.countNewLeft(event)) * 100) / (this.trackerWrap.offsetWidth)); 846 this.makeRightSliderMove(); 847 }, this); 848 849 document.ontouchend = function () { 850 document.ontouchmove = document.ontouchend = null; 851 }; 852 } 853 854 return false; 855 }; 856 857 return SmartFilter; 858})();
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.