PageSourceSearch

https://philipkingsley-russia.ru/bitrix/templates/aspro_max/compon…/catalog.smart.filter/main_ajax/script.js

js philipkingsley-russia.ru collected 2026-10-05 00:14:21 UTC 42,875 bytes, 1,314 lines download raw bytes

1// fix double add event handler (composite + google PSI module)
2if (!window.JCSmartFilterBinds) {
3  $(document).ready(function () {
4    var checkClosed = function (item) {
5      $.cookie.json = true;
6      var arClosed = $.cookie("MAX_FILTER_CLOSED");
7      if (arClosed && typeof arClosed != "undefined") {
8        if (typeof item != "undefined") {
9          var propID = item.parents(".bx_filter_parameters_box").data("property_id");
10          var delIndex = $.inArray(propID, arClosed);
11          if (delIndex >= 0) {
12            arClosed.splice(delIndex, 1);
13          } else {
14            arClosed.push(propID);
15          }
16        }
17      } else {
18        var arClosed = [];
19        if (typeof item != "undefined") {
20          item = $(item);
21          var propID = item.parents(".bx_filter_parameters_box").data("property_id");
22          if (!item.parents(".bx_filter_parameters_box").is(".active")) {
23            if (!$.inArray(propID, arClosed) >= 0) {
24              arClosed.push(propID);
25            }
26          } else {
27            if ($.inArray(propID, arClosed) >= 0) {
28              arClosed.splice(delIndex, 1);
29            }
30          }
31        }
32      }
33      $.cookie("MAX_FILTER_CLOSED", arClosed, {
34        path: "/",
35        domain: "",
36        expires: 360,
37      });
38      return true;
39    };
40    $(document).on("click", ".bx_filter_parameters_box_title", function (e) {
41      if (!$(e.target).hasClass("tooltip")) {
42        var active = 2;
43        if ($(this).closest(".bx_filter_parameters_box").hasClass("active")) {
44          // $(this).next(".bx_filter_block").slideUp(100);
45          $(this).next(".bx_filter_block").stop().velocity("slideUp", 100);
46        } else {
47          // $(this).next(".bx_filter_block").slideDown(200);
48          $(this).next(".bx_filter_block").stop().velocity("slideDown", 200);
49        }
50
51        $(this).closest(".bx_filter_parameters_box").toggleClass("active");
52
53        if ($(this).closest(".bx_filter_parameters_box").hasClass("active")) active = 3;
54
55        $.cookie.json = true;
56        $.cookie("MAX_filter_prop_" + $(this).closest(".bx_filter_parameters_box").data("prop_code"), active, {
57          path: "/",
58          domain: "",
59          expires: 360,
60        });
61
62        /*setTimeout(() => {
63					InitStickySideBar();
64				}, 300);*/
65
66        setTimeout(function () {
67          InitStickySideBar();
68        }, 300);
69      }
70    });
71    $('.bx_filter_parameters_box:not(.enumOne)').each(function(){
72      if ($.cookie("MAX_filter_prop_" + $(this).data("prop_code")) == 2) {
73        $(this).removeClass("active");
74        $(this).find(".bx_filter_block").hide();
75      } else if ($.cookie("MAX_filter_prop_" + $(this).data("prop_code")) == 3) {
76        $(this).addClass("active");
77        $(this).find(".bx_filter_block").show();
78      }
79    });
80    if (typeof window["stickySidebar"] !== "undefined") {
81      window["stickySidebar"].updateSticky();
82    }
83    $(document).click(function (e) {
84      if (!$(e.target).hasClass("tooltip")) {
85        $(".bx_filter .hint.active").removeClass("active").find(".tooltip").slideUp(200);
86      }
87    });
88    window.JCSmartFilterBinds = true;
89    InitScrollBar();
90  });
91}
92function JCSmartFilter(ajaxURL, viewMode, params) {
93  this.ajaxURL = ajaxURL;
94  this.form = null;
95  this.timer = null;
96  this.cacheKey = "";
97  this.cache = [];
98  this.viewMode = viewMode;
99  this.normal_url = false;
100  this.reset = false;
101  /*if (params && params.SEF_SET_FILTER_URL)
102		{*/
103  this.bindUrlToButton("set_filter", params.SEF_SET_FILTER_URL);
104  this.sef = true;
105  /*}
106		if (params && params.SEF_DEL_FILTER_URL)
107		{*/
108  this.bindUrlToButton("del_filter", params.SEF_DEL_FILTER_URL);
109  //}
110  if (!params.SEF_DEL_FILTER_URL) {
111    this.normal_url = true;
112  }
113}
114
115JCSmartFilter.prototype.keyup = function (input) {
116  if (!!this.timer) {
117    clearTimeout(this.timer);
118  }
119  if (!$(input).hasClass("disabled")) {
120    this.timer = setTimeout(
121      BX.delegate(function () {
122        this.reload(input);
123      }, this),
124      500
125    );
126  }
127};
128
129JCSmartFilter.prototype.click = function (checkbox) {
130  if (!!this.timer) {
131    clearTimeout(this.timer);
132  }
133
134  this.timer = setTimeout(
135    BX.delegate(function () {
136      this.reload(checkbox);
137    }, this),
138    500
139  );
140};
141
142JCSmartFilter.prototype.reload = function (input) {
143  if (this.cacheKey !== "") {
144    //Postprone backend query
145    if (!!this.timer) {
146      clearTimeout(this.timer);
147    }
148    this.timer = setTimeout(
149      BX.delegate(function () {
150        this.reload(input);
151      }, this),
152      1000
153    );
154    return;
155  }
156  this.cacheKey = "|";
157
158  this.position = BX.pos(input, true);
159  this.form = BX.findParent(input, { tag: "form" });
160
161  if (this.form) {
162    if ($(".middle > .container .ajax_load").length) $(".middle > .container .ajax_load").addClass("loading-state");
163
164    var values = [];
165    values[0] = { name: "ajax", value: "y" };
166    this.gatherInputsValues(values, BX.findChildren(this.form, { tag: new RegExp("^(input|select)$", "i") }, true));
167
168    $(".bx_filter_parameters_box").removeClass("set");
169
170    for (var i = 0; i < values.length; i++) {
171      this.cacheKey += values[i].name + ":" + values[i].value + "|";
172      $("input[name=" + values[i].name + "]")
173        .closest(".bx_filter_parameters_box")
174        .addClass("set");
175    }
176
177    for (var i = 0; i < values.length; i++) this.cacheKey += values[i].name + ":" + values[i].value + "|";
178
179    if (this.cache[this.cacheKey]) {
180      this.curFilterinput = input;
181      this.postHandler(this.cache[this.cacheKey], true);
182    } else {
183      if (this.sef) {
184        var set_filter = BX("set_filter"),
185          reset_filter = BX("del_filter");
186
187        if (set_filter) set_filter.disabled = true;
188        if (reset_filter) reset_filter.disabled = true;
189      }
190
191      this.curFilterinput = input;
192      BX.ajax.loadJSON(this.ajaxURL, this.values2post(values), BX.delegate(this.postHandler, this));
193    }
194  }
195};
196
197JCSmartFilter.prototype.updateItem = function (PID, arItem, reset) {
198  if (arItem.PROPERTY_TYPE === "N" || arItem.PRICE) {
199    var trackBar = window["trackBar" + PID];
200    if (!trackBar && arItem.ENCODED_ID) trackBar = window["trackBar" + arItem.ENCODED_ID];
201
202    if (trackBar && arItem.VALUES) {
203      if (arItem.VALUES.MIN) {
204        if (arItem.VALUES.MIN.HTML_VALUE && window.FilterHelper !== undefined) {
205          var helperData = {
206            NAME: arItem.VALUES.MIN.CONTROL_ID,
207            VALUE: BX.message("FROM") + " " + arItem.VALUES.MIN.HTML_VALUE,
208            TITLE: arItem.NAME,
209            CODE: arItem.VALUES.MIN.CONTROL_ID.replace("_MIN", ""),
210            TYPE: "price",
211          };
212          FilterHelper.add(helperData);
213        }
214        if (arItem.VALUES.MIN.FILTERED_VALUE) trackBar.setMinFilteredValue(arItem.VALUES.MIN.FILTERED_VALUE);
215        else trackBar.setMinFilteredValue(arItem.VALUES.MIN.VALUE);
216      }
217
218      if (arItem.VALUES.MAX) {
219        if (arItem.VALUES.MAX.HTML_VALUE && window.FilterHelper !== undefined) {
220          var helperData = {
221            NAME: arItem.VALUES.MAX.CONTROL_ID,
222            VALUE: BX.message("BEFORE") + " " + arItem.VALUES.MAX.HTML_VALUE,
223            TITLE: arItem.NAME,
224            CODE: arItem.VALUES.MAX.CONTROL_ID.replace("_MAX", ""),
225            TYPE: "price",
226          };
227          FilterHelper.add(helperData);
228        }
229        if (arItem.VALUES.MAX.FILTERED_VALUE) trackBar.setMaxFilteredValue(arItem.VALUES.MAX.FILTERED_VALUE);
230        else trackBar.setMaxFilteredValue(arItem.VALUES.MAX.VALUE);
231      }
232      if (reset == "Y") {
233        trackBar.leftPercent = trackBar.rightPercent = 0;
234        $("#" + arItem.VALUES.MIN.CONTROL_ID).val("");
235        $("#" + arItem.VALUES.MAX.CONTROL_ID).val("");
236        $("#left_slider_" + arItem.ENCODED_ID).css({ left: "0%" });
237        $("#colorUnavailableActive_" + arItem.ENCODED_ID).css({ left: "0%", r
237ight: "0%" });
238        $("#colorAvailableInactive_" + arItem.ENCODED_ID).css({ left: "0%", right: "0%" });
239        $("#colorAvailableActive_" + arItem.ENCODED_ID).css({ left: "0%", right: "0%" });
240        $("#right_slider_" + arItem.ENCODED_ID).css({ right: "0%" });
241      }
242    }
243  } else if (arItem.VALUES) {
244    for (var i in arItem.VALUES) {
245      if (arItem.VALUES.hasOwnProperty(i)) {
246        var value = arItem.VALUES[i];
247        var control = BX(value.CONTROL_ID);
248        if (!!control) {
249          var label = document.querySelector('[data-role="label_' + value.CONTROL_ID + '"]');
250          input = document.querySelector('[id="' + value.CONTROL_ID + '"]');
251
252          if (value.CHECKED && window.FilterHelper !== undefined) {
253            var helperData = {
254              NAME: value.CONTROL_ID,
255              VALUE: value.VALUE,
256              TITLE: arItem.NAME,
257              INPUT: input,
258              CODE: arItem.CODE.toLowerCase(),
259              TYPE: $(input).attr("type"),
260            };
261            FilterHelper.add(helperData);
262          }
263          if (value.DISABLED) {
264            if (label) {
265              BX.addClass(label, "disabled");
266              if (input) {
267                input.setAttribute("disabled", "disabled");
268                BX.addClass(input, "disabled");
269              }
270            } else {
271              BX.addClass(control.parentNode, "disabled");
272            }
273          } else {
274            if (label) {
275              BX.removeClass(label, "disabled");
276              if (input) {
277                input.removeAttribute("disabled");
278                BX.removeClass(input, "disabled");
279              }
280              // if(reset=="Y"){
281              if ($(control)) {
282                $(control).prop("disabled", false);
283                $(control).removeClass("disabled");
284              }
285              $(label).find("span").removeClass("disabled");
286              // }
287            } else BX.removeClass(control.parentNode, "disabled");
288          }
289
290          if (reset == "Y") {
291            if ($(control).attr("type") == "checkbox" || $(control).attr("type") == "radio") {
292              if ($(control).attr("checked")) {
293                $(control).prop("checked", false);
294                // input.removeAttribute('checked');
295              }
296            }
297          }
298
299          if (value.hasOwnProperty("ELEMENT_COUNT")) {
300            label = document.querySelector('[data-role="count_' + value.CONTROL_ID + '"]');
301            if (label) label.innerHTML = value.ELEMENT_COUNT;
302          }
303        }
304      }
305    }
306  }
307};
308
309JCSmartFilter.prototype.postHandlerAjax = function (result, fromCache) {
310  $("#content").html(result);
311};
312
313JCSmartFilter.prototype.setUrlSortDisplay = function (url) {
314  var arReplace_url = "",
315    strReplace_url = "";
316
317  $(".sort_btn").each(function () {
318    arReplace_url = $(this).attr("href").split("?");
319    arReplace_url[0] = url;
320    strReplace_url = arReplace_url.join("?");
321
322    $(this).attr("href", strReplace_url);
323  });
324};
325
326JCSmartFilter.prototype.filterCatalog = function (url, set_disabled, reset, count) {
327  if (url.match(/%(?![0-9][0-9a-fA-F]+)/g)) {
328    url = url.replace(/%(?![0-9][0-9a-fA-F]+)/g, '%25');
329
330    if (($('.bx-ie').length && !$('.bx-ie11').length) || !$('.bx-core').length) {
331      location.href = url;
332    } else {
333      window.history.pushState(null, document.title, url);
334    }
335  } else if (window.History.enabled || window.history.pushState != null) {
336    window.History.pushState(null, document.title, decodeURIComponent(url));
337  } else {
338    location.href = url;
339  }
340
341  // this.setUrlSortDisplay(url);
342
343  $.ajax({
344    url: url,
345    type: "GET",
346    data: { ajax_get: "Y", ajax_get_filter: "Y" },
347    success: function (html) {
348      /*$('.middle > .container').html(html);
349
350				if($(html).find('.filter_title').hasClass('active-filter'))
351				{
352					$('.filter_title').addClass('active-filter');
353					$('.bx_filter_search_reset').removeClass('hidden');
354				}
355				else
356				{
357					$('.filter_title').removeClass('active-filter');
358					if(reset)
359						$('.bx_filter_search_reset').addClass('hidden');
360				}
361
362				if(reset)
363				{
364					$('.bx_filter_button_box .bx_filter_search_reset').addClass('hidden');
365
366
367					if(reset && $('#mobilefilter .bx_filter').length)
368					{
369						mobileFilterNum(count);
370					}
371
372					smartFilter.reset = false;
373				}*/
374
375      if (reset && (!$("#wrapInlineFilter").length || !$("#wrapInlineFilter").is(":empty"))) {
376        // $('#right_block_ajax').html($(html).find('#right_block_ajax').html());
377        $(".js-load-wrapper").html($(html).find(".js-load-wrapper").html());
378        $(".left_block").html($(html).find(".left_block").html());
379        $(".top-content-block").html($(html).find(".top-content-block").html());
380
381        if ("checkFilterLandgings" in window && typeof checkFilterLandgings == "function") {
382          checkFilterLandgings();
383        }
384
385        InitStickySideBar();
386        InitScrollBar($(".left_block .smartfilter .srollbar-custom"));
387      } else {
388        var itemsHtml = $.trim($(html).find(".inner_wrapper").html());
389        $(".middle > .container .inner_wrapper").html(itemsHtml);
390
391        //ajax top-block
392        $(".top-content-block").html($(html).find(".top-content-block").html());
393
394        //ajax sort-block
395        $(".sort_header").html($(html).find(".sort_header").html());
396
397        if ($(html).find(".filter_title").hasClass("active-filter")) {
398          $(".filter_title").addClass("active-filter");
399          $(".bx_filter_search_reset ").removeClass("hidden");
400        } else {
401          $(".filter_title").removeClass("active-filter");
402          $(".bx_filter_search_reset ").addClass("hidden");
403        }
404
405        if (reset && $("#mobilefilter .bx_filter").length) {
406          $("#mobilefilter").html("");
407          $(html).find(".bx_filter").appendTo($("#mobilefilter"));
408          $("#mobilefilter .bx_filter_parameters").addClass("scrollbar");
409          $("#mobilefilter .bx_filter_parameters .bx_filter_parameters_box_title").addClass(
410            "colored_theme_hover_bg-block"
411          );
412          $("#mobilefilter .bx_filter_button_box .filter-bnt-wrapper").removeClass("hidden");
413          InitCustomScrollBar();
414
415          smartFilter.bindUrlToButton("set_filter", smartFilter.SEF_SET_FILTER_URL);
416          smartFilter.bindUrlToButton("del_filter", smartFilter.SEF_DEL_FILTER_URL);
417
418          mobileFilterNum(count);
419
420          if (window.sortFilterPopup !== undefined && typeof window.sortFilterPopup.destroy == "function") {
421            window.sortFilterPopup.destroy();
422          }
423        }
424
425        if ("checkFilterLandgings" in window && typeof checkFilterLandgings == "function") {
426          checkFilterLandgings();
427        }
428      }
429
430      CheckTopMenuFullCatalogSubmenu();
431
432      $(".fast_view_frame").remove();
433
434      // setStatusButton();
435      BX.onCustomEvent("onAjaxSuccessFilter");
436
437      if (set_disabled == "Y") {
438        var set_filter = BX("set_filter"),
439          reset_filter = BX("del_filter");
440
441        if (set_filter) set_filter.disabled = false;
442        if (reset_filter) reset_filter.disabled = false;
443      }
444
445      var eventdata = { action: "jsLoadBlock" };
446      BX.onCustomEvent("onCompleteAction", [eventdata, this]);
447
448      if ($(".middle > .container .ajax_load").length)
449        $(".middle > .container .ajax_load").removeClass("loading-state");
450
451      // $('.countdown').countdown('destroy');
452      // initCountdown();
453
454      if(typeof Ya.share2 == 'function'){
455        var myShare = document.querySelector('.ya-share2');
456        Ya.share2(myShare, {
457          content: {
458            url: location.href    
459          }
460        });
461      }
462    },
463  });
464};
465
466JCSmartFilter.prototype.postHandler = function (result, fromCache) {
467  if (window.FilterHelper !== undefined) {
468    FilterHelper.reload();
469  }
470  var hrefFILTER, url, curProp;
471  var modef = BX("modef");
472  var modef_mobile = BX("modef_mobile");
473  var modef_num = BX("modef_num");
474  var modef_num_mobile = BX("modef_num_mobile");
475  var reset = "N";
476
477  if ("RESET_FORM" in result) {
478    document.getElementsByClassName("smartfilter")[0].reset();
479    reset = "Y";
480  }
481
482  if (!!result && !!result.ITEMS) {
483    for (var PID in result.ITEMS) {
484      if (result.ITEMS.hasOwnProperty(PID)) {
485        this.updateItem(PID, result.ITEMS[PID], reset);
486      }
487    }
488    if (reset == "Y") {
489      if ($(".bx_filter_select_block").length) {
490        $(".bx_filter_select_block").each(function () {
491          var id = $(this).closest(".bx_filter_parameters_box").attr("property_id"),
492            all_text = $(this).find(".input_wr_all input:first-child").data("title");
493          $(this).find(".bx_filter_select_text").text(all_text);
494          $(this).find(".bx_filter_select_popup li label").removeClass("selected");
495        });
496      }
497    }
498    if (!!modef && !!modef_num) {
499      modef_num.innerHTML = result.ELEMENT_COUNT;
500      modef_num_mobile.innerHTML = result.ELEMENT_COUNT;
501      if (typeof mobileFilterNum === "function") {
502        mobileFilterNum(result.ELEMENT_COUNT);
503      }
504      hrefFILTER = BX.findChildren(modef, { tag: "A" }, true);
505      hrefFILTER_mobile = BX.findChildren(modef_mobile, { tag: "A" }, true);
506
507      if (result.FILTER_URL && hrefFILTER) {
508        hrefFILTER[0].href = BX.util.htmlspecialcharsback(result.FILTER_URL.replace("/filter/clear/apply/", "/"));
509        hrefFILTER_mobile[0].href = BX.util.htmlspecialcharsback(
510          result.FILTER_URL.replace("/filter/clear/apply/", "/")
511        );
512      }
513
514      if (result.FILTER_AJAX_URL && result.COMPONENT_CONTAINER_ID) {
515        BX.unbindAll(hrefFILTER[0]);
516        BX.unbindAll(hrefFILTER_mobile[0]);
517        BX.bind(hrefFILTER[0], "click", function (e) {
518          url = BX.util.htmlspecialcharsback(result.FILTER_AJAX_URL);
519          BX.ajax.insertToNode(url, result.COMPONENT_CONTAINER_ID);
520          return BX.PreventDefault(e);
521        });
522      }
523
524      if (result.INSTANT_RELOAD && result.COMPONENT_CONTAINER_ID) {
525        url = BX.util.htmlspecialcharsback(result.FILTER_AJAX_URL);
526        BX.ajax.insertToNode(url, result.COMPONENT_CONTAINER_ID);
527      } else {
528        /*ajax update filter catalog items start*/
529
530        url = BX.util.htmlspecialcharsback(result.FILTER_AJAX_URL);
531        // BX.ajax.insertToNode(url+'?ajax_get=Y', "right_block_ajax");
532
533        this.filterCatalog(url, "N", this.reset, result.ELEMENT_COUNT);
534
535        /*ajax update filter catalog items end*/
536
537        /*if (modef.style.display === 'none')
538					{
539						modef.style.display = 'inline-block';
540						modef_mobile.style.display = 'inline-block';
541					}
542					if (this.viewMode == "vertical")
543					{
544						curProp = BX.findChild(BX.findParent(this.curFilterinput, {'class':'bx_filter_parameters_box'}), {'class':'bx_filter_container_modef'}, true, false);
545						curProp.appendChild(modef);
546					}*/
547
548        if (result.SEF_SET_FILTER_URL) {
549          this.bindUrlToButton("set_filter", result.SEF_SET_FILTER_URL);
550        } else {
551          this.bindUrlToButton("set_filter", url);
552        }
553      }
554    }
555    if (window.FilterHelper !== undefined) {
556      FilterHelper.show();
557    }
558  }
559
560  if (this.sef) {
561    var set_filter = BX("set_filter"),
562      reset_filter = BX("del_filter");
563
564    if (set_filter) set_filter.disabled = false;
565    if (reset_filter) reset_filter.disabled = false;
566  }
567
568  if (!fromCache && this.cacheKey !== "") {
569    this.cache[this.cacheKey] = result;
570  }
571  this.cacheKey = "";
572};
573
574JCSmartFilter.prototype.bindUrlToButton = function (buttonId, url) {
575  var button = BX(buttonId);
576  if (button) {
577    var proxy = function (j, func) {
578      return function () {
579        return func(j);
580      };
581    };
582
583    if (button.type == "submit") button.type = "button";
584
585    $(button).data("href", url);
586    BX.unbindAll(button);
587
588    BX.bind(
589      button,
590      "click",
591      BX.proxy(function () {
592        var url_filter = $(button).data("href"),
593          id = $(button).attr("id");
594
595        if (id == "del_filter") {
596          var values = [],
597            url_form = this.normal_url ? $("form.smartfilter").attr("action") : this.ajaxURL;
598          values[0] = { name: "ajax", value: "y" };
599          // document.getElementById("smartfilter").reset();
600          if (!this.normal_url) {
601            // this.gatherInputsValues(values, BX.findChildren(document.getElementById("smartfilter"), {'tag': new RegExp('^([type=hidden])$', 'i')}, true));
602            this.gatherInputsValues(
603              values,
604              BX.findChildren(document.getElementById("smartfilter"), { attribute: "hidden" }, true)
605            );
606          }
607          values[1] = { name: "reset_form", value: "y" };
608          if (this.sef) {
609            var set_filter = BX("set_filter"),
610              reset_filter = BX("del_filter");
611
612            if (set_filter) set_filter.disabled = true;
613            if (reset_filter) reset_filter.disabled = true;
614          }
615
616          this.reset = true;
617
618          BX.ajax.loadJSON(url_form, this.values2post(values), BX.delegate(this.postHandler, this));
619        } else {
620          if (url_filter) {
621            if (this.sef) {
622              var set_filter = BX("set_filter"),
623                reset_filter = BX("del_filter");
624
625              if (set_filter) set_filter.disabled = true;
626              if (reset_filter) reset_filter.disabled = true;
627            }
628
629            this.filterCatalog(url_filter, "Y");
630          }
631        }
632      }, this)
633    );
634  }
635};
636
637JCSmartFilter.prototype.gatherInputsValues = function (values, elements) {
638  if (elements) {
639    for (var i = 0; i < elements.length; i++) {
640      var el = elements[i];
641      if (el.disabled || !el.type) continue;
642
643      switch (el.type.toLowerCase()) {
644        case "text":
645        case "textarea":
646        case "password":
647        case "hidden":
648        case "select-one":
649          if (el.value.length) values[values.length] = { name: el.name, value: el.value };
650          break;
651        case "radio":
652        case "checkbox":
653          if (el.checked) values[values.length] = { name: el.name, value: el.value };
654          break;
655        case "select-multiple":
656          for (var j = 0; j < el.options.length; j++) {
657            if (el.options[j].selected) values[values.length] = { name: el.name, value: el.options[j].value };
658          }
659          break;
660        default:
661          break;
662      }
663    }
664  }
665};
666
667JCSmartFilter.prototype.values2post = function (values) {
668  var post = [];
669  var current = post;
670  var i = 0;
671
672  while (i < values.length) {
673    var p = values[i].name.indexOf("[");
674    if (p == -1) {
675      current[values[i].name] = values[i].value;
676      current = post;
677      i++;
678    } else {
679      var name = values[i].name.substring(0, p);
680      var rest = values[i].name.substring(p + 1);
681      if (!current[name]) current[name] = [];
682
683      var pp = rest.indexOf("]");
684      if (pp == -1) {
685        //Error - not balanced brackets
686        current = post;
687        i++;
688      } else if (pp == 0) {
689        //No index specified - so take the next integer
690        current = current[name];
691        values[i].name = "" + current.length;
692      } else {
693        //Now index name becomes and name and we go deeper into the array
694        current = current[name];
695        values[i].name = rest.substring(0, pp) + rest.substring(pp + 1);
696      }
697    }
698  }
699  return post;
700};
701
702JCSmartFilter.prototype.hideFilterProps = function (element) {
703  var obj = element.parentNode,
704    filterBlock = obj.querySelector("[data-role='bx_filter_block']"),
705    propAngle = obj.querySelector("[data-role='prop_angle']");
706
707  if (BX.hasClass(obj, "bx-active")) {
708    new BX.easing({
709      duration: 300,
710      start: { opacity: 1, height: filterBlock.offsetHeight },
711      finish: { opacity: 0, height: 0 },
712      transition: BX.easing.transitions.quart,
713      step: function (state) {
714        filterBlock.style.opacity = state.opacity;
715        filterBlock.style.height = state.height + "px";
716      },
717      complete: function () {
718        filterBlock.setAttribute("style", "");
719        BX.removeClass(obj, "bx-active");
720      },
721    }).animate();
722
723    BX.addClass(propAngle, "fa-angle-down");
724    BX.removeClass(propAngle, "fa-angle-up");
725  } else {
726    filterBlock.style.display = "block";
727    filterBlock.style.opacity = 0;
728    filterBlock.style.height = "auto";
729
730    var obj_children_height = filterBlock.offsetHeight;
731    filterBlock.style.height = 0;
732
733    new BX.easing({
734      duration: 300,
735      start: { opacity: 0, height: 0 },
736      finish: { opacity: 1, height: obj_children_height },
737      transition: BX.easing.transitions.quart,
738      step: function (state) {
739        filterBlock.style.opacity = state.opacity;
740        filterBlock.style.height = state.height + "px";
741      },
742      complete: function () {},
743    }).animate();
744
745    BX.addClass(obj, "bx-active");
746    BX.removeClass(propAngle, "fa-angle-down");
747    BX.addClass(propAngle, "fa-angle-up");
748  }
749};
750
751JCSmartFilter.prototype.showDropDownPopup = function (element, popupId) {
752  const dropDownID = "smartFilterDropDown" + popupId
753  var contentNode = element.querySelector('[data-role="dropdownContent"]'),
754    offset = $(element).offset();
755  var el = BX.PopupWindowManager.create(dropDownID, element, {
756    autoHide: true,
757    offsetLeft: 0,
758    offsetTop: 0,
759    overlay: false,
760    draggable: { restrict: true },
761    closeByEsc: true,
762    content: contentNode,
763  });
764
765  if( 
766    typeof BX.PopupWindowManager._popups !== 'undefined' && 
767    BX.PopupWindowManager._popups.length && 
768    el.bindElement !== element
769  ){
770    BX.PopupWindowManager._popups = BX.PopupWindowManager._popups.filter(function(popup){
771      if (popup.uniquePopupId !== dropDownID) return;
772    });
773
774    el = BX.PopupWindowManager.create(dropDownID, element, {
775      autoHide: true,
776      offsetLeft: 0,
777      offsetTop: 0,
778      overlay: false,
779      draggable: { restrict: true },
780      closeByEsc: true,
781      content: contentNode,
782    });
783  }
784
785  if (popupId == "ASPRO_FILTER_SORT") {
786    window.sortFilterPopup = el;
787  }
788
789  el.show();
790
791  $("#smartFilterDropDown" + popupId).insertAfter($(element).closest(".bx_filter_parameters_box_container"));
792
793  $("#smartFilterDropDown" + popupId)
794    .addClass("scrollblock")
795    .css({ top: "auto", left: "auto" /*, 'width':$(element).css('width')*/ });
796  InitScrollBar();
797};
798
799JCSmartFilter.prototype.selectDropDownItem = function (element, controlId) {
800  if (!BX.hasClass(element, "disabled")) {
801    this.keyup(BX(controlId));
802
803    var wrapContainer = BX.findParent(BX(controlId), { className: "bx_filter_select_container" }, false);
804
805    var currentOption = wrapContainer.querySelector('[data-role="currentOption"]');
806
807    currentOption.innerHTML = element.innerHTML;
808    $(element).closest(".bx_filter_select_popup").find("label").removeClass("selected");
809    BX.addClass(element, "selected");
810
811    if (BX.PopupWindowManager.getCurrentPopup()) BX.PopupWindowManager.getCurrentPopup().close();
812  }
813};
814
815BX.namespace("BX.Iblock.SmartFilter");
816BX.Iblock.SmartFilter = (function () {
817  var SmartFilter = function (arParams) {
818    if (typeof arParams === "object") {
819      this.leftSlider = BX(arParams.leftSlider);
820      this.rightSlider = BX(arParams.rightSlider);
821      this.tracker = BX(arParams.tracker);
822      this.trackerWrap = BX(arParams.trackerWrap);
823
824      this.minInput = BX(arParams.minInputId);
825      this.maxInput = BX(arParams.maxInputId);
826
827      this.minPrice = parseFloat(arParams.minPrice);
828      this.maxPrice = parseFloat(arParams.maxPrice);
829
830      this.curMinPrice = parseFloat(arParams.curMinPrice);
831      this.curMaxPrice = parseFloat(arParams.curMaxPrice);
832
833      this.fltMinPrice = arParams.fltMinPrice ? parseFloat(arParams.fltMinPrice) : parseFloat(arParams.curMinPrice);
834      this.fltMaxPrice = arParams.fltMaxPrice ? parseFloat(arParams.fltMaxPrice) : parseFloat(arParams.curMaxPrice);
835
836      this.precision = arParams.precision || 0;
837
838      this.priceDiff = this.maxPrice - this.minPrice;
839
840      this.leftPercent = arParams.leftPercent ? parseFloat(arParams.leftPercent) : 0;
841      this.rightPercent = arParams.rightPercent ? parseFloat(arParams.rightPercent) : 0;
842
843      this.fltMinPercent = 0;
844      this.fltMaxPercent = 0;
845
846      this.colorUnavailableActive = BX(arParams.colorUnavailableActive); //gray
847      this.colorAvailableActive = BX(arParams.colorAvailableActive); //blue
848      this.colorAvailableInactive = BX(arParams.colorAvailableInactive); //light blue
849
850      this.isTouch = false;
851
852      this.init();
853
854      if ("ontouchstart" in document.documentElement || "ontouchstart" in window) {
855        this.isTouch = true;
856
857        BX.bind(
858          this.leftSlider,
859          "touchstart",
860          BX.proxy(function (event) {
861            this.onMoveLeftSlider(event);
862          }, this)
863        );
864
865        BX.bind(
866          this.rightSlider,
867          "touchstart",
868          BX.proxy(function (event) {
869            this.onMoveRightSlider(event);
870          }, this)
871        );
872
873        BX.bind(
874          this.colorAvailableActive,
875          "touchstart",
876          BX.proxy(function (event) {
877            this.onChangeLeftSlider(event);
878          }, this)
879        );
880
881        BX.bind(
882          this.colorUnavailableActive,
883          "touchstart",
884          BX.proxy(function (event) {
885            this.onChangeLeftSlider(event);
886          }, this)
887        );
888
889        BX.bind(
890          this.colorAvailableInactive,
891          "touchstart",
892          BX.proxy(function (event) {
893            this.onChangeLeftSlider(event);
894          }, this)
895        );
896      } else {
897        BX.bind(
898          this.leftSlider,
899          "mousedown",
900          BX.proxy(function (event) {
901            this.onMoveLeftSlider(event);
902          }, this)
903        );
904
905        BX.bind(
906          this.rightSlider,
907          "mousedown",
908          BX.proxy(function (event) {
909            this.onMoveRightSlider(event);
910          }, this)
911        );
912
913        BX.bind(
914          this.colorAvailableActive,
915          "mousedown",
916          BX.proxy(function (event) {
917            this.onChangeLeftSlider(event);
918          }, this)
919        );
920
921        BX.bind(
922          this.colorUnavailableActive,
923          "mousedown",
924          BX.proxy(function (event) {
925            this.onChangeLeftSlider(event);
926          }, this)
927        );
928
929        BX.bind(
930          this.colorAvailableInactive,
931          "mousedown",
932          BX.proxy(function (event) {
933            this.onChangeLeftSlider(event);
934          }, this)
935        );
936      }
937
938      BX.bind(
939        this.minInput,
940        "keyup",
941        BX.proxy(function (event) {
942          this.onInputChange();
943        }, this)
944      );
945
946      BX.bind(
947        this.maxInput,
948        "keyup",
949        BX.proxy(function (event) {
950          this.onInputChange();
951        }, this)
952      );
953    }
954  };
955
956  SmartFilter.prototype.init = function () {
957    var priceDiff;
958
959    if (this.curMinPrice > this.minPrice) {
960      priceDiff = this.curMinPrice - this.minPrice;
961      this.leftPercent = (priceDiff * 100) / this.priceDiff;
962
963      this.leftSlider.style.left = this.leftPercent + "%";
964      this.colorUnavailableActive.style.left = this.leftPercent + "%";
965    }
966
967    this.setMinFilteredValue(this.fltMinPrice);
968
969    if (this.curMaxPrice < this.maxPrice) {
970      priceDiff = this.maxPrice - this.curMaxPrice;
971      this.rightPercent = (priceDiff * 100) / this.priceDiff;
972
973      this.rightSlider.style.right = this.rightPercent + "%";
974      this.colorUnavailableActive.style.right = this.rightPercent + "%";
975    }
976
977    this.setMaxFilteredValue(this.fltMaxPrice);
978  };
979
980  SmartFilter.prototype.setMinFilteredValue = function (fltMinPrice) {
981    if (this.colorAvailableInactive) {
982      this.fltMinPrice = parseFloat(fltMinPrice);
983      if (this.fltMinPrice >= this.minPrice) {
984        var priceDiff = this.fltMinPrice - this.minPrice;
985        this.fltMinPercent = (priceDiff * 100) / this.priceDiff;
986
987        if (this.leftPercent > this.fltMinPercent) this.colorAvailableActive.style.left = this.leftPercent + "%";
988        else this.colorAvailableActive.style.left = this.fltMinPercent + "%";
989
990        this.colorAvailableInactive.style.left = this.fltMinPercent + "%";
991      } else {
992        this.colorAvailableActive.style.left = "0%";
993        this.colorAvailableInactive.style.left = "0%";
994      }
995    }
996  };
997
998  SmartFilter.prototype.setMaxFilteredValue = function (fltMaxPrice) {
999    if (this.colorAvailableInactive) {
1000      this.fltMaxPrice = parseFloat(fltMaxPrice);
1001      if (this.fltMaxPrice <= this.maxPrice) {
1002        var priceDiff = this.maxPrice - this.fltMaxPrice;
1003        this.fltMaxPercent = (priceDiff * 100) / this.priceDiff;
1004
1005        if (this.rightPercent > this.fltMaxPercent) this.colorAvailableActive.style.right = this.rightPercent + "%";
1006        else this.colorAvailableActive.style.right = this.fltMaxPercent + "%";
1007
1008        this.colorAvailableInactive.style.right = this.fltMaxPercent + "%";
1009      } else {
1010        this.colorAvailableActive.style.right = "0%";
1011        this.colorAvailableInactive.style.right = "0%";
1012      }
1013    }
1014  };
1015
1016  SmartFilter.prototype.getXCoord = function (elem) {
1017    var box = elem.getBoundingClientRect();
1018    var body = document.body;
1019    var docElem = document.documentElement;
1020
1021    var scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft;
1022    var clientLeft = docElem.clientLeft || body.clientLeft || 0;
1023    var left = box.left + scrollLeft - clientLeft;
1024
1025    return Math.round(left);
1026  };
1027
1028  SmartFilter.prototype.getPageX = function (e) {
1029    e = e || window.event;
1030    var pageX = null;
1031
1032    if (this.isTouch && e.targetTouches[0] != null) {
1033      pageX = e.targetTouches[0].pageX;
1034    } else if (e.pageX != null) {
1035      pageX = e.pageX;
1036    } else if (e.clientX != null) {
1037      var html = document.documentElement;
1038      var body = document.body;
1039
1040      pageX = e.clientX + (html.scrollLeft || (body && body.scrollLeft) || 0);
1041      pageX -= html.clientLeft || 0;
1042    }
1043
1044    return pageX;
1045  };
1046
1047  SmartFilter.prototype.recountMinPrice = function () {
1048    var newMinPrice = (this.priceDiff * this.leftPercent) / 100;
1049    newMinPrice = (this.minPrice + newMinPrice).toFixed(this.precision);
1050
1051    if (newMinPrice != this.minPrice) this.minInput.value = newMinPrice;
1052    else this.minInput.value = "";
1053    smartFilter.keyup(this.minInput);
1054  };
1055
1056  SmartFilter.prototype.recountMaxPrice = function () {
1057    var newMaxPrice = (this.priceDiff * this.rightPercent) / 100;
1058    newMaxPrice = (this.maxPrice - newMaxPrice).toFixed(this.precision);
1059
1060    if (newMaxPrice != this.maxPrice) this.maxInput.value = newMaxPrice;
1061    else this.maxInput.value = "";
1062    smartFilter.keyup(this.maxInput);
1063  };
1064
1065  SmartFilter.prototype.onInputChange = function () {
1066    var priceDiff;
1067    if (this.minInput.value) {
1068      var leftInputValue = this.minInput.value;
1069      if (leftInputValue < this.minPrice) leftInputValue = this.minPrice;
1070
1071      if (leftInputValue > this.maxPrice) leftInputValue = this.maxPrice;
1072
1073      priceDiff = leftInputValue - this.minPrice;
1074      this.leftPercent = (priceDiff * 100) / this.priceDiff;
1075
1076      this.makeLeftSliderMove(false);
1077    }
1078
1079    if (this.maxInput.value) {
1080      var rightInputValue = this.maxInput.value;
1081      if (rightInputValue < this.minPrice) rightInputValue = this.minPrice;
1082
1083      if (rightInputValue > this.maxPrice) rightInputValue = this.maxPrice;
1084
1085      priceDiff = this.maxPrice - rightInputValue;
1086      this.rightPercent = (priceDiff * 100) / this.priceDiff;
1087
1088      this.makeRightSliderMove(false);
1089    }
1090  };
1091
1092  SmartFilter.prototype.makeLeftSliderMove = function (recountPrice) {
1093    recountPrice = recountPrice !== false;
1094
1095    this.leftSlider.style.left = this.leftPercent + "%";
1096    this.colorUnavailableActive.style.left = this.leftPercent + "%";
1097
1098    var areBothSlidersMoving = false;
1099    if (this.leftPercent + this.rightPercent >= 100) {
1100      areBothSlidersMoving = true;
1101      this.rightPercent = 100 - this.leftPercent;
1102      this.rightSlider.style.right = this.rightPercent + "%";
1103      this.colorUnavailableActive.style.right = this.rightPercent + "%";
1104    }
1105
1106    if (this.leftPercent >= this.fltMinPercent && this.leftPercent <= 100 - this.fltMaxPercent) {
1107      this.colorAvailableActive.style.left = this.leftPercent + "%";
1108      if (areBothSlidersMoving) {
1109        this.colorAvailableActive.style.right = 100 - this.leftPercent + "%";
1110      }
1111    } else if (this.leftPercent <= this.fltMinPercent) {
1112      this.colorAvailableActive.style.left = this.fltMinPercent + "%";
1113      if (areBothSlidersMoving) {
1114        this.colorAvailableActive.style.right = 100 - this.fltMinPercent + "%";
1115      }
1116    } else if (this.leftPercent >= this.fltMaxPercent) {
1117      this.colorAvailableActive.style.left = 100 - this.fltMaxPercent + "%";
1118      if (areBothSlidersMoving) {
1119        this.colorAvailableActive.style.right = this.fltMaxPercent + "%";
1120      }
1121    }
1122
1123    if (recountPrice) {
1124      this.recountMinPrice();
1125      if (areBothSlidersMoving) this.recountMaxPrice();
1126    }
1127  };
1128
1129  SmartFilter.prototype.countNewLeft = function (event) {
1130    var pageX = this.getPageX(event);
1131
1132    var trackerXCoord = this.getXCoord(this.trackerWrap);
1133    var rightEdge = this.trackerWrap.offsetWidth;
1134
1135    var newLeft = pageX - trackerXCoord;
1136
1137    if (newLeft < 0) newLeft = 0;
1138    else if (newLeft > rightEdge) newLeft = rightEdge;
1139
1140    return newLeft;
1141  };
1142
1143  SmartFilter.prototype.onMoveLeftSlider = function (e) {
1144    if (!this.isTouch) {
1145      this.leftSlider.ondragstart = function () {
1146        return false;
1147      };
1148    }
1149
1150    $(".bx_filter .bx_filter_parameters_box_container input").prop("disabled", false);
1151
1152    if (!this.isTouch) {
1153      document.onmousemove = BX.proxy(function (event) {
1154        this.leftPercent = (this.countNewLeft(event) * 100) / this.trackerWrap.offsetWidth;
1155        this.makeLeftSliderMove();
1156      }, this);
1157
1158      document.onmouseup = function () {
1159        document.onmousemove = document.onmouseup = null;
1160      };
1161    } else {
1162      var onMoveFunction = BX.proxy(function (event) {
1163        this.leftPercent = (this.countNewLeft(event) * 100) / this.trackerWrap.offsetWidth;
1164        this.makeLeftSliderMove();
1165      }, this);
1166
1167      var onEndFunction = BX.proxy(function (event) {
1168        window.removeEventListener("touchmove", onMoveFunction, false);
1169        window.removeEventListener("touchend", onEndFunction, false);
1170        onMoveFunction = onEndFunction = null;
1171      }, this);
1172
1173      window.addEventListener("touchmove", onMoveFunction, false);
1174      window.addEventListener("touchend", onEndFunction, false);
1175
1176      /*document.ontouchmove = BX.proxy(function(event) {
1177					this.leftPercent = ((this.countNewLeft(event)*100)/this.trackerWrap.offsetWidth);
1178					this.makeLeftSliderMove();
1179				}, this);
1180
1181				document.ontouchend = function() {
1182					document.ontouchmove = document.touchend = null;
1183				};*/
1184    }
1185
1186    return false;
1187  };
1188
1189  SmartFilter.prototype.makeRightSliderMove = function (recountPrice) {
1190    recountPrice = recountPrice !== false;
1191
1192    this.rightSlider.style.right = this.rightPercent + "%";
1193    this.colorUnavailableActive.style.right = this.rightPercent + "%";
1194
1195    var areBothSlidersMoving = false;
1196    if (this.leftPercent + this.rightPercent >= 100) {
1197      areBothSlidersMoving = true;
1198      this.leftPercent = 100 - this.rightPercent;
1199      this.leftSlider.style.left = this.leftPercent + "%";
1200      this.colorUnavailableActive.style.left = this.leftPercent + "%";
1201    }
1202
1203    if (100 - this.rightPercent >= this.fltMinPercent && this.rightPercent >= this.fltMaxPercent) {
1204      this.colorAvailableActive.style.right = this.rightPercent + "%";
1205      if (areBothSlidersMoving) {
1206        this.colorAvailableActive.style.left = 100 - this.rightPercent + "%";
1207      }
1208    } else if (this.rightPercent <= this.fltMaxPercent) {
1209      this.colorAvailableActive.style.right = this.fltMaxPercent + "%";
1210      if (areBothSlidersMoving) {
1211        this.colorAvailableActive.style.left = 100 - this.fltMaxPercent + "%";
1212      }
1213    } else if (100 - this.rightPercent <= this.fltMinPercent) {
1214      this.colorAvailableActive.style.right = 100 - this.fltMinPercent + "%";
1215      if (areBothSlidersMoving) {
1216        this.colorAvailableActive.style.left = this.fltMinPercent + "%";
1217      }
1218    }
1219
1220    if (recountPrice) {
1221      this.recountMaxPrice();
1222      if (areBothSlidersMoving) this.recountMinPrice();
1223    }
1224  };
1225
1226  SmartFilter.prototype.onMoveRightSlider = function (e) {
1227    if (!this.isTouch) {
1228      this.rightSlider.ondragstart = function () {
1229        return false;
1230      };
1231    }
1232
1233    $(".bx_filter .bx_filter_parameters_box_container input").prop("disabled", false);
1234
1235    if (!this.isTouch) {
1236      document.onmousemove = BX.proxy(function (event) {
1237        this.rightPercent = 100 - (this.countNewLeft(event) * 100) / this.trackerWrap.offsetWidth;
1238        this.makeRightSliderMove();
1239      }, this);
1240
1241      document.onmouseup = function () {
1242        document.onmousemove = document.onmouseup = null;
1243      };
1244    } else {
1245      document.ontouchmove = BX.proxy(function (event) {
1246        this.rightPercent = 100 - (this.countNewLeft(event) * 100) / this.trackerWrap.offsetWidth;
1247        this.makeRightSliderMove();
1248      }, this);
1249
1250      document.ontouchend = function () {
1251        document.ontouchmove = document.ontouchend = null;
1252      };
1253    }
1254
1255    return false;
1256  };
1257
1258  SmartFilter.prototype.onChangeLeftSlider = function (e) {
1259    if (!this.isTouch) {
1260      this.leftSlider.ondragstart = function () {
1261        //return false;
1262      };
1263    }
1264
1265    if (!this.isTouch) {
1266      // document.onmousedown = BX.proxy(function(event) {
1267      var percent = (this.countNewLeft(event) * 100) / this.trackerWrap.offsetWidth;
1268      if ($(event.target).is(".bx_ui_slider_handle") || !$(event.target).is("[class^=bx_ui_slider]")) return;
1269      if (percent < 50) {
1270        this.leftPercent = percent + 1;
1271        this.makeLeftSliderMove();
1272      } else {
1273        this.rightPercent = 100 - percent;
1274        this.makeRightSliderMove();
1275      }
1276      // }, this);
1277
1278      document.onmouseup = function () {
1279        document.onmousemove = document.onmouseup = null;
1280      };
1281    } else {
1282      var percent = (this.countNewLeft(e) * 100) / this.trackerWrap.offsetWidth;
1283      if ($(e.target).is(".bx_ui_slider_handle")) return;
1284      if (percent < 50) {
1285        this.leftPercent = percent;
1286        this.makeLeftSliderMove();
1287      } else {
1288        this.rightPercent = 100 - percent;
1289        this.makeRightSliderMove();
1290      }
1291
1292      /*document.ontouchend = BX.proxy(function(event) {
1293					var percent=((this.countNewLeft(event)*100)/this.trackerWrap.offsetWidth);
1294					if($(event.target).is(".bx_ui_slider_handle"))
1295						return;
1296					if(percent<50){
1297						this.leftPercent = percent;
1298						this.makeLeftSliderMove();
1299					}else{
1300						this.rightPercent = 100-percent;
1301						this.makeRightSliderMove();
1302					}
1303				}, this);
1304
1305				document.ontouchend = function() {
1306					document.ontouchmove = document.touchend = null;
1307				};*/
1308    }
1309
1310    return false;
1311  };
1312
1313  return SmartFilter;
1314})();

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.