PageSourceSearch

https://www.eraled.sk/catalog/view/javascript/brainyfilter.js

js eraled.sk collected 2026-10-06 13:15:50 UTC 58,175 bytes, 1,312 lines download raw bytes

1/**
2 * Brainy Filter Ultimate 5.1.6 OC3, September 10, 2019 / brainyfilter.com 
3 * Copyright 2015-2019 Giant Leap Lab / www.giantleaplab.com 
4 * License: Commercial. Reselling of this software or its derivatives is not allowed. You may use this software for one website ONLY including all its subdomains if the top level domain belongs to you and all subdomains are parts of the same OpenCart store. 
5 * Support: http://support.giantleaplab.com
6 */
7(function($){
8    
9if (typeof BrainyFilter === 'undefined') {
10    var BrainyFilter = {
11
12        ajaxHandler: null,
13
14        sliderId: ".bf-slider-range",
15
16        filterFormId: ".bf-form",
17
18        maxFieldId: "[name='bfp_price_max']",
19
20        minFieldId: "[name='bfp_price_min']",
21
22        max: 0,
23        min: 0,
24        lowerValue : 0,
25        higherValue : 0,
26
27        timeout: null,
28
29        urlSeparators: null,
30
31        selectionCache: {},
32
33        ajaxEnabled: true,
34
35        requestCount : false,
36        requestPrice : false,
37        separateCountRequest : false,
38
39        redirectTo: '',
40        baseUrl: '',
41        currentRoute: '',
42        
43        isInitialized: false,
44
45        init: function() {
46            this.isInitialized = true;
47            this.ajaxEnabled = !isIE() && $(this.selectors.container).size() 
48                                       && $(this.selectors.paginator).size();
49            this.redirectTo = this.redirectTo.replace('&', '&');
50
51            $(this.sliderId).each(function(){
52                var $slider = $(this),
53                    sliderType = parseInt($slider.data('slider-type'));
54                $slider[0].slide = null;
55                $slider.slider({
56                    range: true,
57                    min: BrainyFilter.min,
58                    max: BrainyFilter.max,
59                    values: [BrainyFilter.lowerValue, BrainyFilter.higherValue],
60                    slide: function( event, ui ) {
61                        $(BrainyFilter.minFieldId).val(ui.values[0]);
62                        $(BrainyFilter.maxFieldId).val(ui.values[1]);
63                    },
64                    stop : function(){ BrainyFilter.currentSendMethod($(this)); }
65                });
66                if (sliderType === 2 || sliderType === 3) {
67                    BrainyFilter.priceSliderLabels($slider);
68                }
69            });
70            
71            $('.bf-price-container input').keyup(function() {
72                var $inp = $(this), 
73                    index = ($inp.hasClass("bf-range-max")) ? 1 : 0;
74                (index) ? $(".bf-range-max").val($inp.val()) 
75                        : $(".bf-range-min").val($inp.val());
76                $(BrainyFilter.sliderId).slider("values", index, $inp.val());
77            });
78            $('.bf-search-container input').keyup(function(e) {
79                var code = e.keyCode || e.which;
80                if (code === 13) {
81                    e.preventDefault();
82                    BrainyFilter.sendRequest();
83                    $(document).one('bfFloatButton.show', function(){
84                        $('.bf-float-submit').hide();
85                    });
86                } else {
87                    //BrainyFilter.currentSendMethod();
88                }
89            });
90
91            try {
92                this.initSliders();
93            } catch(e) {
94                console.log(e);
95            }
96
97            if ((this.requestCount || this.requestPrice) && this.separateCountRequest) {
98                this.getTotalByAttr();
99            } else if (this.requestCount) {
100                BrainyFilter.hideEmptySections();
101            }
102
103            $(this.filterFormId).find('select, input').change(function(){
104                var fid = $(this).data('filterid');
105                if (fid) {
106                    var $input = $('input[data-filterid='+fid+']');
107                    if ($(this)[0].checked) {
108                        $input.attr('checked', 'checked');
109                    } else {
110                        $input.removeAttr('checked');
111                    }
112                }
113                BrainyFilter.currentSendMethod($(this));
114            });
115
116            $(this.filterFormId).find('input[type="checkbox"], input[type="radio"]').change(function(){
117                if (!$(this).closest('.bf-attr-filter').find('.bf-count').size()) {
118                    BrainyFilter.addCross($(this));
119                }
120            });
121
122            $(this.filterFormId).find('input[type="checkbox"], input[type="radio"]').each(function(i,v){
123                BrainyFilter.addCross($(v));
124            });
125            
126            $(this.filterFormId).find('option[data-totals]').each(function(){
127                var totals = $(this).data('totals');
128                $(this).append('<span> (' + totals + ')</span>');
129            });
130
131            this.floatSubmit();
132
133            $(this.filterFormId).submit(function(){
134//                BrainyFilter.sendRequest();
135                return false;
136            });
137
138            this.selectionCache = this.serializeMultipleForms();
139
140            this.initSliding();
141
142            this.initGrid();
143
144            this.rebindSearchAction();
145
146            this.collapse();
147            
148            this.initHorizontalView();
149
150            this.initAbsolutePosition();
151            
152            this.addBFilterParam();
153            
154            window.onpopstate = function() {
155                window.location.reload();
156            };
157        },
158
159        initSliders : function() {
160            $('.bf-slider-container').each(function(){
161                var $slider = $(this),
162                    sliderType = parseInt($slider.data('slider-type')),
163                    $cont = $slider.closest('.bf-attr-filter'),
164                    id = $slider.data('slider-group'),
165                    $s = $('[data-slider-group='+id+']').not($slider).closest('.bf-attr-filter'),
166                    minInp = $cont.find('[data-min-limit]'),
167                    maxInp = $cont.find('[data-max-limit]'),
168                    minLbl = $cont.find('.bf-slider-text-inp-min'),
169                    maxLbl = $cont.find('.bf-slider-text-inp-max'),
170                    labels = BrainyFilter.sliderValues[id].slice(0),
171                    values = [NaN, NaN];
172                    var v1 = parseInt(minInp.val()),
173                        v2 = parseInt(maxInp.val());
174                    for (var i=0; i < labels.length; i++) {
175                        if (parseInt(labels[i].s) === v1) {
176                            values[0] = i + 1;
177                        }
178                        if (parseInt(labels[i].s) === v2) {
179                            values[1] = i + 1;
180                        }
181                    }
182                    //values = [parseInt(minInp.val()) + 1, parseInt(maxInp.val()) + 1];
183                    labels.splice(0, 0, {n:''});
184                    labels.splice(labels.length, 0, {n:''});
185                    values[0] = isNaN(values[0]) ? 0 : values[0];
186                    values[1] = isNaN(values[1]) ? labels.length - 1 : values[1];
187                    
188                $slider.slider({
189                    range: true,
190                    min: 0,
191                    max: labels.length - 1,
192                    values: values,
193                    slide: function(e, ui) {
194                        minInp.val(labels[ui.values[0]].s);
195                        maxInp.val(labels[ui.values[1]].s);
196                        minLbl.attr('value', labels[ui.values[0]].n).val(labels[ui.values[0]].n);
197                        maxLbl.attr('value', labels[ui.values[1]].n).val(labels[ui.values[1]].n);
198                        $s.find('[data-min-limit]').val(labels[ui.values[0]].s);
199                        $s.find('[data-max-limit]').val(labels[ui.values[1]].s);
200                        var sMinLbl = $s.find('.bf-slider-text-inp-min'),
201                            sMaxLbl = $s.find('.bf-slider-text-inp-max');
202                        sMinLbl.val(labels[ui.values[0]].n);
203                        sMaxLbl.val(labels[ui.values[1]].n);
204                        $s.find('.bf-slider-container').slider('option', 'values', ui.values);
205                    },
206                    stop : function(){ BrainyFilter.currentSendMethod($(this)); }
207                });
208                
209                var changeSlider = function(){
210                    var $slider = $(this).closest('.bf-attr-filter').find('.bf-slider-container'),
211                        id = $slider.data('slider-group'),
212                        val = $(this).val(),
213                        target = $(this).hasClass('bf-slider-text-inp-min') ? 'min' : 'max',
214                        fVal = -1;
215                    for (var i = 0; i < labels.length; i++) {
216                        if (labels[i].n === val) {
217                            fVal = i;
218                            break;
219                        }
220                    }
221                    if (fVal !== -1) {
222                        if (target === 'min') {
223                            minInp.val(labels[fVal].s);
224                            $slider.slider("values", 0, fVal);
225                        } else {
226                            maxInp.val(labels[fVal].s);
227                            $slider.slider("values", 1, (fVal) ? fVal : labels.length - 1);
228                        }
229                    }
230                };
231                minLbl.keyup(changeSlider);
232                maxLbl.keyup(changeSlider);
233                
234                if (sliderType === 2 || sliderType === 3) {
235                    BrainyFilter.addSliderLabels($slider, labels);
236                }
237            });
238        },
239
240        initGrid : function() {
241            $('.bf-grid input').each(function(){ 
242                var sel = function(el){
243                    if (el.is(':checked')) {
244                        el.closest('.bf-grid').find('.bf-grid-item').removeClass('selected');
245                        el.closest('.bf-grid-item').addClass('selected');
246                    }
247                };
248                $(this).change(function(){ sel( $(this) ); });
249                sel( $(this) );
250            });
251        },
252
253        addCross: function($obj) {
254            var fid = $obj.data('filterid');
255
256            $('input[data-filterid='+fid+']').each(function(){
257                var checkbox = $(this);
258                var parent = checkbox.closest('.bf-attr-filter');
259                if($obj[0].checked) { 
260                    if (checkbox.is("input[type='radio']")) {
261                        checkbox.parents('.bf-attr-block').find('.bf-cross').remove();
262                    }
263                    var cross = $('<span class="bf-cross" data-filterid="'+fid+'"></span>');
264                    cross.click(function(){
265                        var fid = $(this).data('filterid');
266                        var $cross = $('.bf-cross[data-filterid='+fid+']');
267                        $cross.closest('.bf-attr-filter').find('input').removeAttr('checked');
268                        BrainyFilter.currentSendMethod($(this));
269                        $cross.hide();
270                        setTimeout(function(){$cross.remove();}, 500);
271                    });
272                    parent.find('.bf-c-3').html(cross);
273                    checkbox.attr('checked', 'checked');
274                    checkbox[0].checked = true;
275                } else {
276                    parent.find('.bf-cross').remove();
277                    if (checkbox[0].checked) {
278                        checkbox.removeAttr('checked');
279                    }
280                }
281            });
282        },
283
284        reset: function() {
285            if ($('.bf-buttonclear').is('[disabled]')) {
286                return;
287            }
288            $('.bf-slider-container').each(function(){
289                var $slider = $(this),
290                    $cont = $slider.closest('.bf-attr-filter'),
291                    minInp = $cont.find('[data-min-limit]'),
292                    maxInp = $cont.find('[data-max-limit]'),
293                    minLbl = $cont.find('.bf-slider-text-inp-min'),
294                    maxLbl = $cont.find('.bf-slider-text-inp-max'),
295                    values = [0, $slider.slider('option', 'max')];
296                $slider.slider('option', 'values', values);
297                minInp.val(values[0]);
298                maxInp.val(values[1]);
299                minLbl.val('').attr('value', '');
300                maxLbl.val('').attr('value', '');
301            });
302            $(this.filterFormId + ' .bf-search-container input').val('');
303            $(this.sliderId).slider("option", "values", [this.min, this.max]);
304            $(this.filterFormId + ' ' + this.minFieldId).val(this.min);
305            $(this.filterFormId + ' ' + this.maxFieldId).val(this.max);
306            $(this.filterFormId + ' input').filter(':checkbox, :radio').removeAttr('checked');
307            $(this.filterFormId + ' option').removeAttr('selected');
308            $(this.filterFormId + ' option.bf-default').attr('selected', 'true');
309            $(this.filterFormId).find('.bf-cross').remove();
310            this.sendRequest();
311            var disableBtn = function() {
312                $('.bf-buttonclear').attr('disabled', 'disabled');
313                $(document).ajaxStop(enableBtn);
314            };
315            var enableBtn  = function() {
316                $(document).unbind('ajaxStart', disableBtn);
317                $(document).unbind('ajaxStop', enableBtn);
318                $('.bf-buttonclear').removeAttr('disabled');
319            };
320            $(document).ajaxStart(disableBtn);
321        },
322
323        currentSendMethod: function($elem){
324            var submitType = $elem.closest(BrainyFilter.filterFormId).data('submit-type');
325            var submitDelay = $elem.closest(BrainyFilter.filterFormId).data('submit-delay');
326            switch(submitType) {
327                case 'auto':
328                    BrainyFilter.sendRequest();
329                    break;
330                case 'delay':
331                    if (BrainyFilter.timeout) {
332                        clearTimeout(BrainyFilter.timeout);
333                    }
334                    BrainyFilter.timeout = setTimeout(BrainyFilter.sendRequest, submitDelay);
335                    break;
336                default:
337                    break;
338            }
339        },
340
341        sendRequest: function() {
342            if (BrainyFilter.ajaxEnabled) {
343
344                // hide results until response will be recieved
345                if(parseInt($('.bf-form').data('submit-hide-panel'))) {
346                    $('.bf-panel-wrapper').addClass('bf-panel-hidden');
347                }
348                $('.bf-panel-wrapper').append('<div class="ajax-shadow"></div>');
349                
350                if(this.ajaxHandler && this.ajaxHandler.readystate !== 4){
351                    this.ajaxHandler.abort();
352                }
353
354                this.ajaxHandler = $.ajax({
355                    url: window.location.origin + BrainyFilter.baseUrl +'index.php' 
356                            + BrainyFilter.prepareFilterData(false, 'extension/module/brainyfilter/ajaxfilter') 
357                            + '&count=' + (BrainyFilter.requestCount ? '1' : '0')
358                            + '&price=' + (BrainyFilter.requestPrice ? '1' : '0')
359                            + '&withContent=1'
360                            + '&curRoute=' + BrainyFilter.currentRoute,
361                    dataType:'json',
362                    type: 'get',
363                    success: function(res) {
364                        if (res) {
365                            BrainyFilter.updateProductList(res.products, res.brainyfilter);
366                        }
367                        $(BrainyFilter.filterFormId).find('input[type="checkbox"], input[type="radio"]').each(function(i,v){
368                            BrainyFilter.addCross($(v));
369                        });
370                        var newUrl   = window.location.origin + BrainyFilter.prepareFilterData(true, false);
371
372                        if ($(BrainyFilter.sliderId).size()) {
373                            BrainyFilter.changePriceSlider(res.min, res.max);
374                        };
375                        
376                        BrainyFilter.historyPushState(res, newUrl);
377
378                        BrainyFilter.selectionCache = BrainyFilter.serializeMultipleForms();
379                        
380                        $(document).trigger('productlistchange');
381                    },
382                    complete: function() {
383                        $('.bf-panel-wrapper .ajax-shadow').remove();
384                        $('.bf-panel-wrapper').removeClass('bf-panel-hidden');
385                    }
386                }); 
387            }else{
388                var newUrl;
389                if (BrainyFilter.redirectTo) {
390                    newUrl = BrainyFilter.redirectTo + (BrainyFilter.redirectTo.match(/\?/) ? '&' : '?') + BrainyFilter.serializeFilterForm();
391                } else {
392                    newUrl = window.location.origin + BrainyFilter.prepareFilterData(true);
393                }
394                window.location = newUrl;
395            }
396        }, 
397        
398        updateProductList: function(html, bfData) {
399            var $gridBtn = $('#grid-view').clone(true), 
400                $listBtn = $('#list-view').clone(true),
401                $html    = $(html),
402                $prodCont = $html.find(BrainyFilter.selectors.container),
403                $paginCont = $html.find(BrainyFilter.selectors.paginator),
404                $emptyMsg = $('<p/>', {'class': 'bf-empty-product-list-msg'}).html(bfLang.empty_list)
405                ;
406
407            if ($prodCont.size()) {
408                $(BrainyFilter.selectors.container).html($prodCont.html());
409                $(BrainyFilter.selectors.paginator).html($paginCont.html());
410            } else {
411                $(BrainyFilter.selectors.container).html($emptyMsg);
412                $(BrainyFilter.selectors.paginator).html('');
413            }
414            
415            BrainyFilter.addBFilterParam();
416            
417            $('#grid-view').replaceWith($gridBtn);
418            $('#list-view').replaceWith($listBtn);
419            try {
420                if (typeof display === 'function') {
421                    if (typeof $.totalStorage !== 'undefined') {
422                        display($.totalStorage('display'));
423                    } else if (typeof $.cookie !== 'undefined'){
424                        display($.cookie('display')); 
425                    }
426                } else
427                if (typeof dataAnimate === 'function') { //support for Boss Themes animation
428                    dataAnimate();
429                } else {
430                    if (typeof localStorage.getItem === 'function' && localStorage.getItem('display') === 'list') {
431                        $listBtn.trigger('click');
432                    } else {
433                        $gridBtn.trigger('click');
434                    }
435                }
436            } catch(e) {
437                console.log('Brainy Filter - call of display() failed: ' + e);
438            }
439            if (BrainyFilter.requestCount) {
440                BrainyFilter.changeTotalNumbers(bfData);
441            }
442            BrainyFilter.initSliding();
443            BrainyFilter.hideEmptySections();
444            BrainyFilter.initHorizontalScrolls();
445            if (typeof infscrl != 'undefined') infscrl.initjson();
446        },
447        
448        historyPushState: function(data, url) {
449           window.history.pushState({brainyfilter: true}, document.title, url);
450        },
451        
452        addBFilterParam: function() {
453            var self = BrainyFilter,
454                bfilter = BrainyFilter.serializeFilterForm();
455            $.fn.bfparam = function(bfparam){
456                this.each(function(){
457                    var $this = $(this), attr = $this.is('[value]') ? 'value' : 'href',
458                        url = $(this).attr(attr);
459                    if(typeof url !== 'undefined') {
460                        url = url.replace(/[\?\&](bfilter|manufacturer_id|search|category_id)\=[^\&]+/g, '');
461                        if (bfparam !== '') {
462                            url += /\?/.test(url) ? '&' : '?';
463                            url += bfilter;
464                        }
465                        $this.attr(attr, url);
466                    }
467                });
468                return this;
469            };
470            $('body').find('option[value^="http"]').bfparam(bfilter);
471            $(self.selectors.paginator).find('a').bfparam(bfilter);
472        },
473
474        prepareFilterData: function(full, route) {
475            var path, query;
476            var nRoute = '';
477            var nPath  = '';
478            var str = window.location.search;
479            if (str.match(/[\?\&]route\=/)) {
480                var nRoute = str.replace(/(.*)([\?\&])(route\=)([^\&]+)(.*)/, '$4');
481            }
482            if (str.match(/[?\&]path\=/)) {
483                var nPath  = str.replace(/(.*)([\?\&])(path\=)([^\&]+)(.*)/, '$4');
484            }
485            path  = window.location.pathname;
486            query = window.location.search.replace(/[\&\?]+((route)|(path)|(page)|(bfilter)|(search)|(category_id)|(sub_category)|(description)|(manufacturer_id))[^&]+/g, '');
487
488            $(this.filterFormId).find('.bf-disabled input').removeAttr('disabled');
489
490            var form  = this.serializeMultipleForms();
491
492            $(this.filterFormId).find('.bf-disabled input').attr('disabled', 'disabled');
493            form = '&' + form;
494
495            if (route) {
496                form = form.replace(/[\&](route)=[^\&]+/g, '').replace(/[\&]+$/, '');
497                form = 'route=' + route + form;
498            } else {
499                form = form.replace(/[\&](route|path|manufacturer_id)=[^\&]+/g, '').replace(/[\&]+$/, '');
500                if (nPath !== '') {
501                    form = 'path=' + nPath + form;
502                }
503                if (nRoute !== '') {
504                    form = 'route=' + nRoute + '&' + form;
505                }
506            }
507
508            var str= window.location.toString();
509            str = str.match(/[\?\&]route\=/);
510            if (full === true && !str) {
511                form = form.replace(/[\&\?]((route)|(path))[^&]+/g, '');
512            }
513
514            form = form.replace(/[\&]bfp_[^\=]+\=[^\&]*/g, '');
515
516            var bfilter = this.serializeFilterForm();
517
518            if (form !== '') {
519                query = query + (query === '' ? '' : '&') + form;
520            }
521            if (bfilter !== '') {
522                query = query + (query === '' ? '' : '&') + bfilter;
523            }
524            query = '?' + query.replace(/(\?)|(^[\&])/, '').replace(/[\&]+/, '&');
525            query = query.replace(/pslimit=\d+/g,'');
526            return (full) ? path + query : query;
527        },
528
529        serializeFilterForm : function(){
530            var form  = this.serializeMultipleForms();
531
532            $(this.filterFormId).find('.bf-disabled input').attr('disabled', 'disabled');
533            form = '&' + form;
534
535            if (parseInt($(BrainyFilter.minFieldId).val()) === BrainyFilter.min) {
536                form = form.replace(/\&bfp_price_min\=[^\&]+/g, '');
537            }
538            if (parseInt($(BrainyFilter.maxFieldId).val()) === BrainyFilter.max) {
539                form = form.replace(/\&bfp_price_max\=[^\&]+/g, '');
540            }
541
542            $('.bf-slider-container').each(function(){
543                var $slider = $(this), 
544                    $cont = $slider.closest('.bf-slider'), 
545                    values = $slider.slider('option', 'values');
546                if (values[0] === 0) {
547                    var name = $cont.find('[data-min-limit]').attr('name');
548                    form = form.replace(new RegExp("\&"+name+"\=[^\&]+","g"), '');
549                }
550                if (values[1] === $slider.slider('option', 'max')) {
551                    var name = $cont.find('[data-max-limit]').attr('name');
552                    form = form.replace(new RegExp("\&"+name+"\=[^\&]+","g"), '');
553                }
554            });
555
556            var params = form.replace(/^\&/, '').split('&');
557            var bfilter = '';
558            var brandFilter = '';
559            var price = ['na', 'na'];
560            var rating = [];
561            var filters = {};
562    //        var searchFilters = {};
563            if (params.length) {
564                for (var i = 0; i < params.length; i ++) {
565                    var parts = params[i].split('=');
566                    var name = parts[0];
567                    var value = parts[1];
568                    if (name.match(/^bfp_/)) {
569                        if (value !== '') {
570                            var p = name.split('_');
571                            if (p[1] === 'price') {
572                                price[(p[2] === 'min') ? 0 : 1] = value;
573                            } else if (p[1] === 'rating') {
574                                rating.push(value);
575                            } else if (p[1] === 'min' || p[1] === 'max') {
576                                if (typeof filters[p[2]] === 'undefined') {
577                                    filters[p[2]] = {min: 'na', max: 'na'};
578                                }
579                                filters[p[2]][p[1]] = value;
580                            } else {
581                                if (typeof filters[p[1]] === 'undefined') {
582                                    filters[p[1]] = [];
583                                }
584                                filters[p[1]].push(value);
585                            }
586                        }
587                    } else if (name === 'manufacturer_id') {
588                        brandFilter = 'manufacturer_id=' + value;
589                    }
590                }
591            }
592            if (price[0] !== 'na' || price[1] !== 'na') {
593                bfilter += 'price:' + price[0] + '-' + price[1] + ';';
594            }
595            if (rating.length) {
596                bfilter += 'rating:' + rating.join(',') + ';';
597            }
598            for (var id in filters) {
599                if (filters.hasOwnProperty(id)) {
600                    if (!$.isArray(filters[id])) {
601                        bfilter += id + ':' + filters[id].min + '-' + filters[id].max + ';';
602                    } else {
603                        bfilter += id + ':' + filters[id].join(',') + ';';
604                    }
605                }
606            }
607            var output = '',
608                searchFilters = BrainyFilter.serializeSearchForm();
609            if (searchFilters !== '') {
610                output += (output === '' ? '' : '&') + searchFilters;
611            }
612            if (brandFilter) {
613                output += (output === '' ? '' : '&') + brandFilter;
614            }
615            if (bfilter !== '') {
616                output += (output === '' ? '' : '&') + 'bfilter=' + bfilter;
617            }
618            return output;
619        },
620
621        serializeMultipleForms : function() {
622            if ($(this.filterFormId).size() === 1) {
623                return $(this.filterFormId).serialize();
624            }
625            var params = $(this.filterFormId).serializeArray();
626            for (var i = 0; i < params.length; i ++) {
627                for (var j = i+1; j < params.length; j ++) {
628                    if (params[i].name === params[j].name && params[j].value !== '' && params[j].value.toLowerCase() !== 'na') {
629                        params[i].value = params[j].value;
630                        params.splice(j, 1);
631                        break;
632                    }
633                }
634            }
635            var str = '';
636            for (var i = 0; i < params.length; i ++) {
637                str += (str !== '' ? '&' : '') + params[i].name + '=' + params[i].value;
638            }
639            return str;
640        },
641
642        serializeSearchForm : function() {
643            var $search = $('#content').find('[name=search]');
644            if ($search.size() && $search.val() !== '') {
645                var str = 'search=' + encodeURIComponent($search.val());
646                var cat = $('#content').find('[name=category_id]').val();
647                if (parseInt(cat) > 0) {
648                    str += '&category_id=' + cat;
649                }
650                if ($('#content').find('[name=sub_category]:checked').size()) {
651                    str += '&sub_category=true';
652                }
653                if ($('#content').find('[name=description]:checked').size()) {
654                    str += '&description=true';
655                }
656                return str;
657            }
658            return '';
659        },
660
661        rebindSearchAction : function() {
662            $('#button-search').unbind('click')
663                .click(function(){
664                    BrainyFilter.sendRequest();
665                    return false;
666                });
667        },
668
669        getTotalByAttr: function() {
670            $.ajax({
671                url: window.location.origin + BrainyFilter.baseUrl +'index.php' 
672                            + BrainyFilter.prepareFilterData(false, 'extension/module/brainyfilter/ajaxfilter') 
673                            + '&count=' + (BrainyFilter.requestCount ? '1' : '0')
674                            + '&price=' + (BrainyFilter.requestPrice ? '1' : '0')
675                            + '&curRoute=' + BrainyFilter.currentRoute,
676                dataType:'json',
677                type: 'get',
678                success: function(res) {
679                    BrainyFilter.changeTotalNumbers(res.brainyfilter);
680                    BrainyFilter.initSliding();
681                    BrainyFilter.hideEmptySections();
682                    BrainyFilter.initHorizontalScrolls();
683                    if (typeof res.min !== 'undefined') {
684                        BrainyFilter.changePriceSlider(res.min, res.max);
685                    }
686                }
687            }); 
688        },
689
690        changeTotalNumbers: function(data) {
691            var $form = $(BrainyFilter.filterFormId).filter('.bf-with-counts');
692            $form.find('.bf-count').remove();
693            $form.find('option span').remove();
694            $form.find('select').removeAttr('disabled');
695            var $ctrls = $form.find('.bf-attr-filter')
696                .find('input, option')
697                .not(':checked')
698                .not(':selected')
699                .not('[type=text]')
700                .not('[type=hidden]')
701                .not('.bf-default'),
702                $checkedBlks = $form.find('.bf-attr-filter input[type=checkbox]')
703                .filter(':checked')
704                .parents('.bf-attr-block');
705            
706            $ctrls.attr('disabled', 'disabled')
707                .not('option')
708                .parents('.bf-attr-filter')
709                .addClass('bf-disabled');
710
711            $ctrls.each(function(){
712                var $this = $(this), 
713                name = $this.prop('tagName') === 'OPTION' ? $this.parent().attr('name') : $this.attr('name'),
714                gid  = name.replace(/(bfp_)([^_]+)(.*)/, '$2'),
715                val  = $this.attr('value');
716                if (data[gid] && data[gid][val]) {
717                    if ($this.prop('tagName') === 'OPTION') {
718                        $this.append('<span> (' + data[gid][val] + ')</span>');
719                    } else {
720                        var $row = $this.closest('.bf-attr-filter').removeClass('bf-disabled');
721                        $row.find('.bf-cell').last().append('<span class="bf-count">' + data[gid][val] + '</span>');
722                    }
723                    $this.removeAttr('disabled');
724                }
725            });
726            
727            $checkedBlks.find('.bf-disabled').each(function(){
728                var $this = $(this);
729                $this.removeClass('bf-disabled').find('.bf-cell').last().append('<span class="bf-count bf-empty">0</span>');
730                $this.find('input:disabled').removeAttr('disabled');
731            });
732            $checkedBlks.find('.bf-count').each(function(i, v){
733                var $this = $(v);
734                $this.text('+' + $this.text());
735            });
736            // disable select box if it hasn't any active option
737            $form.find('select').each(function(){
738                if ($(this).find('option').not('.bf-default,[disabled]').size() === 0) {
739                    $(this).attr('disabled', 'true');
740                }
741            });
742        },
743
744        initHorizontalView: function() {
745            if (!$('.bf-check-position').hasClass('bf-horizontal')){
746                return;
747            }
748            BrainyFilter.initHorizontalScrolls();
749
750            // slide up/down all the horizontal filter layout
751            $('.bf-toggle-filter-arrow').on('click', function() {
752                var $cont = $(this).closest('.box').find('.brainyfilter-panel');
753                if ($cont.is(':visible')) {
754                    $cont.stop().slideUp(600);
755                    $(this).addClass('bf-down');
756                } else {
757                    $cont.stop().slideDown(600);
758                    $(this).removeClass('bf-down');
759                }
760            });
761            // add shrink/expand ability for attribute groups
762            $('.bf-horizontal').find('.bf-attr-group-header').each(function(){
763                var $arrow = $('<a class="bf-group-arrow"></a>');
764                $(this).append($arrow);
765                var $group = $(this)
766                        .nextUntil('.bf-attr-group-header', '.bf-attr-block')
767                        .wrapAll('<div class="bf-attr-block-wrapper"></div>')
768                        .parent();
769
770                $arrow.on('click', function(){
771                    if ($group.is(':visible')) {
772                        $arrow.addClass('bf-down');
773                        $group.slideUp(600);
774                    } else {
775                        $arrow.removeClass('bf-down');
776                        $group.slideDown(600);
777                    }
778                });
779            });
780
781        },
782        
783        initHorizontalScrolls : function() {
784            var scroll = function(block, direction) {
785                var $block = $(block);
786                var dw = $block.width();
787                var $last = $block.find('.bf-attr-filter').filter(':visible').last();
788                var mw = $last.position().left + $last.outerWidth();
789                var curOffset = -parseInt($block.find('.bf-attr-block-cont').css('left')) || 0;
790                var newOffset = direction > 0 ? curOffset + dw : curOffset - dw;
791                    newOffset = newOffset < 0 ? 0 : newOffset;
792                $block.find('.bf-attr-filter').filter(':visible').each(function(i){
793                    var left = $(this).position().left;
794                    var width = $(this).outerWidth();
795                    var offset = (newOffset + dw > mw) ? mw - dw : newOffset;
796                    var id = (newOffset + dw > mw) ? i + 1 : i;
797                    if (offset > left && offset < left + width) {
798                        newOffset = $block.find('.bf-attr-filter').filter(':visible').eq(id).position().left;
799                        return false;
800                    }
801                });
802                $block.find('.bf-attr-block-cont').stop().animate({left: "-"+ newOffset +"px"}, 1200);
803            };
804            
805            var filterRows = $('.bf-horizontal').find('.bf-attr-block')
806                    .not('.bf-keywords-filter')
807                    .not('.bf-price-filter')
808                    .not('.bf-slider');
809            
810            filterRows.each(function(){
811                var scrollBlockWidth = 0;
812                $(this).find('.bf-row').filter(':visible').each(function(){
813                    scrollBlockWidth += $(this).outerWidth();
814                });
815                var $win  = $(this).find('.bf-sliding-cont');
816                var $cont = $(this).find('.bf-attr-block-cont');
817                $cont.width(scrollBlockWidth + 100);
818                $win.removeClass('bf-scrollable');
819                $win.parent().find('.bf-btn-left').remove();
820                $win.parent().find('.bf-btn-right').remove();
821                if ($win.width() < scrollBlockWidth) {
822                    $(this).addClass('bf-with-scroll');
823                    $win.addClass('bf-scrollable');
824                    var $btnLeft  = $('<a class="bf-btn-left"></a>');
825                    var $btnRight = $('<a class="bf-btn-right"></a>');
826                    $win.after($btnLeft, $btnRight);
827                    $btnLeft.on('click', function(){
828                        scroll($win, -1);
829                    });
830                    $btnRight.on('click', function(){
831                        scroll($win, 1);
832                    });
833                } else {
834                    $cont.css({left : 0});
835                }
836            });
837                /*The vertical alignment of the blocks*/
838            filterRows.each(function(i,v){
839                var attrHeader = $(this).find('.bf-attr-header').outerHeight();
840                var contHeight = $(this).find('.bf-sliding-cont').outerHeight();
841                var slidingCont = $(this).find('.bf-sliding-cont');
842                if(attrHeader > contHeight){
843                    var margin = (attrHeader - contHeight)/2;
844                    slidingCont.css('margin-top', margin);
845                    if (slidingCont.hasClass('bf-scrollable')) {
846                         $(this).find('.bf-btn-left').css('margin-top', margin);
847                         $(this).find('.bf-btn-right').css('margin-top', margin);
848                    };
849                }
850            });
851             /*END*/
852        },
853        
854        changePriceSlider: function(min, max) {
855            $(this.sliderId).each(function(){
856                var $slider = $(this),
857                    sliderType = parseInt($slider.data('slider-type')),
858                    priceCont = $slider.closest('.bf-price-container'),
859                    minVal = parseFloat(priceCont.find(BrainyFilter.minFieldId).val()),
860                    maxVal = parseFloat(priceCont.find(BrainyFilter.maxFieldId).val()),
861                    vals = [minVal, maxVal],
862                    curMin = $slider.slider('option', 'min'),
863                    curMax = $slider.slider('option', 'max');
864                min = parseFloat(min);
865                max = parseFloat(max);
866
867                BrainyFilter.max = max;
868                BrainyFilter.min = min;
869                $slider.slider('option', 'min', min);
870                $slider.slider('option', 'max', max);
871                if (vals[0] === curMin || vals[0] < min) {
872                    vals[0] = min;
873                }
874                if (vals[1] === curMax || vals[1] > max) {
875                    vals[1] = max;
876                }
877                if (vals[0] > vals[1]) {
878                    vals[0] = vals[1];
879                }
880                $slider.slider('option', 'values', vals);
881
882                if (sliderType === 2 || sliderType === 3) {
883                    BrainyFilter.priceSliderLabels($slider);
884                }
885                
886                priceCont.find(BrainyFilter.minFieldId).val(vals[0]);
887                priceCont.find(BrainyFilter.maxFieldId).val(vals[1]);
888            });
889        },
890
891        floatSubmit: function() {
892            var cont = $(BrainyFilter.filterFormId).filter('.bf-with-float-btn');
893            var winWidth = $('body').width();
894            var btn      = cont.find('.bf-buttonsubmit').eq(0);
895            var closeBtn = $('<div class="bf-close-btn"></div>');
896            var tick     = $('<div class="bf-tick"></div>');
897            var panel    = $('<div class="bf-float-submit"></div>').prepend(tick)
898                    .append(btn).append(closeBtn);
899            $('body').append(panel);
900            panel.css('display', 'none');
901
902            var timer = null;
903            var hideBtn = function(){
904                $('.bf-float-submit').fadeOut(400);
905            };
906            closeBtn.click(hideBtn);
907            var showBtn = function(){
908                var form = BrainyFilter.serializeMultipleForms();
909                if (BrainyFilter.selectionCache === form || cont.closest('.bf-responsive.bf-active').hasClass('bf-opened')) {
910                    hideBtn();
911                    return;
912                }
913                var outBlockOffset = $(this).closest('.brainyfilter-panel').offset();
914                var blockOffset = $(this).closest('.bf-attr-filter').offset();
915                var blockHeight = $(this).closest('.bf-attr-filter').outerHeight();
916                var panelHeight = panel.outerHeight();
917                var panelWidth  = panel.outerWidth();
918                var blockWidth  = $(this).closest('.brainyfilter-panel').outerWidth();
919                var panelNewLeft = (outBlockOffset.left + blockWidth + panelWidth > winWidth) 
920                    ? outBlockOffset.left - panelWidth + 4
921                    : outBlockOffset.left + blockWidth - 4;
922                if (panel.css('display') === 'block') {
923                    if (parseFloat(panel.css('left')) === panelNewLeft) {
924                        panel.animate({top: blockOffset.top + (blockHeight - panelHeight) / 2}, 300);
925                    } else {
926                        panel.offset({top: blockOffset.top + (blockHeight - panelHeight) / 2, left: panelNewLeft});
927                    }
928                } else {
929                    panel.css('display', 'block');
930                    panel.offset({top: blockOffset.top, left: panelNewLeft});
931                    panel.css({top: blockOffset.top + (blockHeight - panelHeight) / 2});
932                }
933                if (timer) {
934                    clearTimeout(timer);
935                }
936                timer = setTimeout(hideBtn, 10000);
937                $(document).trigger('bfFloatButton.show');
938            };
939            cont.find('input, select').not('[type="text"]').change(showBtn);
940            cont.find('input[type="text"]').keyup(showBtn);
941            cont.find('.bf-c-3').on('click', '.bf-cross', showBtn);
942            cont.find(BrainyFilter.sliderId).on( "slidestop", showBtn);
943            cont.find('.bf-slider-container').on( "slidestop", showBtn);
944        },
945
946        loadingAnimation: function() {
947            $('.bf-tick').addClass('bf-loading');
948            var stopSpin = function(){
949                $('.bf-tick').removeClass('bf-loading');
950                $(document).unbind('ajaxComplete', stopSpin);
951                $('.bf-float-submit').css('display', 'none');
952            };
953            $(document).ajaxComplete(stopSpin);
954        },
955
956        initSliding: function() {
957            $(this.filterFormId).each(function(){
958                var $form = $(this);
959                var enableSliding = $form.hasClass('bf-with-sliding');
960                var limitHeight   = $form.hasClass('bf-with-height-limit');
961                var limitHeightOpts = parseInt($form.data('height-limit'));
962                var visibleItems = parseInt($form.data('visible-items'));
963                var hideItems = parseInt($form.data('hide-items'));
964                $form.find('.bf-attr-block-cont').each(function(i, v) {
965                    var $this = $(this), 
966                        firstInit = false, 
967                        wrapper = $this.parent();
968                    if (!$this.parent().is('.bf-sliding')) {
969                        $this.wrap('<div class="bf-sliding"></div>');
970                        $this.parent().wrap('<div class="bf-sliding-cont"></div>');
971                        wrapper = $this.parent();
972                        wrapper.addClass('bf-expanded');
973                        firstInit = true;
974                    }
975                    if (enableSliding) {
976                        var count = $this.find('.bf-attr-filter').filter(':visible').size() - visibleItems;
977                        if ( count > 0 && count >= hideItems) {
978                            if ($this.parent().hasClass('bf-expanded') && !firstInit) {
979                                BrainyFilter.expandBlock(v);
980                                $this.parent().parent().find('.bf-sliding-show').removeClass('bf-hidden');
981                            } else {
982                                BrainyFilter.shrinkBlock(v, visibleItems, true);
983                            }
984                        } else {
985                            $this.parent().css('height', 'auto');
986                            $this.parent().parent().find('.bf-sliding-show').addClass('bf-hidden');
987                        }
988                    }else if(limitHeight) {
989                        if (wrapper.height()) {
990                            wrapper.css('height', 'auto');
991                            if (wrapper.height() > limitHeightOpts) {
992                                wrapper.css({'height':limitHeightOpts, 'overflow-x': 'hidden', 'overflow-y': 'auto'});
993                            } else {
994                                wrapper.css('height', 'auto');
995                            }
996                        }
997                    }
998                    $this.parents('.bf-attr-block').find('.bf-attr-header').addClass('bf-clickable');
999
1000                    $this.parents('.bf-attr-block').find('.bf-attr-header').off('click').on("click", function(){
1001                        if ( wrapper.hasClass('bf-expanded') ) {
1002                            BrainyFilter.shrinkBlock(v, 0);
1003                        } else {
1004                            BrainyFilter.expandBlock(v);
1005                        }
1006                    });
1007                });
1008            });
1009        },
1010        
1011        shrinkBlock: function(block, items, disableAnim) {
1012            // disable for horizontal view
1013            if ($(block).closest('.bf-check-position').hasClass('bf-horizontal')) {
1014                return;
1015            }
1016            var $form = $(block).closest(BrainyFilter.filterFormId);
1017            var visibleItems = parseInt($form.data('visible-items'));
1018            var count   = $(block).find('.bf-attr-filter').filter(':visible').size() - visibleItems;
1019            var height  = 0;
1020            var wrapper = $(block).closest('.bf-sliding-cont');
1021            var showMore = wrapper.find('.bf-sliding-show').addClass('bf-hidden');
1022            if (items) {
1023                $(block).find('.bf-attr-filter').each(function(j, vv){
1024                    if (j < items) {
1025                        height += $(vv).height();
1026                    }
1027                });
1028                if (!showMore.size()) {
1029                    wrapper.append('<div class="bf-sliding-show" ></div>'); 
1030                }
1031                wrapper.find('.bf-sliding-show')
1032                    .text(bfLang.show_more + ' (' + count + ')')
1033                    .unbind('click')
1034                    .removeClass('bf-hidden')
1035                    .click(function() {
1036                        BrainyFilter.expandBlock(block);
1037                    });
1038            }
1039
1040            if (disableAnim) {
1041                $(block).closest('.bf-sliding').stop().css('height', height);
1042            } else {
1043                $(block).closest('.bf-sliding').stop().animate({height: height}, 300);
1044            }
1045            if (!items) {
1046                $(block).closest('.bf-attr-block').find('.bf-arrow').css('background-position', '50% -128px');
1047            }
1048            $(block).parent().removeClass('bf-expanded');
1049        },
1050
1051        expandBlock: function(block, disableAnim) {
1052            // disable for horizontal view
1053            if ($(block).closest('.bf-check-position').hasClass('bf-horizontal')) {
1054                return;
1055            }
1056            var $form = $(block).closest(BrainyFilter.filterFormId);
1057            var limitHeight = $form.hasClass('bf-with-height-limit');
1058            var limitHeightOpts = parseInt($form.data('height-limit'));
1059            var visibleItems = parseInt($form.data('visible-items'));
1060            var fullHeight = $(block).height();
1061            var wrapper    = $(block).parent();
1062            if(limitHeight && limitHeightOpts < fullHeight) {
1063                fullHeight = limitHeightOpts;
1064            }
1065            if (disableAnim) {
1066                wrapper.stop().css('height', fullHeight);
1067            } else {
1068                wrapper.stop().animate({height : fullHeight}, 300);
1069            }
1070            wrapper.parent().find('.bf-sliding-show')
1071                .text(bfLang.show_less)
1072                .unbind('click')
1073                .removeClass('bf-hidden')
1074                .click(function() {
1075                    BrainyFilter.shrinkBlock(block, visibleItems);
1076                });
1077            wrapper.addClass('bf-expanded');
1078            $(block).parents('.bf-attr-block').find('.bf-arrow').css('background-position', '50% -153px');
1079        },
1080
1081        collapse: function() {
1082            var height  = 0;
1083            $('.bf-collapse').parents('.bf-attr-block').find('.bf-sliding').removeClass('bf-expanded');
1084            $('.bf-collapse').parents('.bf-attr-block').find('.bf-sliding-show').addClass('bf-hidden');
1085            $('.bf-collapse').parents('.bf-attr-block').find('.bf-arrow').css('background-position', '50% -128px');
1086            $('.bf-collapse').parents('.bf-attr-block').find('.bf-sliding').stop().animate({height: height}, 300);
1087
1088        },
1089        
1090        hideEmptySections : function() {
1091            $('.bf-attr-block').each(function(){
1092                var $this = $(this);
1093                $this.removeClass('bf-hidden');
1094                if ($this.find('.bf-attr-filter').filter(':visible').size()) {
1095                    $this.removeClass('bf-hidden');
1096                } else {
1097                    $this.addClass('bf-hidden');
1098                }
1099            });
1100            $('.bf-attr-group-header').each(function(){
1101                var $this = $(this);
1102                $this.removeClass('bf-hidden');
1103                if ($this.nextUntil('.bf-attr-group-header', '.bf-attr-block').filter(':visible').size()
1104                        || $this.next('.bf-attr-block-wrapper').find('.bf-attr-filter').filter(':visible').size()) {
1105                    $this.removeClass('bf-hidden');
1106                } else {
1107                    $this.addClass('bf-hidden');
1108                }
1109            });
1110        },
1111        
1112        initAbsolutePosition : function() {
1113            var $layout = $('.bf-responsive').eq(0),
1114                $form = $layout.find(BrainyFilter.filterFormId),
1115                $fixedLayout = $layout.find('.bf-check-position'),
1116                curSubmitType, isHorizontal;
1117            
1118            var checkWidth = function(){
1119                var p = 15,
1120                    w = $(window).width(),
1121                    mw = parseInt($form.data('resp-max-scr-width')),
1122                    rw = parseInt($form.data('resp-max-width'));
1123                if (w <= mw) {
1124                    $layout.addClass('bf-active');
1125                    if ($layout.parent().prop('tagName') !== 'BODY') {
1126                        $('body').append($layout);
1127                    }
1128                    var mh = $(window).height() - parseInt($fixedLayout.css('top')) - p;
1129                    var nw = w - p * 2;
1130                        nw = nw > rw && rw > 0 ? rw : nw;
1131                    $fixedLayout.css({'width': nw, 'max-height' : mh});
1132                    // force auto submit
1133                    $form.data('submit-type', 'auto');
1134                    // suppress horizontal view
1135                    if (isHorizontal) {
1136                        $form.closest('.bf-check-position').removeClass('bf-horizontal');
1137                    }
1138                    // collapse sections
1139                    if ($form.data('resp-collapse')) {
1140                        $form.find('.bf-attr-block-cont').each(function(){
1141                            if(!$form.find('input[type="text"]:focus')) {
1142                                BrainyFilter.shrinkBlock(this, 0);
1143                            }
1144                        });
1145                    }
1146                    if ($layout.hasClass('bf-opened')) {
1147                        preventBodyScroll();
1148                    }
1149                } else {
1150                    $layout.removeClass('bf-active');
1151                    $fixedLayout.css({'width': 'inherit', 'max-height' : 'none'});
1152                    $form.data('submit-type', curSubmitType);
1153                    if (isHorizontal) {
1154                        $form.closest('.bf-check-position').addClass('bf-horizontal');
1155                    }
1156                    if ($layout.parent().prop('tagName') === 'BODY') {
1157                        $('#bf-brainyfilter-anchor').after($layout);
1158                    }
1159                    letBodyScroll();
1160                }
1161            };
1162            
1163            var preventBodyScroll = function() {
1164                var $body = $('body');
1165                var $doc = $(document);
1166                if (!$body.hasClass('bf-non-scrollable')) {
1167                    $body.css({'top' : -$doc.scrollTop(), 'left' : -$doc.scrollLeft()});
1168                    $body.addClass('bf-non-scrollable');
1169                }
1170            };
1171            var letBodyScroll = function() {
1172                var $body = $('body.bf-non-scrollable');
1173                if ($body.size()) {
1174                    $body.removeClass('bf-non-scrollable');
1175                    $(document).scrollTop(-parseInt($body.css('top')));
1176                    $(document).scrollLeft(-parseInt($body.css('left')));
1177                    $body.css({'top' : 'auto', 'left' : 'auto'});
1178                }
1179            };
1180            
1181            if ($layout.size()) {
1182                $layout.before('<div id="bf-brainyfilter-anchor"></div>');
1183//                $form = $layout.find(BrainyFilter.filterFormId);
1184                curSubmitType = $form.data('submit-type');
1185                isHorizontal  = $form.closest('.bf-check-position').hasClass('bf-horizontal');
1186                $(window).resize(checkWidth);
1187                $layout.find('.bf-btn-show').on('click', function(){
1188                    $layout.toggleClass('bf-opened');
1189                    if ($('body').hasClass('bf-non-scrollable')) {
1190                        letBodyScroll();
1191                    } else {
1192                        preventBodyScroll();
1193                    }
1194                });
1195            }
1196            checkWidth();
1197        },
1198        
1199        addSliderLabels : function($slider, labels, showExtrems) {
1200            var $lbl = $('<span />', {'class': 'bf-slider-label'}),
1201                w = $slider.outerWidth(),
1202                n = labels.length - 1,
1203                dx = w / n,
1204                dxp = 100 / n,
1205                $labels = [],
1206                line = 0;
1207        
1208            $slider.find('.bf-slider-label').remove();
1209            
1210            $.each(labels, function(i, v){
1211                if ((!i || i === n) && !showExtrems) return;
1212                var offset = dxp * i,
1213                    $l = $lbl.clone();
1214                
1215                $slider.append($l);
1216                $l.text(typeof v.n !== 'undefined' ? v.n : v);
1217                var lw = $l.width(), marg = (!i) ? 0 : ((i === n) ? -lw : -lw / 2);
1218                
1219                if (i === 1) {
1220                    line = lw;
1221                } else {
1222                    var lblLeft = w * offset / 100 + marg;
1223                    if (line > lblLeft) {
1224                        if (i === labels.length - 2) {
1225                            $labels[$labels.length-1].text('').css('margin-left', 0);
1226                        } else {
1227                            $l.text('');
1228                            marg = 0;
1229                        }
1230                    } else {
1231                        line = lblLeft + lw;
1232                    }
1233                }
1234                
1235                $l.css({left: offset + '%', 'margin-left' : marg});
1236                $labels.push($l);
1237            });
1238            
1239        },
1240        priceSliderLabels : function($slider){
1241            var w = $slider.outerWidth(),
1242                px = BrainyFilter.max - BrainyFilter.min,
1243                d = px < 2 ? w : ((BrainyFilter.max.toFixed(2) + '').length + 1) * 6 * 1.5,
1244                n = Math.floor(w / d),
1245                dx = w / n,
1246                labels = [BrainyFilter.currencySymb + BrainyFilter.min.toFixed(2)];
1247                
1248            for (var i = 1; i < n; i ++) {
1249                var p = Math.round(BrainyFilter.min + i * dx / w * (BrainyFilter.max - BrainyFilter.min));
1250                labels.push(BrainyFilter.currencySymb + p.toFixed(2));
1251            }
1252            labels.push(BrainyFilter.currencySymb + BrainyFilter.max.toFixed(2));
1253            BrainyFilter.addSliderLabels($slider, labels, true);
1254        }
1255    };
1256    window['BrainyFilter'] = BrainyFilter;
1257}
1258if (typeof isIE === 'undefined') {
1259    function isIE(){
1260        if ((document.all && document.querySelector && !document.addEventListener) 
1261         || (document.all && !document.querySelector) 
1262         || (document.all && document.querySelector && document.addEventListener && 
1263        !window.atob)) {
1264            return true;
1265        }else{
1266            return false;
1267        }
1268    }
1269}
1270if (typeof window.location.origin === 'undefined') {
1271  window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
1272}
1273
1274})(jQuery);
1275
1276if ( ! window.console ) console = { log: function(){} };
1277
1278jQuery(document).ready(function(){
1279    function onProductListChangeHandler () {
1280        if(localStorage.getItem('display') === 'grid') {
1281            Journal.gridView();
1282        } else {
1283            Journal.listView();
1284        }
1285        if (Journal.quickViewStatus) {
1286            Journal.enableQuickView();
1287        }
1288        $('.main-products .product-grid-item .image > a').prepend('<div class="p-over p-grid-over"> </div>');
1289        $('.main-products .product-list-item .image > a').prepend('<div class="p-over p-list-over"> </div>');
1290
1291        $("img.lazy").lazy({
1292            bind: 'event',
1293            visibleOnly: false,
1294            effect: "fadeIn",
1295            effectTime: 250
1296        });
1297
1298        if ($('html').hasClass('product-page') || $('html').hasClass('quickview')) {
1299            Journal.enableCloudZoom('inner');
1300        }
1301
1302        Journal.itemsEqualHeight();
1303    }
1304    
1305    if (typeof Journal !== 'undefined' && BrainyFilter && !BrainyFilter.journalCompatibilityEnabled) {
1306
1307        BrainyFilter.journalCompatibilityEnabled = true;
1308
1309        $(document).on('productlistchange', onProductListChangeHandler);
1310    }
1311    
1312});

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.