PageSourceSearch

https://www.shop4laptophoes.nl/js/tygh/product_filters.js?ver=4.8.2

js shop4laptophoes.nl collected 2026-10-06 11:01:37 UTC 6,084 bytes, 177 lines download raw bytes

1(function (_, $) {
2    'use strict';
3
4    var base_url;
5    var ajax_ids;
6    var no_trigger = false;
7
8    var HASH_SEPARATOR = '_';
9    var HASH_FEATURE_SEPARATOR = '-';
10
11    (function ($) {
12
13        function generateHash(container) {
14            var features = {};
15            var hash = [];
16
17            container.find('input.cm-product-filters-checkbox:checked').each(function () {
18                var elm = $(this);
19                if (!features[elm.data('caFilterId')]) {
20                    features[elm.data('caFilterId')] = [];
21                }
22                features[elm.data('caFilterId')].push(elm.val());
23            });
24
25            for (var k in features) {
26                hash.push(k + HASH_FEATURE_SEPARATOR + features[k].join(HASH_FEATURE_SEPARATOR));
27            }
28
29            return hash.join(HASH_SEPARATOR);
30        }
31
32        function resetFilters(obj) {
33            obj.prop('checked', !obj.prop('checked'));
34            if (obj.data('prevVal')) {
35                no_trigger = true;
36
37                var vals = obj.data('prevVal').split('-');
38                var sli = obj.parent().find('.cm-range-slider');
39                if (sli.length) {
40                    sli.slider('values', [vals[0], vals[1]]);
41                    sli.slider('option', 'slide').call(sli, {}, {values: [vals[0], vals[1]]}); // that's so dirty, but it works
42                }
43
44                var da = obj.parent().find('.cm-date-range');
45                if (da.length) {
46                    da.daterangepicker({
47                        startDate: vals[0],
48                        endDate: vals[1]
49                    });
50                }
51
52                no_trigger = false;
53            }
54        }
55
56        function getProducts(url, obj) {
57            if (ajax_ids) {
58                $.ceAjax('request', url, {
59                    result_ids: ajax_ids,
60                    full_render: true,
61                    save_history: true,
62                    caching: false,
63                    scroll: '.ty-mainbox-title',
64                    obj: obj,
65                    callback: function (response) {
66                        if (response.no_products) {
67                            resetFilters(obj);
68                        }
69                    }
70                });
71            } else {
72                $.redirect(url);
73            }
74
75            return false;
76        }
77
78        function setHandler() {
79            $(_.doc).on('change', '.cm-product-filters-checkbox', function () {
80                if (no_trigger) {
81                    return false;
82                }
83
84                var self = $(this);
85                var container = self.parents('.cm-product-filters');
86
87                return getProducts($.attachToUrl(base_url, 'features_hash=' + generateHash(container)), self);
88            });
89        }
90
91        function setCallback() {
92            // re-init filters
93            $.ceEvent('on', 'ce.commoninit', function (context) {
94
95                context.find('.cm-product-filters').each(function () {
96                    var self = $(this);
97                    if (self.data('caBaseUrl')) {
98                        base_url = self.data('caBaseUrl');
99                        ajax_ids = self.data('caTargetId');
100                    }
101                });
102
103                initSlider(context);
104            });
105
106            $.ceEvent('on', 'ce.filterdate', function (elm, time_from, time_to) {
107                var cb = $('#elm_checkbox_' + elm.prop('id'));
108
109                cb.data('prevVal', cb.val());
110                cb.val(time_from + '-' + time_to).prop('checked', true).trigger('change');
111            });
112        }
113
114        function initSlider(parent) {
115            parent.find('.cm-range-slider').each(function () {
116                var $el = $(this);
117                var id = $el.prop('id');
118                var json_data = $('#' + id + '_json').val();
119                if ($el.data('uiSlider') || !json_data) {
120                    return false;
121                }
122                var data = $.parseJSON(json_data) || null;
123                if (!data) {
124                    return false;
125                }
126
127                $el.slider({
128                    disabled: data.disabled,
129                    range: true,
130                    min: data.min,
131                    max: data.max,
132                    step: data.step,
133                    values: [data.left, data.right],
134                    slide: function (event, ui) {
135                        $('#' + id + '_left').val(ui.values[0]);
136                        $('#' + id + '_right').val(ui.values[1]);
137                    },
138                    change: function (event, ui) {
139                        var replacement = ui.values[0] + '-' + ui.values[1];
140
141                        if (data.extra) {
142                            replacement = replacement + '-' + data.extra;
143                        }
144
145                        var $checkbox = $('#elm_checkbox_' + id);
146                        $checkbox.data('prevVal', $checkbox.val());
147                        $checkbox.val(replacement).prop('checked', true).trigger('change');
148                    }
149                });
150
151                if (data.left != data.min || data.right != data.max) {
152                    var replacement = data.left + '-' + data.right;
153                    if (data.extra) {
154                        replacement = replacement + '-' + data.extra;
155                    }
156
157                    $('#elm_checkbox_' + id).val(replacement).prop('checked', true);
158                }
159
160                $('#' + id + '_left, #' + id + '_right')
161                    .off('change')
162                    .on('change', function () {
163                        var index = $(this).attr('id') == id + '_left' ? 0 : 1;
164                        $el.slider('values', index, _.toNumeric($(this).val()));
165                    });
166
167                if ($el.parents('.filter-wrap').hasClass('open')) {
168                    $el.parent('.price-slider').show();
169                }
170            });
171        }
172
173        setCallback();
174        setHandler();
175    })($);
176
177}(Tygh, Tygh.$));

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.