Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed geo_autocomplete plugin and old demo.

  • Loading branch information...
commit c3626e8581950c98648ca97d14836480624ff7e9 1 parent 280814c
Julia West authored
66  demo/index.html
... ...
@@ -1,66 +0,0 @@
1  
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2  
-<html>
3  
-<head>
4  
-
5  
-<title>jQuery geo_Autocomplete Plugin</title>
6  
-<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
7  
-<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
8  
-
9  
-<!-- 
10  
-jquery.autocomplete.js requires a minor modification for geo_autocomplete to work
11  
-the following script includes the required mod
12  
--->
13  
-<script type="text/javascript" src="../lib/jquery.autocomplete_geomod.js"></script>
14  
-
15  
-<script type="text/javascript" src="../geo_autocomplete.js"></script>
16  
-<link rel="stylesheet" type="text/css" href="../lib/jquery.autocomplete.css" />
17  
-	
18  
-<script type="text/javascript">
19  
-$().ready(function() {
20  
-
21  
-    var latlng = new google.maps.LatLng(-34.397, 150.644);
22  
-    var myOptions = {
23  
-      zoom: 8,
24  
-      center: latlng,
25  
-      mapTypeId: google.maps.MapTypeId.ROADMAP
26  
-    };
27  
-    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
28  
-
29  
-	// use all the autocomplete options as documented at http://docs.jquery.com/Plugins/Autocomplete
30  
-	/* additional geo_autocomplete options:
31  
-		mapkey : 'ABQ...' (required for Static Maps thumbnails, obtain a key for your site from http://code.google.com/apis/maps/signup.html)
32  
-		mapwidth : 100
33  
-		mapheight : 100
34  
-		maptype : 'terrain' (see http://code.google.com/apis/maps/documentation/staticmaps/#MapTypes)
35  
-		mapsensor : true or false
36  
-	*/
37  
-	$('#location').geo_autocomplete(new google.maps.Geocoder, {
38  
-		mapkey: 'ABQIAAAAbnvDoAoYOSW2iqoXiGTpYBTIx7cuHpcaq3fYV4NM0BaZl8OxDxS9pQpgJkMv0RxjVl6cDGhDNERjaQ', 
39  
-		selectFirst: false,
40  
-		minChars: 3,
41  
-		cacheLength: 50,
42  
-		width: 300,
43  
-		scroll: true,
44  
-		scrollHeight: 330
45  
-	}).result(function(_event, _data) {
46  
-		if (_data) map.fitBounds(_data.geometry.viewport);
47  
-	});
48  
-
49  
-});
50  
-</script>
51  
-<style>
52  
-.ac_results li img {
53  
-	float: left;
54  
-	margin-right: 5px;
55  
-}
56  
-</style>
57  
-</head>
58  
-<body>
59  
-<h3><a href="http://code.google.com/p/geo-autocomplete">jQuery geo-autocomplete Plugin</a> Demo</h3>
60  
-
61  
-<div>Location: <input type="text" id="location" /> (autocomplete)</div>
62  
-<br/>
63  
-<div id="map_canvas" style="width:500px;height:350px;"/>
64  
-
65  
-</body>
66  
-</html>
BIN  demo/screenshot.png
BIN  demo/screenshot_small.png
68  geo_autocomplete.js
... ...
@@ -1,68 +0,0 @@
1  
-/*
2  
- * jQuery geo_autocomplete plugin 1.0
3  
- *
4  
- * Copyright (c) 2009 Bob Hitching
5  
- *
6  
- * Dual licensed under the MIT and GPL licenses:
7  
- *   http://www.opensource.org/licenses/mit-license.php
8  
- *   http://www.gnu.org/licenses/gpl.html
9  
- *
10  
- * Requires jQuery Autocomplete plugin by Jörn Zaefferer - see http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
11  
- * jquery.autocomplete.js requires a minor modification for geo_autocomplete to work, as shown in /lib/jquery.autocomplete_geomod.js
12  
- * 
13  
- */
14  
-;(function($) {
15  
-
16  
-$.fn.extend({
17  
-	geo_autocomplete: function(_geocoder, _options) {
18  
-		options = $.extend({}, $.Autocompleter.defaults, {
19  
-			geocoder: _geocoder,
20  
-			mapwidth: 100,
21  
-			mapheight: 100,
22  
-			maptype: 'terrain',
23  
-			mapkey: 'ABQIAAAAbnvDoAoYOSW2iqoXiGTpYBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQNumU68AwGqjbSNF9YO8NokKst8w', // localhost
24  
-			mapsensor: false,
25  
-			parse: function(_results, _status, _query) {
26  
-				var _parsed = [];
27  
-				if (_results && _status && _status == 'OK') {
28  
-					$.each(_results, function(_key, _result) {
29  
-						if (_result.geometry && _result.geometry.viewport) {
30  
-							// place is first matching segment, or first segment
31  
-							var _place_parts = _result.formatted_address.split(',');
32  
-							var _place = _place_parts[0];
33  
-							$.each(_place_parts, function(_key, _part) {
34  
-								if (_part.toLowerCase().indexOf(_query.toLowerCase()) != -1) {
35  
-									_place = $.trim(_part);
36  
-									return false; // break
37  
-								}
38  
-							});
39  
-							_parsed.push({
40  
-								data: _result,
41  
-								value: _place,
42  
-								result: _place
43  
-							});
44  
-						}
45  
-					});
46  
-				}
47  
-				return _parsed;
48  
-			},
49  
-			formatItem: function(_data, _i, _n, _value) {
50  
-				var _src = 'http://maps.google.com/maps/api/staticmap?visible=' + _data.geometry.viewport.getSouthWest().toUrlValue() + '|' + _data.geometry.viewport.getNorthEast().toUrlValue() + '&size=' + options.mapwidth + 'x' + options.mapheight + '&maptype=' + options.maptype + '&key=' + options.mapkey + '&sensor=' + (options.mapsensor ? 'true' : 'false');
51  
-				var _place = _data.formatted_address.replace(/,/gi, ',<br/>');
52  
-				return '<img src="' + _src + '" width="' + options.mapwidth + '" height="' + options.mapheight + '" /> ' + _place + '<br clear="both"/>';
53  
-			}
54  
-		}, _options);
55  
-		
56  
-		// if highlight is set to false, replace it with a do-nothing function
57  
-		options.highlight = options.highlight || function(value) { return value; };
58  
-		
59  
-		// if the formatMatch option is not specified, then use formatItem for backwards compatibility
60  
-		options.formatMatch = options.formatMatch || options.formatItem;
61  
-
62  
-		return this.each(function() {
63  
-			new $.Autocompleter(this, options);
64  
-		});
65  
-	}
66  
-});
67  
-
68  
-})(jQuery);
821  lib/jquery.autocomplete_geomod.js
... ...
@@ -1,821 +0,0 @@
1  
-/*
2  
- * jQuery Autocomplete plugin 1.1
3  
- *
4  
- * Copyright (c) 2009 Jörn Zaefferer
5  
- *
6  
- * Dual licensed under the MIT and GPL licenses:
7  
- *   http://www.opensource.org/licenses/mit-license.php
8  
- *   http://www.gnu.org/licenses/gpl.html
9  
- *
10  
- * Revision: $Id: jquery.autocomplete.js 15 2009-08-22 10:30:27Z joern.zaefferer $
11  
- */
12  
-
13  
-;(function($) {
14  
-	
15  
-$.fn.extend({
16  
-	autocomplete: function(urlOrData, options) {
17  
-		var isUrl = typeof urlOrData == "string";
18  
-		options = $.extend({}, $.Autocompleter.defaults, {
19  
-			url: isUrl ? urlOrData : null,
20  
-			data: isUrl ? null : urlOrData,
21  
-			delay: isUrl ? $.Autocompleter.defaults.delay : 10,
22  
-			max: options && !options.scroll ? 10 : 150
23  
-		}, options);
24  
-		
25  
-		// if highlight is set to false, replace it with a do-nothing function
26  
-		options.highlight = options.highlight || function(value) { return value; };
27  
-		
28  
-		// if the formatMatch option is not specified, then use formatItem for backwards compatibility
29  
-		options.formatMatch = options.formatMatch || options.formatItem;
30  
-		
31  
-		return this.each(function() {
32  
-			new $.Autocompleter(this, options);
33  
-		});
34  
-	},
35  
-	result: function(handler) {
36  
-		return this.bind("result", handler);
37  
-	},
38  
-	search: function(handler) {
39  
-		return this.trigger("search", [handler]);
40  
-	},
41  
-	flushCache: function() {
42  
-		return this.trigger("flushCache");
43  
-	},
44  
-	setOptions: function(options){
45  
-		return this.trigger("setOptions", [options]);
46  
-	},
47  
-	unautocomplete: function() {
48  
-		return this.trigger("unautocomplete");
49  
-	}
50  
-});
51  
-
52  
-$.Autocompleter = function(input, options) {
53  
-
54  
-	var KEY = {
55  
-		UP: 38,
56  
-		DOWN: 40,
57  
-		DEL: 46,
58  
-		TAB: 9,
59  
-		RETURN: 13,
60  
-		ESC: 27,
61  
-		COMMA: 188,
62  
-		PAGEUP: 33,
63  
-		PAGEDOWN: 34,
64  
-		BACKSPACE: 8
65  
-	};
66  
-
67  
-	// Create $ object for input element
68  
-	var $input = $(input).attr("autocomplete", "off").addClass(options.inputClass);
69  
-
70  
-	var timeout;
71  
-	var previousValue = "";
72  
-	var cache = $.Autocompleter.Cache(options);
73  
-	var hasFocus = 0;
74  
-	var lastKeyPressCode;
75  
-	var config = {
76  
-		mouseDownOnSelect: false
77  
-	};
78  
-	var select = $.Autocompleter.Select(options, input, selectCurrent, config);
79  
-	
80  
-	var blockSubmit;
81  
-	
82  
-	// prevent form submit in opera when selecting with return key
83  
-	$.browser.opera && $(input.form).bind("submit.autocomplete", function() {
84  
-		if (blockSubmit) {
85  
-			blockSubmit = false;
86  
-			return false;
87  
-		}
88  
-	});
89  
-	
90  
-	// only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all
91  
-	$input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
92  
-		// a keypress means the input has focus
93  
-		// avoids issue where input had focus before the autocomplete was applied
94  
-		hasFocus = 1;
95  
-		// track last key pressed
96  
-		lastKeyPressCode = event.keyCode;
97  
-		switch(event.keyCode) {
98  
-		
99  
-			case KEY.UP:
100  
-				event.preventDefault();
101  
-				if ( select.visible() ) {
102  
-					select.prev();
103  
-				} else {
104  
-					onChange(0, true);
105  
-				}
106  
-				break;
107  
-				
108  
-			case KEY.DOWN:
109  
-				event.preventDefault();
110  
-				if ( select.visible() ) {
111  
-					select.next();
112  
-				} else {
113  
-					onChange(0, true);
114  
-				}
115  
-				break;
116  
-				
117  
-			case KEY.PAGEUP:
118  
-				event.preventDefault();
119  
-				if ( select.visible() ) {
120  
-					select.pageUp();
121  
-				} else {
122  
-					onChange(0, true);
123  
-				}
124  
-				break;
125  
-				
126  
-			case KEY.PAGEDOWN:
127  
-				event.preventDefault();
128  
-				if ( select.visible() ) {
129  
-					select.pageDown();
130  
-				} else {
131  
-					onChange(0, true);
132  
-				}
133  
-				break;
134  
-			
135  
-			// matches also semicolon
136  
-			case options.multiple && $.trim(options.multipleSeparator) == "," && KEY.COMMA:
137  
-			case KEY.TAB:
138  
-			case KEY.RETURN:
139  
-				if( selectCurrent() ) {
140  
-					// stop default to prevent a form submit, Opera needs special handling
141  
-					event.preventDefault();
142  
-					blockSubmit = true;
143  
-					return false;
144  
-				}
145  
-				break;
146  
-				
147  
-			case KEY.ESC:
148  
-				select.hide();
149  
-				break;
150  
-				
151  
-			default:
152  
-				clearTimeout(timeout);
153  
-				timeout = setTimeout(onChange, options.delay);
154  
-				break;
155  
-		}
156  
-	}).focus(function(){
157  
-		// track whether the field has focus, we shouldn't process any
158  
-		// results if the field no longer has focus
159  
-		hasFocus++;
160  
-	}).blur(function() {
161  
-		hasFocus = 0;
162  
-		if (!config.mouseDownOnSelect) {
163  
-			hideResults();
164  
-		}
165  
-	}).click(function() {
166  
-		// show select when clicking in a focused field
167  
-		if ( hasFocus++ > 1 && !select.visible() ) {
168  
-			onChange(0, true);
169  
-		}
170  
-	}).bind("search", function() {
171  
-		// TODO why not just specifying both arguments?
172  
-		var fn = (arguments.length > 1) ? arguments[1] : null;
173  
-		function findValueCallback(q, data) {
174  
-			var result;
175  
-			if( data && data.length ) {
176  
-				for (var i=0; i < data.length; i++) {
177  
-					if( data[i].result.toLowerCase() == q.toLowerCase() ) {
178  
-						result = data[i];
179  
-						break;
180  
-					}
181  
-				}
182  
-			}
183  
-			if( typeof fn == "function" ) fn(result);
184  
-			else $input.trigger("result", result && [result.data, result.value]);
185  
-		}
186  
-		$.each(trimWords($input.val()), function(i, value) {
187  
-			request(value, findValueCallback, findValueCallback);
188  
-		});
189  
-	}).bind("flushCache", function() {
190  
-		cache.flush();
191  
-	}).bind("setOptions", function() {
192  
-		$.extend(options, arguments[1]);
193  
-		// if we've updated the data, repopulate
194  
-		if ( "data" in arguments[1] )
195  
-			cache.populate();
196  
-	}).bind("unautocomplete", function() {
197  
-		select.unbind();
198  
-		$input.unbind();
199  
-		$(input.form).unbind(".autocomplete");
200  
-	});
201  
-	
202  
-	
203  
-	function selectCurrent() {
204  
-		var selected = select.selected();
205  
-		if( !selected )
206  
-			return false;
207  
-		
208  
-		var v = selected.result;
209  
-		previousValue = v;
210  
-		
211  
-		if ( options.multiple ) {
212  
-			var words = trimWords($input.val());
213  
-			if ( words.length > 1 ) {
214  
-				var seperator = options.multipleSeparator.length;
215  
-				var cursorAt = $(input).selection().start;
216  
-				var wordAt, progress = 0;
217  
-				$.each(words, function(i, word) {
218  
-					progress += word.length;
219  
-					if (cursorAt <= progress) {
220  
-						wordAt = i;
221  
-						return false;
222  
-					}
223  
-					progress += seperator;
224  
-				});
225  
-				words[wordAt] = v;
226  
-				// TODO this should set the cursor to the right position, but it gets overriden somewhere
227  
-				//$.Autocompleter.Selection(input, progress + seperator, progress + seperator);
228  
-				v = words.join( options.multipleSeparator );
229  
-			}
230  
-			v += options.multipleSeparator;
231  
-		}
232  
-		
233  
-		$input.val(v);
234  
-		hideResultsNow();
235  
-		$input.trigger("result", [selected.data, selected.value]);
236  
-		return true;
237  
-	}
238  
-	
239  
-	function onChange(crap, skipPrevCheck) {
240  
-		if( lastKeyPressCode == KEY.DEL ) {
241  
-			select.hide();
242  
-			return;
243  
-		}
244  
-		
245  
-		var currentValue = $input.val();
246  
-		
247  
-		if ( !skipPrevCheck && currentValue == previousValue )
248  
-			return;
249  
-		
250  
-		previousValue = currentValue;
251  
-		
252  
-		currentValue = lastWord(currentValue);
253  
-		if ( currentValue.length >= options.minChars) {
254  
-			$input.addClass(options.loadingClass);
255  
-			if (!options.matchCase)
256  
-				currentValue = currentValue.toLowerCase();
257  
-			request(currentValue, receiveData, hideResultsNow);
258  
-		} else {
259  
-			stopLoading();
260  
-			select.hide();
261  
-		}
262  
-	};
263  
-	
264  
-	function trimWords(value) {
265  
-		if (!value)
266  
-			return [""];
267  
-		if (!options.multiple)
268  
-			return [$.trim(value)];
269  
-		return $.map(value.split(options.multipleSeparator), function(word) {
270  
-			return $.trim(value).length ? $.trim(word) : null;
271  
-		});
272  
-	}
273  
-	
274  
-	function lastWord(value) {
275  
-		if ( !options.multiple )
276  
-			return value;
277  
-		var words = trimWords(value);
278  
-		if (words.length == 1) 
279  
-			return words[0];
280  
-		var cursorAt = $(input).selection().start;
281  
-		if (cursorAt == value.length) {
282  
-			words = trimWords(value)
283  
-		} else {
284  
-			words = trimWords(value.replace(value.substring(cursorAt), ""));
285  
-		}
286  
-		return words[words.length - 1];
287  
-	}
288  
-	
289  
-	// fills in the input box w/the first match (assumed to be the best match)
290  
-	// q: the term entered
291  
-	// sValue: the first matching result
292  
-	function autoFill(q, sValue){
293  
-		// autofill in the complete box w/the first match as long as the user hasn't entered in more data
294  
-		// if the last user key pressed was backspace, don't autofill
295  
-		if( options.autoFill && (lastWord($input.val()).toLowerCase() == q.toLowerCase()) && lastKeyPressCode != KEY.BACKSPACE ) {
296  
-			// fill in the value (keep the case the user has typed)
297  
-			$input.val($input.val() + sValue.substring(lastWord(previousValue).length));
298  
-			// select the portion of the value not typed by the user (so the next character will erase)
299  
-			$(input).selection(previousValue.length, previousValue.length + sValue.length);
300  
-		}
301  
-	};
302  
-
303  
-	function hideResults() {
304  
-		clearTimeout(timeout);
305  
-		timeout = setTimeout(hideResultsNow, 200);
306  
-	};
307  
-
308  
-	function hideResultsNow() {
309  
-		var wasVisible = select.visible();
310  
-		select.hide();
311  
-		clearTimeout(timeout);
312  
-		stopLoading();
313  
-		if (options.mustMatch) {
314  
-			// call search and run callback
315  
-			$input.search(
316  
-				function (result){
317  
-					// if no value found, clear the input box
318  
-					if( !result ) {
319  
-						if (options.multiple) {
320  
-							var words = trimWords($input.val()).slice(0, -1);
321  
-							$input.val( words.join(options.multipleSeparator) + (words.length ? options.multipleSeparator : "") );
322  
-						}
323  
-						else {
324  
-							$input.val( "" );
325  
-							$input.trigger("result", null);
326  
-						}
327  
-					}
328  
-				}
329  
-			);
330  
-		}
331  
-	};
332  
-
333  
-	function receiveData(q, data) {
334  
-		if ( data && data.length && hasFocus ) {
335  
-			stopLoading();
336  
-			select.display(data, q);
337  
-			autoFill(q, data[0].value);
338  
-			select.show();
339  
-		} else {
340  
-			hideResultsNow();
341  
-		}
342  
-	};
343  
-
344  
-	function request(term, success, failure) {
345  
-		if (!options.matchCase)
346  
-			term = term.toLowerCase();
347  
-		var data = cache.load(term);
348  
-		// recieve the cached data
349  
-		if (data && data.length) {
350  
-			success(term, data);
351  
-
352  
-		// start geo_Autocomplete mod
353  
-		// request handler for google geocoder
354  
-		} else if (options.geocoder) {
355  
-			var _query = lastWord(term);
356  
-			options.geocoder.geocode({'address': _query}, function(_results, _status) {
357  
-				var parsed = options.parse(_results, _status, _query);
358  
-				cache.add(term, parsed);
359  
-				success(term, parsed);
360  
-			});
361  
-		// end geo_Autocomplete mod
362  
-				
363  
-		// if an AJAX url has been supplied, try loading the data now
364  
-		} else if( (typeof options.url == "string") && (options.url.length > 0) ){
365  
-			
366  
-			var extraParams = {
367  
-				timestamp: +new Date()
368  
-			};
369  
-			$.each(options.extraParams, function(key, param) {
370  
-				extraParams[key] = typeof param == "function" ? param() : param;
371  
-			});
372  
-						
373  
-			$.ajax({
374  
-				// try to leverage ajaxQueue plugin to abort previous requests
375  
-				mode: "abort",
376  
-				// limit abortion to this input
377  
-				port: "autocomplete" + input.name,
378  
-				dataType: options.dataType,
379  
-				url: options.url,
380  
-				data: $.extend({
381  
-					q: lastWord(term),
382  
-					limit: options.max
383  
-				}, extraParams),
384  
-				success: function(data) {
385  
-					var parsed = options.parse && options.parse(data) || parse(data);
386  
-					cache.add(term, parsed);
387  
-					success(term, parsed);
388  
-				}
389  
-			});
390  
-			
391  
-		} else {
392  
-			// if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match
393  
-			select.emptyList();
394  
-			failure(term);
395  
-		}
396  
-	};
397  
-	
398  
-	function parse(data) {
399  
-		var parsed = [];
400  
-		var rows = data.split("\n");
401  
-		for (var i=0; i < rows.length; i++) {
402  
-			var row = $.trim(rows[i]);
403  
-			if (row) {
404  
-				row = row.split("|");
405  
-				parsed[parsed.length] = {
406  
-					data: row,
407  
-					value: row[0],
408  
-					result: options.formatResult && options.formatResult(row, row[0]) || row[0]
409  
-				};
410  
-			}
411  
-		}
412  
-		return parsed;
413  
-	};
414  
-
415  
-	function stopLoading() {
416  
-		$input.removeClass(options.loadingClass);
417  
-	};
418  
-
419  
-};
420  
-
421  
-$.Autocompleter.defaults = {
422  
-	inputClass: "ac_input",
423  
-	resultsClass: "ac_results",
424  
-	loadingClass: "ac_loading",
425  
-	minChars: 1,
426  
-	delay: 400,
427  
-	matchCase: false,
428  
-	matchSubset: true,
429  
-	matchContains: false,
430  
-	cacheLength: 10,
431  
-	max: 100,
432  
-	mustMatch: false,
433  
-	extraParams: {},
434  
-	selectFirst: true,
435  
-	formatItem: function(row) { return row[0]; },
436  
-	formatMatch: null,
437  
-	autoFill: false,
438  
-	width: 0,
439  
-	multiple: false,
440  
-	multipleSeparator: ", ",
441  
-	highlight: function(value, term) {
442  
-		return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
443  
-	},
444  
-    scroll: true,
445  
-    scrollHeight: 180
446  
-};
447  
-
448  
-$.Autocompleter.Cache = function(options) {
449  
-
450  
-	var data = {};
451  
-	var length = 0;
452  
-	
453  
-	function matchSubset(s, sub) {
454  
-		if (!options.matchCase) 
455  
-			s = s.toLowerCase();
456  
-		var i = s.indexOf(sub);
457  
-		if (options.matchContains == "word"){
458  
-			i = s.toLowerCase().search("\\b" + sub.toLowerCase());
459  
-		}
460  
-		if (i == -1) return false;
461  
-		return i == 0 || options.matchContains;
462  
-	};
463  
-	
464  
-	function add(q, value) {
465  
-		if (length > options.cacheLength){
466  
-			flush();
467  
-		}
468  
-		if (!data[q]){ 
469  
-			length++;
470  
-		}
471  
-		data[q] = value;
472  
-	}
473  
-	
474  
-	function populate(){
475  
-		if( !options.data ) return false;
476  
-		// track the matches
477  
-		var stMatchSets = {},
478  
-			nullData = 0;
479  
-
480  
-		// no url was specified, we need to adjust the cache length to make sure it fits the local data store
481  
-		if( !options.url ) options.cacheLength = 1;
482  
-		
483  
-		// track all options for minChars = 0
484  
-		stMatchSets[""] = [];
485  
-		
486  
-		// loop through the array and create a lookup structure
487  
-		for ( var i = 0, ol = options.data.length; i < ol; i++ ) {
488  
-			var rawValue = options.data[i];
489  
-			// if rawValue is a string, make an array otherwise just reference the array
490  
-			rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue;
491  
-			
492  
-			var value = options.formatMatch(rawValue, i+1, options.data.length);
493  
-			if ( value === false )
494  
-				continue;
495  
-				
496  
-			var firstChar = value.charAt(0).toLowerCase();
497  
-			// if no lookup array for this character exists, look it up now
498  
-			if( !stMatchSets[firstChar] ) 
499  
-				stMatchSets[firstChar] = [];
500  
-
501  
-			// if the match is a string
502  
-			var row = {
503  
-				value: value,
504  
-				data: rawValue,
505  
-				result: options.formatResult && options.formatResult(rawValue) || value
506  
-			};
507  
-			
508  
-			// push the current match into the set list
509  
-			stMatchSets[firstChar].push(row);
510  
-
511  
-			// keep track of minChars zero items
512  
-			if ( nullData++ < options.max ) {
513  
-				stMatchSets[""].push(row);
514  
-			}
515  
-		};
516  
-
517  
-		// add the data items to the cache
518  
-		$.each(stMatchSets, function(i, value) {
519  
-			// increase the cache size
520  
-			options.cacheLength++;
521  
-			// add to the cache
522  
-			add(i, value);
523  
-		});
524  
-	}
525  
-	
526  
-	// populate any existing data
527  
-	setTimeout(populate, 25);
528  
-	
529  
-	function flush(){
530  
-		data = {};
531  
-		length = 0;
532  
-	}
533  
-	
534  
-	return {
535  
-		flush: flush,
536  
-		add: add,
537  
-		populate: populate,
538  
-		load: function(q) {
539  
-			if (!options.cacheLength || !length)
540  
-				return null;
541  
-			/* 
542  
-			 * if dealing w/local data and matchContains than we must make sure
543  
-			 * to loop through all the data collections looking for matches
544  
-			 */
545  
-			if( !options.url && options.matchContains ){
546  
-				// track all matches
547  
-				var csub = [];
548  
-				// loop through all the data grids for matches
549  
-				for( var k in data ){
550  
-					// don't search through the stMatchSets[""] (minChars: 0) cache
551  
-					// this prevents duplicates
552  
-					if( k.length > 0 ){
553  
-						var c = data[k];
554  
-						$.each(c, function(i, x) {
555  
-							// if we've got a match, add it to the array
556  
-							if (matchSubset(x.value, q)) {
557  
-								csub.push(x);
558  
-							}
559  
-						});
560  
-					}
561  
-				}				
562  
-				return csub;
563  
-			} else 
564  
-			// if the exact item exists, use it
565  
-			if (data[q]){
566  
-				return data[q];
567  
-			} else
568  
-			if (options.matchSubset) {
569  
-				for (var i = q.length - 1; i >= options.minChars; i--) {
570  
-					var c = data[q.substr(0, i)];
571  
-					if (c) {
572  
-						var csub = [];
573  
-						$.each(c, function(i, x) {
574  
-							if (matchSubset(x.value, q)) {
575  
-								csub[csub.length] = x;
576  
-							}
577  
-						});
578  
-						return csub;
579  
-					}
580  
-				}
581  
-			}
582  
-			return null;
583  
-		}
584  
-	};
585  
-};
586  
-
587  
-$.Autocompleter.Select = function (options, input, select, config) {
588  
-	var CLASSES = {
589  
-		ACTIVE: "ac_over"
590  
-	};
591  
-	
592  
-	var listItems,
593  
-		active = -1,
594  
-		data,
595  
-		term = "",
596  
-		needsInit = true,
597  
-		element,
598  
-		list;
599  
-	
600  
-	// Create results
601  
-	function init() {
602  
-		if (!needsInit)
603  
-			return;
604  
-		element = $("<div/>")
605  
-		.hide()
606  
-		.addClass(options.resultsClass)
607  
-		.css("position", "absolute")
608  
-		.appendTo(document.body);
609  
-	
610  
-		list = $("<ul/>").appendTo(element).mouseover( function(event) {
611  
-			if(target(event).nodeName && target(event).nodeName.toUpperCase() == 'LI') {
612  
-	            active = $("li", list).removeClass(CLASSES.ACTIVE).index(target(event));
613  
-			    $(target(event)).addClass(CLASSES.ACTIVE);            
614  
-	        }
615  
-		}).click(function(event) {
616  
-			$(target(event)).addClass(CLASSES.ACTIVE);
617  
-			select();
618  
-			// TODO provide option to avoid setting focus again after selection? useful for cleanup-on-focus
619  
-			input.focus();
620  
-			return false;
621  
-		}).mousedown(function() {
622  
-			config.mouseDownOnSelect = true;
623  
-		}).mouseup(function() {
624  
-			config.mouseDownOnSelect = false;
625  
-		});
626  
-		
627  
-		if( options.width > 0 )
628  
-			element.css("width", options.width);
629  
-			
630  
-		needsInit = false;
631  
-	} 
632  
-	
633  
-	function target(event) {
634  
-		var element = event.target;
635  
-		while(element && element.tagName != "LI")
636  
-			element = element.parentNode;
637  
-		// more fun with IE, sometimes event.target is empty, just ignore it then
638  
-		if(!element)
639  
-			return [];
640  
-		return element;
641  
-	}
642  
-
643  
-	function moveSelect(step) {
644  
-		listItems.slice(active, active + 1).removeClass(CLASSES.ACTIVE);
645  
-		movePosition(step);
646  
-        var activeItem = listItems.slice(active, active + 1).addClass(CLASSES.ACTIVE);
647  
-        if(options.scroll) {
648  
-            var offset = 0;
649  
-            listItems.slice(0, active).each(function() {
650  
-				offset += this.offsetHeight;
651  
-			});
652  
-            if((offset + activeItem[0].offsetHeight - list.scrollTop()) > list[0].clientHeight) {
653  
-                list.scrollTop(offset + activeItem[0].offsetHeight - list.innerHeight());
654  
-            } else if(offset < list.scrollTop()) {
655  
-                list.scrollTop(offset);
656  
-            }
657  
-        }
658  
-	};
659  
-	
660  
-	function movePosition(step) {
661  
-		active += step;
662  
-		if (active < 0) {
663  
-			active = listItems.size() - 1;
664  
-		} else if (active >= listItems.size()) {
665  
-			active = 0;
666  
-		}
667  
-	}
668  
-	
669  
-	function limitNumberOfItems(available) {
670  
-		return options.max && options.max < available
671  
-			? options.max
672  
-			: available;
673  
-	}
674  
-	
675  
-	function fillList() {
676  
-		list.empty();
677  
-		var max = limitNumberOfItems(data.length);
678  
-		for (var i=0; i < max; i++) {
679  
-			if (!data[i])
680  
-				continue;
681  
-			var formatted = options.formatItem(data[i].data, i+1, max, data[i].value, term);
682  
-			if ( formatted === false )
683  
-				continue;
684  
-			var li = $("<li/>").html( options.highlight(formatted, term) ).addClass(i%2 == 0 ? "ac_even" : "ac_odd").appendTo(list)[0];
685  
-			$.data(li, "ac_data", data[i]);
686  
-		}
687  
-		listItems = list.find("li");
688  
-		if ( options.selectFirst ) {
689  
-			listItems.slice(0, 1).addClass(CLASSES.ACTIVE);
690  
-			active = 0;
691  
-		}
692  
-		// apply bgiframe if available
693  
-		if ( $.fn.bgiframe )
694  
-			list.bgiframe();
695  
-	}
696  
-	
697  
-	return {
698  
-		display: function(d, q) {
699  
-			init();
700  
-			data = d;
701  
-			term = q;
702  
-			fillList();
703  
-		},
704  
-		next: function() {
705  
-			moveSelect(1);
706  
-		},
707  
-		prev: function() {
708  
-			moveSelect(-1);
709  
-		},
710  
-		pageUp: function() {
711  
-			if (active != 0 && active - 8 < 0) {
712  
-				moveSelect( -active );
713  
-			} else {
714  
-				moveSelect(-8);
715  
-			}
716  
-		},
717  
-		pageDown: function() {
718  
-			if (active != listItems.size() - 1 && active + 8 > listItems.size()) {
719  
-				moveSelect( listItems.size() - 1 - active );
720  
-			} else {
721  
-				moveSelect(8);
722  
-			}
723  
-		},
724  
-		hide: function() {
725  
-			element && element.hide();
726  
-			listItems && listItems.removeClass(CLASSES.ACTIVE);
727  
-			active = -1;
728  
-		},
729  
-		visible : function() {
730  
-			return element && element.is(":visible");
731  
-		},
732  
-		current: function() {
733  
-			return this.visible() && (listItems.filter("." + CLASSES.ACTIVE)[0] || options.selectFirst && listItems[0]);
734  
-		},
735  
-		show: function() {
736  
-			var offset = $(input).offset();
737  
-			element.css({
738  
-				width: typeof options.width == "string" || options.width > 0 ? options.width : $(input).width(),
739  
-				top: offset.top + input.offsetHeight,
740  
-				left: offset.left
741  
-			}).show();
742  
-            if(options.scroll) {
743  
-                list.scrollTop(0);
744  
-                list.css({
745  
-					maxHeight: options.scrollHeight,
746  
-					overflow: 'auto'
747  
-				});
748  
-				
749  
-                if($.browser.msie && typeof document.body.style.maxHeight === "undefined") {
750  
-					var listHeight = 0;
751  
-					listItems.each(function() {
752  
-						listHeight += this.offsetHeight;
753  
-					});
754  
-					var scrollbarsVisible = listHeight > options.scrollHeight;
755  
-                    list.css('height', scrollbarsVisible ? options.scrollHeight : listHeight );
756  
-					if (!scrollbarsVisible) {
757  
-						// IE doesn't recalculate width when scrollbar disappears
758  
-						listItems.width( list.width() - parseInt(listItems.css("padding-left")) - parseInt(listItems.css("padding-right")) );
759  
-					}
760  
-                }
761  
-                
762  
-            }
763  
-		},
764  
-		selected: function() {
765  
-			var selected = listItems && listItems.filter("." + CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);
766  
-			return selected && selected.length && $.data(selected[0], "ac_data");
767  
-		},
768  
-		emptyList: function (){
769  
-			list && list.empty();
770  
-		},
771  
-		unbind: function() {
772  
-			element && element.remove();
773  
-		}
774  
-	};
775  
-};
776  
-
777  
-$.fn.selection = function(start, end) {
778  
-	if (start !== undefined) {
779  
-		return this.each(function() {
780  
-			if( this.createTextRange ){
781  
-				var selRange = this.createTextRange();
782  
-				if (end === undefined || start == end) {
783  
-					selRange.move("character", start);
784  
-					selRange.select();
785  
-				} else {
786  
-					selRange.collapse(true);
787  
-					selRange.moveStart("character", start);
788  
-					selRange.moveEnd("character", end);
789  
-					selRange.select();
790  
-				}
791  
-			} else if( this.setSelectionRange ){
792  
-				this.setSelectionRange(start, end);
793  
-			} else if( this.selectionStart ){
794  
-				this.selectionStart = start;
795  
-				this.selectionEnd = end;
796  
-			}
797  
-		});
798  
-	}
799  
-	var field = this[0];
800  
-	if ( field.createTextRange ) {
801  
-		var range = document.selection.createRange(),
802  
-			orig = field.value,
803  
-			teststring = "<->",
804  
-			textLength = range.text.length;
805  
-		range.text = teststring;
806  
-		var caretAt = field.value.indexOf(teststring);
807  
-		field.value = orig;
808  
-		this.selection(caretAt, caretAt + textLength);
809  
-		return {
810  
-			start: caretAt,
811  
-			end: caretAt + textLength
812  
-		}
813  
-	} else if( field.selectionStart !== undefined ){
814  
-		return {
815  
-			start: field.selectionStart,
816  
-			end: field.selectionEnd
817  
-		}
818  
-	}
819  
-};
820  
-
821  
-})(jQuery);

0 notes on commit c3626e8

Please sign in to comment.
Something went wrong with that request. Please try again.