PageSourceSearch

https://www.dynomax.com/js/amasty/amfinder/finder.js

js dynomax.com collected 2026-10-05 01:03:41 UTC 4,124 bytes, 126 lines download raw bytes

1/**
2* @author Amasty Team
3* @copyright Copyright (c) 2010-2011 Amasty (http://www.amasty.com)
4* @package Amasty_Finder
5*/
6var amFinder = new Class.create();
7
8amFinder.prototype = {
9    initialize: function(containerId, ajaxUrl, loadingText, isNeedLast, autoSubmit)
10    {
11        this.containerId = containerId;
12        this.ajaxUrl	 = ajaxUrl;
13        this.autoSubmit  = autoSubmit;
14        this.loadingText = loadingText;
15        this.isNeedLast  = Number(isNeedLast);
16        this.selects     = new Array();
17        
18        //possible bug if select order in the HTML will be different
19    	$$('#' + this.containerId + ' select').each(function(select){
20    		select.observe('change', this.onChange.bindAsEventListener(this));
21    		this.selects[this.selects.length] = select;
22    	}.bind(this));
23    },
24        
25    onChange: function(event)
26    {
27    	var select     = Event.element(event);
28    	var parentId   = select.value;
29    	var dropdownId = 0;
30    	
31    	/* should load next element's options only if current is not the last one */
32    	for (var i = 0; i < this.selects.length; i++){
33    		if (this.selects[i].id == select.id && i != this.selects.length-1){
34    			var selectToReload = this.selects[i + 1];
35    			if (selectToReload){
36    				dropdownId = selectToReload.id.substr(selectToReload.id.search('--') + 2);
37    			}
38    			break;
39    		}
40    	}
41    	
42    	this.clearAllBelow(select);
43    	
44    	if (0 != parentId && dropdownId){
45    		var postData = 'dropdown_id=' + dropdownId + '&parent_id=' + parentId;
46    		new Ajax.Request(this.ajaxUrl, {
47                method: 'post',
48                postBody : postData,
49                evalJSON : 'force',
50                
51                onLoading: function(){
52                	this.showLoading(selectToReload);
53                }.bind(this),
54                
55                onSuccess: function(transport) {
56                    if (transport.responseJSON){
57                        this.clearSelectOptions(selectToReload);
58                    	var itemsFound = false;
59                    	transport.responseJSON.each(function(item){
60                    		itemsFound = true;
61                    		var option = document.createElement('option');
62                    		option.value = item.value;
63                    		option.text  = item.label;
64                    		option.label = item.label;
65                    		$(selectToReload).appendChild(option);
66                    	});
67                    	
68                    	if (itemsFound){
69                    		$(selectToReload).disabled = false;
70                    	}
71                    }
72                }.bind(this)
73            });
74    	}
75    },
76    
77    isLast: function(select)
78    {
79        return (this.selects[this.selects.length-1].id == select.id);    
80    },
81    
82    isFirst: function(select)
83    {
84        return (this.selects[0].id == select.id);         
85    },
86    
87    clearSelectOptions: function(select)
88    {
89    	$(select).descendants().each(function(option){
90    		option.remove();
91    	});
92    },
93    
94    clearAllBelow: function(select)
95    {
96    	var startClearing = false;
97    	for (var i = 0; i < this.selects.length; i++){
98    		if (startClearing){
99				this.clearSelectOptions(this.selects[i]);
100				$(this.selects[i]).disabled = true;
101			}
102    		if (this.selects[i].id == select.id){
103    			startClearing = true;
104    		}
105    	}
106    	var type = (((this.isLast(select) && !this.isNeedLast) && select.value > 0) || ((this.isNeedLast) && ((select.value > 0) || (!this.isFirst(select))))) ? 'block' : 'none';
107        
108        if ('block' == type && this.autoSubmit)
109        {
110            $$('#' + this.containerId + ' .amfinder-buttons button')[0].form.submit();
111        } else {
112            $$('#' + this.containerId + ' .amfinder-buttons')[0].style.display = type;            
113        }
114        
115
116    },
117    
118    showLoading: function(selectToReload)
119    {
120        var option = document.createElement('option');
121        option.value = 0;
122        option.text  = this.loadingText;
123        option.label = this.loadingText;
124        $(selectToReload).appendChild(option);        
125    },
126};

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.