PageSourceSearch

https://www.motorteiledirekt.de/js/varien/form.js?v=1760513748

js motorteiledirekt.de collected 2026-10-06 13:16:54 UTC 15,385 bytes, 419 lines download raw bytes

1/**
2 * OpenMage
3 *
4 * NOTICE OF LICENSE
5 *
6 * This source file is subject to the Academic Free License (AFL 3.0)
7 * that is bundled with this package in the file LICENSE_AFL.txt.
8 * It is also available through the world-wide-web at this URL:
9 * https://opensource.org/licenses/afl-3.0.php
10 * If you did not receive a copy of the license and are unable to
11 * obtain it through the world-wide-web, please send an email
12 * to [email protected] so we can send you a copy immediately.
13 *
14 * @category    Varien
15 * @package     js
16 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com)
17 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
18 */
19
20VarienForm = Class.create();
21VarienForm.prototype = {
22    initialize: function(formId, firstFieldFocus){
23        this.form       = $(formId);
24        if (!this.form) {
25            return;
26        }
27        this.cache      = $A();
28        this.currLoader = false;
29        this.currDataIndex = false;
30        this.validator  = new Validation(this.form);
31        this.elementFocus   = this.elementOnFocus.bindAsEventListener(this);
32        this.elementBlur    = this.elementOnBlur.bindAsEventListener(this);
33        this.childLoader    = this.onChangeChildLoad.bindAsEventListener(this);
34        this.highlightClass = 'highlight';
35        this.extraChildParams = '';
36        this.firstFieldFocus= firstFieldFocus || false;
37        this.bindElements();
38        if(this.firstFieldFocus){
39            try{
40                Form.Element.focus(Form.findFirstElement(this.form));
41            }
42            catch(e){}
43        }
44    },
45
46    submit : function(url){
47        if(this.validator && this.validator.validate()){
48             this.form.submit();
49        }
50        return false;
51    },
52
53    bindElements:function (){
54        var elements = Form.getElements(this.form);
55        for (var row in elements) {
56            if (elements[row].id) {
57                Event.observe(elements[row],'focus',this.elementFocus);
58                Event.observe(elements[row],'blur',this.elementBlur);
59            }
60        }
61    },
62
63    elementOnFocus: function(event){
64        var element = Event.findElement(event, 'fieldset');
65        if(element){
66            Element.addClassName(element, this.highlightClass);
67        }
68    },
69
70    elementOnBlur: function(event){
71        var element = Event.findElement(event, 'fieldset');
72        if(element){
73            Element.removeClassName(element, this.highlightClass);
74        }
75    },
76
77    setElementsRelation: function(parent, child, dataUrl, first){
78        if (parent=$(parent)) {
79            // TODO: array of relation and caching
80            if (!this.cache[parent.id]){
81                this.cache[parent.id] = $A();
82                this.cache[parent.id]['child']     = child;
83                this.cache[parent.id]['dataUrl']   = dataUrl;
84                this.cache[parent.id]['data']      = $A();
85                this.cache[parent.id]['first']      = first || false;
86            }
87            Event.observe(parent,'change',this.childLoader);
88        }
89    },
90
91    onChangeChildLoad: function(event){
92        element = Event.element(event);
93        this.elementChildLoad(element);
94    },
95
96    elementChildLoad: function(element, callback){
97        this.callback = callback || false;
98        if (element.value) {
99            this.currLoader = element.id;
100            this.currDataIndex = element.value;
101            if (this.cache[element.id]['data'][element.value]) {
102                this.setDataToChild(this.cache[element.id]['data'][element.value]);
103            }
104            else{
105                new Ajax.Request(this.cache[this.currLoader]['dataUrl'],{
106                        method: 'post',
107                        parameters: {"parent":element.value},
108                        onComplete: this.reloadChildren.bind(this)
109                });
110            }
111        }
112    },
113
114    reloadChildren: function(transport){
115        var data = transport.responseJSON || transport.responseText.evalJSON(true) || {};
116        this.cache[this.currLoader]['data'][this.currDataIndex] = data;
117        this.setDataToChild(data);
118    },
119
120    setDataToChild: function(data){
121        if (data.length) {
122            var child = $(this.cache[this.currLoader]['child']);
123            if (child){
124                var html = '<select name="'+child.name+'" id="'+child.id+'" class="'+child.className+'" title="'+child.title+'" '+this.extraChildParams+'>';
125                if(this.cache[this.currLoader]['first']){
126                    html+= '<option value="">'+this.cache[this.currLoader]['first']+'</option>';
127                }
128                for (var i in data){
129                    if(data[i].value) {
130                        html+= '<option value="'+data[i].value+'"';
131                        if(child.value && (child.value == data[i].value || child.value == data[i].label)){
132                            html+= ' selected';
133                        }
134                        html+='>'+data[i].label+'</option>';
135                    }
136                }
137                html+= '</select>';
138                Element.insert(child, {before: html});
139                Element.remove(child);
140            }
141        }
142        else{
143            var child = $(this.cache[this.currLoader]['child']);
144            if (child){
145                var html = '<input type="text" name="'+child.name+'" id="'+child.id+'" class="'+child.className+'" title="'+child.title+'" '+this.extraChildParams+'>';
146                Element.insert(child, {before: html});
147                Element.remove(child);
148            }
149        }
150
151        this.bindElements();
152        if (this.callback) {
153            this.callback();
154        }
155    }
156};
157
158RegionUpdater = Class.create();
159RegionUpdater.prototype = {
160    initialize: function (countryEl, regionTextEl, regionSelectEl, regions, disableAction, zipEl){
161        this.countryEl = $(countryEl);
162        this.regionTextEl = $(regionTextEl);
163        this.regionSelectEl = $(regionSelectEl);
164        this.zipEl = $(zipEl);
165        this.config = regions['config'];
166        delete regions.config;
167        this.regions = regions;
168
169        this.disableAction = (typeof disableAction=='undefined') ? 'hide' : disableAction;
170        this.zipOptions = (typeof zipOptions=='undefined') ? false : zipOptions;
171
172        if (this.regionSelectEl.options.length<=1) {
173            this.update();
174        }
175
176        Event.observe(this.countryEl, 'change', this.update.bind(this));
177    },
178
179    _checkRegionRequired: function(){
180        var label, wildCard;
181        var elements = [this.regionTextEl, this.regionSelectEl];
182        var that = this;
183        if (typeof this.config == 'undefined') {
184            return;
185        }
186        var regionRequired = this.config.regions_required.indexOf(this.countryEl.value) >= 0;
187
188        elements.each(function(currentElement) {
189            Validation.reset(currentElement);
190            label = $$('label[for="' + currentElement.id + '"]')[0];
191            if (label) {
192                wildCard = label.down('em') || label.down('span.required');
193                if (!wildCard) {
194                    label.insert(' <span class="required">*</span>');
195                    wildCard = label.down('span.required');
196                }
197                if (!that.config.show_all_regions) {
198                    if (regionRequired) {
199                        label.up().show();
200                    } else {
201                        label.up().hide();
202                    }
203                }
204            }
205
206            if (label && wildCard) {
207                if (!regionRequired) {
208                    wildCard.hide();
209                    if (label.hasClassName('required')) {
210                        label.removeClassName('required');
211                    }
212                } else if (regionRequired) {
213                    wildCard.show();
214                    if (!label.hasClassName('required')) {
215                        label.addClassName('required');
216                    }
217                }
218            }
219
220            if (!regionRequired) {
221                if (currentElement.hasClassName('required-entry')) {
222                    currentElement.removeClassName('required-entry');
223                }
224                if ('select' == currentElement.tagName.toLowerCase() &&
225                    currentElement.hasClassName('validate-select')) {
226                    currentElement.removeClassName('validate-select');
227                }
228            } else {
229                if (!currentElement.hasClassName('required-entry')) {
230                    currentElement.addClassName('required-entry');
231                }
232                if ('select' == currentElement.tagName.toLowerCase() &&
233                    !currentElement.hasClassName('validate-select')) {
234                    currentElement.addClassName('validate-select');
235                }
236            }
237        });
238    },
239
240    update: function(){
241        if (this.regions[this.countryEl.value]) {
242            var i, option, region, def;
243
244            def = this.regionSelectEl.getAttribute('defaultValue');
245            if (this.regionTextEl) {
246                if (!def) {
247                    def = this.regionTextEl.value.toLowerCase();
248                }
249                this.regionTextEl.value = '';
250            }
251
252            this.regionSelectEl.options.length = 1;
253            for (regionId in this.regions[this.countryEl.value]) {
254                region = this.regions[this.countryEl.value][regionId];
255
256                option = document.createElement('OPTION');
257                option.value = regionId;
258                option.text = region.name.stripTags();
259                option.title = region.name;
260
261                if (this.regionSelectEl.options.add) {
262                    this.regionSelectEl.options.add(option);
263                } else {
264                    this.regionSelectEl.appendChild(option);
265                }
266
267                if (regionId == def || (region.name && region.name.toLowerCase() == def)
268                    || (region.name && region.code.toLowerCase() == def)
269                ) {
270                    this.regionSelectEl.value = regionId;
271                }
272            }
273            this.sortSelect();
274            if (this.disableAction == 'hide') {
275                if (this.regionTextEl) {
276                    this.regionTextEl.style.display = 'none';
277                }
278
279                this.regionSelectEl.style.display = '';
280            } else if (this.disableAction == 'disable') {
281                if (this.regionTextEl) {
282                    this.regionTextEl.disabled = true;
283                }
284                this.regionSelectEl.disabled = false;
285            }
286            this.setMarkDisplay(this.regionSelectEl, true);
287        } else {
288            this.regionSelectEl.options.length = 1;
289            this.sortSelect();
290            if (this.disableAction == 'hide') {
291                if (this.regionTextEl) {
292                    this.regionTextEl.style.display = '';
293                }
294                this.regionSelectEl.style.display = 'none';
295                Validation.reset(this.regionSelectEl);
296            } else if (this.disableAction == 'disable') {
297                if (this.regionTextEl) {
298                    this.regionTextEl.disabled = false;
299                }
300                this.regionSelectEl.disabled = true;
301            } else if (this.disableAction == 'nullify') {
302                this.regionSelectEl.options.length = 1;
303                this.regionSelectEl.value = '';
304                this.regionSelectEl.selectedIndex = 0;
305                this.lastCountryId = '';
306            }
307            this.setMarkDisplay(this.regionSelectEl, false);
308        }
309
310        this._checkRegionRequired();
311        // Make Zip and its label required/optional
312        var zipUpdater = new ZipUpdater(this.countryEl.value, this.zipEl);
313        zipUpdater.update();
314    },
315
316    setMarkDisplay: function(elem, display){
317        elem = $(elem);
318        var labelElement = elem.up(0).down('label > span.required') ||
319                           elem.up(1).down('label > span.required') ||
320                           elem.up(0).down('label.required > em') ||
321                           elem.up(1).down('label.required > em');
322        if(labelElement) {
323            inputElement = labelElement.up().next('input');
324            if (display) {
325                labelElement.show();
326                if (inputElement) {
327                    inputElement.addClassName('required-entry');
328                }
329            } else {
330                labelElement.hide();
331                if (inputElement) {
332                    inputElement.removeClassName('required-entry');
333                }
334            }
335        }
336    },
337
338    sortSelect: function () {
339        var elem = this.regionSelectEl;
340        var tmpArray = new Array();
341        var currentVal = $(elem).value;
342        for (var i = 0; i < $(elem).options.length; i++) {
343            if (i == 0) {
344                continue;
345            }
346            tmpArray[i-1] = new Array();
347            tmpArray[i-1][0] = $(elem).options[i].text;
348            tmpArray[i-1][1] = $(elem).options[i].value;
349        }
350        tmpArray.sort();
351        for (var i = 1; i <= tmpArray.length; i++) {
352            var op = new Option(tmpArray[i-1][0], tmpArray[i-1][1]);
353            $(elem).options[i] = op;
354        }
355        $(elem).value = currentVal;
356        return;
357    }
358};
359
360ZipUpdater = Class.create();
361ZipUpdater.prototype = {
362    initialize: function(country, zipElement){
363        this.country = country;
364        this.zipElement = $(zipElement);
365    },
366
367    update: function(){
368        // Country ISO 2-letter codes must be pre-defined
369        if (typeof optionalZipCountries == 'undefined') {
370            return false;
371        }
372
373        // Ajax-request and normal content load compatibility
374        if (this.zipElement != undefined) {
375            Validation.reset(this.zipElement);
376            this._setPostcodeOptional();
377        } else {
378            Event.observe(window, "load", this._setPostcodeOptional.bind(this));
379        }
380    },
381
382    _setPostcodeOptional: function(){
383        this.zipElement = $(this.zipElement);
384        if (this.zipElement == undefined) {
385            return false;
386        }
387
388        // find label
389        var label = $$('label[for="' + this.zipElement.id + '"]')[0];
390        if (label != undefined) {
391            var wildCard = label.down('em') || label.down('span.required');
392            if (!wildCard) {
393                label.insert(' <span class="required">*</span>');
394                wildCard = label.down('span.required');
395            }
396        }
397
398        // Make Zip and its label required/optional
399        if (optionalZipCountries.indexOf(this.country) != -1) {
400            if (label.hasClassName('required')) {
401                label.removeClassName('required');
402            }
403            while (this.zipElement.hasClassName('required-entry')) {
404                this.zipElement.removeClassName('required-entry');
405            }
406            if (wildCard != undefined) {
407                wildCard.hide();
408            }
409        } else {
410            if (!label.hasClassName('required')) {
411                label.addClassName('required');
412            }
413            this.zipElement.addClassName('required-entry');
414            if (wildCard != undefined) {
415                wildCard.show();
416            }
417        }
418    }
419};

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.