PageSourceSearch

https://atlascopcoparts.ru/bitrix/templates/universesite_s1/js/catalog.js

js atlascopcoparts.ru collected 2026-10-08 15:01:18 UTC 5,846 bytes, 211 lines download raw bytes

1universe.catalog = (function ($, api) {
2    var catalog = {};
3
4    catalog.offers = function (settings) {
5        var self = this;
6        var properties = [];
7        var list = [];
8        var current = null;
9
10        settings = api.extend({}, settings);
11
12        api.each(settings.properties, function (index, property) {
13            properties.push(property);
14        });
15
16        api.each(settings.list, function (index, offer) {
17            list.push(offer);
18        });
19
20        self.getProperties = function () {
21            return properties;
22        };
23
24        self.getList = function () {
25            return list;
26        };
27
28        self.getCurrent = function () {
29            return current;
30        };
31
32        self.setCurrentById = function (id) {
33            var offer = self.getById(id);
34            var changed = false;
35
36            if (offer !== null) {
37                changed = current !== offer;
38                current = offer;
39            }
40
41            if (changed) {
42                self.trigger('change', current, self.getValues());
43                return current;
44            }
45
46            return null;
47        };
48
49        api.extend(self, api.ext.events(self));
50    };
51
52    catalog.offers.prototype.getById = function (id) {
53        var result = null;
54
55        api.each(this.getList(), function (index, offer) {
56            if (offer.id === id) {
57                result = offer;
58                return false;
59            }
60        });
61
62        return result;
63    };
64
65    catalog.offers.prototype.getByValues = function (values) {
66        var self = this;
67        var result = null;
68
69        api.each(self.getList(), function (index, offer) {
70            var equal = true;
71
72            api.each(self.getProperties(), function(index, property) {
73                var value = offer.values[property.code];
74
75                if (!api.isEmpty(value) && !api.isEmpty(values[property.code])) {
76                    if (value != values[property.code])
77                        equal = false;
78                }
79            });
80
81            if (equal) {
82                result = offer;
83                return false;
84            }
85        });
86
87        return result;
88    };
89
90    catalog.offers.prototype.setCurrentByValue = function (code, value) {
91        var offer = this.getCurrent();
92        var result = null;
93        var values;
94
95        if (offer === null)
96            return result;
97
98        values = api.extend({}, offer.values);
99        values[code] = value;
100
101        result = this.getByValues(values);
102
103        if (result !== null)
104            return this.setCurrentById(result.id);
105
106        values = {};
107
108        api.each(offer.values, function (offerValueCode, offerValue) {
109            values[offerValueCode] = offerValue;
110
111            if (offerValueCode == code) {
112                values[offerValueCode] = value;
113                return false;
114            }
115        });
116
117        result = this.getByValues(values);
118
119        if (result !== null)
120            return this.setCurrentById(result.id);
121
122        return result;
123    };
124
125    catalog.offers.prototype.setCurrentByValues = function (values) {
126        var result = this.getByValues(values);
127
128        if (result !== null)
129            return this.setCurrentById(result.id);
130
131        return result;
132    };
133
134    catalog.offers.prototype.getValues = function () {
135        var self = this;
136        var current = self.getCurrent();
137        var properties = [];
138        var result = {
139            'displayed': {},
140            'disabled': {},
141            'enabled': {},
142            'selected': {}
143        };
144
145        api.each(self.getList(), function (index, offer) {
146            api.each(offer.values, function (code, value) {
147                if (!api.isDeclared(result.displayed[code]))
148                    result.displayed[code] = [];
149
150                if (!api.inArray(value, result.displayed[code]))
151                    result.displayed[code].push(value);
152            });
153        });
154
155        api.each(self.getProperties(), function (index, property) {
156            var code = property.code;
157
158            api.each(self.getList(), function (index, offer) {
159                var compared = true;
160                var value = offer.values[property.code];
161
162                if (current !== null) {
163                    intec.each(properties, function (index, property) {
164                        if (offer.values[property.code] != current.values[property.code]) {
165                            compared = false;
166                            return false;
167                        }
168                    });
169                } else if (properties.length > 0) {
170                    compared = false;
171                }
172
173                if (compared) {
174                    if (!api.isDeclared(result.enabled[code]))
175                        result.enabled[code] = [];
176
177                    if (!api.inArray(value, result.enabled[code]))
178                        result.enabled[code].push(value);
179                }
180            });
181
182            properties.push(property);
183        });
184
185        api.each(result.displayed, function (code, values) {
186            if (!api.isDeclared(result.disabled[code]))
187                result.disabled[code] = [];
188
189            api.each(values, function (index, value) {
190                if (!api.inArray(value, result.enabled[code]))
191                    result.disabled[code].push(value);
192            });
193        });
194
195        if (current !== null)
196            intec.each(current.values, function (code, value) {
197                if (!api.isDeclared(result.selected[code]))
198                    result.selected[code] = [];
199
200                result.selected[code].push(value);
201            });
202
203        return result;
204    };
205
206    catalog.offers.prototype.isEmpty = function () {
207        return this.getList().length === 0;
208    };
209
210    return catalog;
211})(jQuery, intec);

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.