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