PageSourceSearch

https://animalface.ru/js/frontend/lib/jquery.ac.js?47

js animalface.ru collected 2026-10-08 09:22:25 UTC 6,602 bytes, 214 lines download raw bytes

1// JavaScript Document
2
3var CurrentElementNumber = 0;
4
5(function($){  
6    $.fn.ac = function(options) {
7       
8	  options = $.extend({  
9         vF: null,
10		 dF: $(this).attr('id'),
11		 request : null,
12		 script : null,
13		 appendTo : null,
14		 type : 'local'  
15      }, options);
16	  
17	  return this.each(function() {  
18	  			
19		$('#' + options.vF).autocomplete({			
20		
21			source: function(request, response) {	
22				
23				reposition = false;
24				
25				if(options.type == 'local') {
26				
27					var req = new Object();
28
29					$.each(options.request, function(index, value) {
30						req[index] = $('#' + value).val();
31					});
32										
33					$.post(options.script, req, function(data) {
34
35						if(data == '') { 
36							data = {label: 'Ничего не найдено'}; 
37						}
38						
39						response(data);
40						
41					}, 'json');
42				
43				} else if(options.type == 'yandex') {
44					
45					ymaps.suggest($('#' + options.vF).val(), {results: 5}).then(function(items) {
46						var data = new Array();
47						
48						if(items.length == 0) {
49							data = {label: 'Ничего не найдено'};
50						
51						} else {
52							
53							$.each(items, function(index, value) {
54								var string = '', 
55									splitted = new Array();
56
57								splitted = value.value.split(',');
58								splitted.splice(0, 1);
59								
60								$.each(splitted, function(i, v) {
61									var comma = (i == 0) ? '' : ', ';
62									string += comma + $.trim(v)
63								});
64								
65								data.push({id: index, label: string});
66							});
67						}
68												
69						response(data);
70					});
71				}
72				
73			},
74				
75			minLength: 3,
76			appendTo: options.appendTo,
77			delay: 300,
78			autoFocus: true,
79			
80			open: function(event, ui) {
81								
82				/* create the scrollbar each time autocomplete menu opens/updates */
83				
84                $(options.appendTo).find('.ui-autocomplete').mCustomScrollbar({
85					scrollInertia: 0,
86                    autoHideScrollbar: false,
87					mouseWheel: { preventDefault: true }
88				});
89                
90			},		
91			
92			close: function(e, ui){
93				/* destroy the scrollbar each time autocomplete menu closes */
94				$(options.appendTo).find('.ui-autocomplete').mCustomScrollbar('destroy'); 
95			},
96			
97			response: function(e, ui) { 
98 				/* destroy the scrollbar after each search complete, before the menu is shown */ 
99                 CurrentElementNumber = 0;
100 				$(options.appendTo).find('.ui-autocomplete').mCustomScrollbar('destroy'); 
101 			}, 
102						
103			search: function(event, ui) {
104																			
105				if((options.dF == 'breed' || options.dF == 'synonym') && $('#kind').val() == '')
106					return false;
107					
108				if(options.dF == 's-breed' && $("#s-kind").val() == '')
109					return false;
110								
111					
112			},
113            
114            focus: function(event, ui) {
115                
116                 /* scroll via keyboard */
117                if(ui.item == undefined) {
118                    var last = $(options.appendTo).find('.ui-autocomplete li:eq(' + CurrentElementNumber + ')');
119				    last.trigger('mouseenter');
120				    $(this).val(last.data('uiAutocompleteItem').label);
121				}
122                
123                // Get Index number    
124                var CurrentIndex = $(options.appendTo).find('.ui-menu-item a').index($('a.ui-state-active'));    
125                
126                // If not found Exit
127                if(CurrentIndex == -1) {
128                    return false;
129                }
130                
131                /* scroll via keyboard */
132                var el = $(options.appendTo).find('.ui-state-active').parent();
133                                                            
134                if(el.viewport().inViewport() === false && !el.filter(':hover').length) {
135
136                    $(options.appendTo).find('.ui-menu-item').each(function(index, value) {
137                        
138                        if($(this).viewport().inViewport()) {
139                                                        
140                            // Go Down, from Up
141                            if(CurrentElementNumber == 0 && CurrentIndex == $(options.appendTo).find('.ui-menu-item').length - 1) {
142                               var goto = $(options.appendTo).find('.ui-menu-item:last');
143                            } 
144                            
145                            // Go Down   
146                            else if (CurrentIndex > CurrentElementNumber) {
147                               var goto = $(this).next();
148                            } 
149                            
150                            // Go Up    
151                            else {
152                               var goto = el;
153                            }
154                            
155                            $(options.appendTo).find('.ui-autocomplete').mCustomScrollbar('scrollTo', goto, {scrollInertia: 0, timeout: 0});    
156                            return false;
157                        }
158  
159                    });
160                    
161                }
162                
163                CurrentElementNumber = CurrentIndex;
164                         
165            },
166            
167			select: function(event, ui) {
168				
169				if(ui.item.label == 'ничего не найдено') {
170					$('#' + options.dF).val('');
171					return false;
172				}
173				
174				$("#" + options.dF).val(ui.item.id);
175				$("#" + options.vF).val(ui.item.label);					
176				
177				// Hide All Objects in Form
178				if(options.dF == 'owner-id') {
179					$('#owner-form > div').hide();
180					$('#owner-form > div:first, #owner-form > div:last').show();
181				}
182
183			}
184						
185		}).data('ui-autocomplete')._renderItem = function(ul, item) {
186						
187			if(item.label == 'Ничего не найдено') {
188                
189				var output = "<a class='not-found-data'>" + item.label + "</a>";
190            }
191            
192            else if(options.dF == 'search-company-field') {
193				var branch = (item.branch == undefined) ?  '' : item.branch + '/'; 
194				var output = '<a href="/company/' + item.id + '/' + branch + '" target="_blank">' + item.label + '</a>';
195			} 
196            
197            else if(options.dF == 'owner-id' || options.dF == 'owner') 
198				var output = "<a><strong>" + item.label + "</strong><span class='regcou'>" + item.phone + "</span></a>"
199			
200            else if(options.dF == 'company')
201				var output = "<a>" + item.kindTitle + ': ' + item.label + "<span class='regcou'>" + item.country + ", " + item.address +"</span></a>" 
202			else
203				var output = "<a>" + item.label + "</a>";
204					
205			return $("<li></li>")
206				.data("ui-autocomplete-item", item)
207				.append(output)
208				.appendTo(ul)
209		};
210		
211	  });	  
212    };
213
214})(jQuery);

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.