PageSourceSearch

https://uzs.ru/bitrix/themes/intec.startshop/web/startshop/js/catalog.js?16189221358060

js uzs.ru collected 2026-10-09 22:42:39 UTC 8,060 bytes, 237 lines download raw bytes

1Startshop.Catalog.Offers = function ($oStructure) {
2    this.Offers = {};
3
4    this.Offers.Current = null;
5    this.Offers.List = $oStructure['OFFERS'];
6    this.Offers.Properties = $oStructure['PROPERTIES'];
7
8    this.Events = {};
9    this.Events.OnOfferChange = function ($oParameters) {};
10    this.Events = $.extend({}, this.Events, $oStructure['EVENTS'] || {});
11};
12
13Startshop.Catalog.Offers.prototype.GetParameters = function () {
14    var $oParameters = {};
15    var $oThat = this;
16    $oParameters.Offer = this.GetCurrentOffer();
17
18    $oParameters.Properties = {};
19    $oParameters.Properties.Displayed = [];
20    $oParameters.Properties.Disabled = [];
21    $oParameters.Properties.Enabled = [];
22    $oParameters.Properties.Selected = [];
23
24    Startshop.Functions.forEach(this.Offers.List, function ($sOfferCode, $oOffer) {
25        var $oOfferTree = $oThat.GetOfferPropertiesTree($oOffer['ID']);
26        Startshop.Functions.forEach($oOfferTree, function ($sOfferPropertyCode, $cOfferPropertyValue) {
27            var $oProperty = {'Key': $sOfferPropertyCode, 'Value': $cOfferPropertyValue};
28
29            if (!Startshop.Functions.inArray($oProperty, $oParameters.Properties.Displayed))
30                $oParameters.Properties.Displayed.push($oProperty);
31        });
32    });
33
34    var $oCurrentOffer = this.GetCurrentOffer();
35    var $oCurrentOfferTree = null;
36
37    if ($oCurrentOffer != null)
38        $oCurrentOfferTree = this.GetOfferPropertiesTree($oCurrentOffer['ID']);
39
40    var $arProperties = [];
41    var $arPropertiesSelected = [];
42
43    Startshop.Functions.forEach($oThat.Offers.Properties, function ($iKey, $oProperty) {
44        $arProperties.push($oProperty['CODE']);
45    });
46
47    Startshop.Functions.forEach($arProperties, function ($iPropertyIndex, $sProperty) {
48        var $sCurrentProperty = $arProperties[$iPropertyIndex];
49
50        Startshop.Functions.forEach($oThat.Offers.List, function ($iOfferCode, $oOffer) {
51            var $bCompared = true;
52            var $oOfferTree = $oThat.GetOfferPropertiesTree($oOffer['ID']);
53
54            if ($oCurrentOffer != null) {
55                Startshop.Functions.forEach($arPropertiesSelected, function ($iPropertySelectedIndex, $sPropertySelected) {
56                    if ($oOfferTree[$sPropertySelected] != $oCurrentOfferTree[$sPropertySelected]) {
57                        $bCompared = false;
58                        return false;
59                    }
60                });
61            } else if ($arPropertiesSelected.length > 0) {
62                $bCompared = false;
63            }
64
65            if ($bCompared == true) {
66                var $oProperty = {'Key':$sCurrentProperty, 'Value':$oOfferTree[$sCurrentProperty]};
67
68                if (!Startshop.Functions.inArray($oProperty, $oParameters.Properties.Enabled))
69                    $oParameters.Properties.Enabled.push($oProperty);
70            }
71        });
72
73        $arPropertiesSelected.push($sCurrentProperty);
74    });
75
76    Startshop.Functions.forEach($oParameters.Properties.Displayed, function ($iPropertyIndex, $oProperty) {
77        if (!Startshop.Functions.inArray($oProperty, $oParameters.Properties.Enabled))
78            $oParameters.Properties.Disabled.push($oProperty);
79    });
80
81    if ($oCurrentOfferTree != null)
82        Startshop.Functions.forEach($oCurrentOfferTree, function ($sPropertyCode, $cPropertyValue) {
83            $oParameters.Properties.Selected.push({'Key': $sPropertyCode, 'Value': $cPropertyValue});
84        });
85
86    return $oParameters;
87};
88
89Startshop.Catalog.Offers.prototype.GetOfferByID = function ($iOfferID) {
90    if (typeof $iOfferID === "string")
91        $iOfferID = parseInt($iOfferID);
92
93    if (isNaN($iOfferID))
94        return null;
95
96    if (typeof $iOfferID === 'number') {
97        var $oCurrentOffer = this.Offers.List[$iOfferID];
98
99        if ($oCurrentOffer !== undefined)
100            return $oCurrentOffer;
101    }
102
103    return null;
104};
105
106Startshop.Catalog.Offers.prototype.GetOfferByPropertiesTree = function ($oProperties) {
107    var $oFoundedOffer = null;
108    Startshop.Functions.forEach(this.Offers.List, function ($sOfferCode, $oOffer) {
109        var $bEqual = true;
110        Startshop.Functions.forEach($oProperties, function($sPropertyCode, $cPropertyValue) {
111            var $oOfferProperty = $oOffer['OFFER']['PROPERTIES'][$sPropertyCode];
112
113            if ($cPropertyValue == '')
114                $cPropertyValue = null;
115
116            if ($cPropertyValue != null) {
117                if ($oOfferProperty !== undefined) {
118                    if ($oOfferProperty['VALUE']['CODE'] != $cPropertyValue)
119                        $bEqual = false;
120                } else {
121                    $bEqual = false;
122                }
123            } else {
124                if ($oOfferProperty !== undefined) {
125                    $bEqual = false;
126                }
127            }
128
129            return $bEqual;
130        });
131
132        if ($bEqual) {
133            $oFoundedOffer = $oOffer;
134            return false;
135        }
136    });
137
138    return $oFoundedOffer;
139};
140
141Startshop.Catalog.Offers.prototype.GetCurrentOffer = function () {
142    return this.GetOfferByID(this.Offers.Current);
143};
144
145Startshop.Catalog.Offers.prototype.SetCurrentOfferByID = function ($iOfferID) {
146    if (this.GetOfferByID($iOfferID) != null) {
147        this.Offers.Current = $iOfferID;
148
149        if (Startshop.Functions.isFunction(this.Events.OnOfferChange))
150            this.Events.OnOfferChange(this.GetParameters());
151
152        return true;
153    }
154
155    return false;
156};
157
158Startshop.Catalog.Offers.prototype.GetOfferPropertiesTree = function ($iOfferID) {
159    var $oTree = {};
160    var $oOffer = this.GetOfferByID($iOfferID);
161
162    if ($oOffer == null)
163        return $oTree;
164
165    Startshop.Functions.forEach(this.Offers.Properties, function ($iKey, $oProperty) {
166        var $oOfferProperty = $oOffer['OFFER']['PROPERTIES'][$oProperty['CODE']];
167
168        if ($oOfferProperty !== undefined) {
169            $oTree[$oProperty['CODE']] = $oOfferProperty['VALUE']['CODE'];
170        } else {
171            $oTree[$oProperty['CODE']] = '';
172        }
173    });
174
175    return $oTree;
176};
177
178Startshop.Catalog.Offers.prototype.SetCurrentOfferByPropertyValue = function ($sProperty, $cValue) {
179    var $oCurrentOffer = this.GetCurrentOffer();
180    var $oFoundedOffer = null;
181    var $oChangeableProperty = null;
182
183    if ($oCurrentOffer == null || typeof $sProperty != "string")
184        return false;
185
186    Startshop.Functions.forEach(this.Offers.Properties, function ($iKey, $oProperty) {
187        if ($oProperty['CODE'] == $sProperty) {
188            $oChangeableProperty = $oProperty;
189            return false;
190        }
191    });
192
193    if ($oChangeableProperty == null)
194        return false;
195
196    var $oCompareProperties = {};
197    var $oCurrentOfferPropertyTree = this.GetOfferPropertiesTree($oCurrentOffer['ID']);
198
199    Startshop.Functions.forEach($oCurrentOfferPropertyTree, function ($sPropertyCode, $sPropertyValue) {
200        $oCompareProperties[$sPropertyCode] = $sPropertyValue;
201        if ($sPropertyCode == $sProperty) {
202            $oCompareProperties[$sPropertyCode] = $cValue;
203        }
204    });
205
206    $oFoundedOffer = this.GetOfferByPropertiesTree($oCompareProperties);
207
208    if ($oFoundedOffer != null) {
209        this.SetCurrentOfferByID($oFoundedOffer['ID']);
210        return true;
211    }
212
213    $oCompareProperties = {};
214
215    Startshop.Functions.forEach($oCurrentOfferPropertyTree, function ($sPropertyCode, $sPropertyValue) {
216        $oCompareProperties[$sPropertyCode] = $sPropertyValue;
217        if ($sPropertyCode == $sProperty) {
218            $oCompareProperties[$sPropertyCode] = $cValue;
219            return false;
220        }
221    });
222
223    $oFoundedOffer = this.GetOfferByPropertiesTree($oCompareProperties);
224
225    if ($oFoundedOffer != null) {
226        this.SetCurrentOfferByID($oFoundedOffer['ID']);
227        return true;
228    }
229};
230
231Startshop.Catalog.Offers.prototype.Initialize = function () {
232    var $sThat = this;
233    Startshop.Functions.forEach(this.Offers.List, function ($sOfferCode, $oOffer) {
234        $sThat.SetCurrentOfferByID($oOffer['ID']);
235        return false;
236    });
237};

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.