Subversion Repositories SmartDukaan

Rev

Rev 13532 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 13532 Rev 20239
Line 1... Line -...
1
/*
-
 
2
 * jQuery Autocomplete plugin 1.1
-
 
3
 *
-
 
4
 * Copyright (c) 2009 Jörn Zaefferer
-
 
5
 *
-
 
6
 * Dual licensed under the MIT and GPL licenses:
-
 
7
 *   http://www.opensource.org/licenses/mit-license.php
-
 
8
 *   http://www.gnu.org/licenses/gpl.html
-
 
9
 *
-
 
10
 * Revision: $Id: jquery.autocomplete.js 15 2009-08-22 10:30:27Z joern.zaefferer $
-
 
11
 */;
-
 
12
(function($) {
-
 
13
	$.fn.extend({
-
 
14
		autocomplete : function(urlOrData, options) {
-
 
15
			var isUrl = typeof urlOrData == "string";
-
 
16
			options = $.extend({}, $.Autocompleter.defaults, {
-
 
17
				url : isUrl ? urlOrData : null,
-
 
18
				data : isUrl ? null : urlOrData,
-
 
19
				delay : isUrl ? $.Autocompleter.defaults.delay : 10,
-
 
20
				max : options && !options.scroll ? 10 : 150
-
 
21
			}, options);
-
 
22
			options.highlight = options.highlight || function(value) {
-
 
23
				return value;
-
 
24
			};
-
 
25
			options.formatMatch = options.formatMatch || options.formatItem;
-
 
26
			return this.each(function() {
-
 
27
				new $.Autocompleter(this, options);
-
 
28
			});
-
 
29
		},
-
 
30
		result : function(handler) {
-
 
31
			return this.bind("result", handler);
-
 
32
		},
-
 
33
		search : function(handler) {
-
 
34
			return this.trigger("search", [ handler ]);
-
 
35
		},
-
 
36
		flushCache : function() {
-
 
37
			return this.trigger("flushCache");
-
 
38
		},
-
 
39
		setOptions : function(options) {
-
 
40
			return this.trigger("setOptions", [ options ]);
-
 
41
		},
-
 
42
		unautocomplete : function() {
-
 
43
			return this.trigger("unautocomplete");
-
 
44
		}
-
 
45
	});
-
 
46
	$.Autocompleter = function(input, options) {
-
 
47
		var KEY = {
-
 
48
			UP : 38,
-
 
49
			DOWN : 40,
-
 
50
			DEL : 46,
-
 
51
			TAB : 9,
-
 
52
			RETURN : 13,
-
 
53
			ESC : 27,
-
 
54
			COMMA : 188,
-
 
55
			PAGEUP : 33,
-
 
56
			PAGEDOWN : 34,
-
 
57
			BACKSPACE : 8
-
 
58
		};
-
 
59
		var $input = $(input).attr("autocomplete", "off").addClass(
-
 
60
				options.inputClass);
-
 
61
		var timeout;
-
 
62
		var previousValue = "";
-
 
63
		var cache = $.Autocompleter.Cache(options);
-
 
64
		var hasFocus = 0;
-
 
65
		var lastKeyPressCode;
-
 
66
		var config = {
-
 
67
			mouseDownOnSelect : false
-
 
68
		};
-
 
69
		var select = $.Autocompleter.Select(options, input, selectCurrent,
-
 
70
				config);
-
 
71
		var blockSubmit;
-
 
72
		$.browser.opera
-
 
73
				&& $(input.form).bind("submit.autocomplete", function() {
-
 
74
					if (blockSubmit) {
-
 
75
						blockSubmit = false;
-
 
76
						return false;
-
 
77
					}
-
 
78
				});
-
 
79
		$input.bind(
-
 
80
				($.browser.opera ? "keypress" : "keydown") + ".autocomplete",
-
 
81
				function(event) {
-
 
82
					hasFocus = 1;
-
 
83
					lastKeyPressCode = event.keyCode;
-
 
84
					switch (event.keyCode) {
-
 
85
					case KEY.UP:
-
 
86
						event.preventDefault();
-
 
87
						if (select.visible()) {
-
 
88
							select.prev();
-
 
89
						} else {
-
 
90
							onChange(0, true);
-
 
91
						}
-
 
92
						break;
-
 
93
					case KEY.DOWN:
-
 
94
						event.preventDefault();
-
 
95
						if (select.visible()) {
-
 
96
							select.next();
-
 
97
						} else {
-
 
98
							onChange(0, true);
-
 
99
						}
-
 
100
						break;
-
 
101
					case KEY.PAGEUP:
-
 
102
						event.preventDefault();
-
 
103
						if (select.visible()) {
-
 
104
							select.pageUp();
-
 
105
						} else {
-
 
106
							onChange(0, true);
-
 
107
						}
-
 
108
						break;
-
 
109
					case KEY.PAGEDOWN:
-
 
110
						event.preventDefault();
-
 
111
						if (select.visible()) {
-
 
112
							select.pageDown();
-
 
113
						} else {
-
 
114
							onChange(0, true);
-
 
115
						}
-
 
116
						break;
-
 
117
					case options.multiple
-
 
118
							&& $.trim(options.multipleSeparator) == ","
-
 
119
							&& KEY.COMMA:
-
 
120
					case KEY.TAB:
-
 
121
					case KEY.RETURN:
-
 
122
						if (selectCurrent()) {
-
 
123
							event.preventDefault();
-
 
124
							blockSubmit = true;
-
 
125
							return false;
-
 
126
						}
-
 
127
						break;
-
 
128
					case KEY.ESC:
-
 
129
						select.hide();
-
 
130
						break;
-
 
131
					default:
-
 
132
						clearTimeout(timeout);
-
 
133
						timeout = setTimeout(onChange, options.delay);
-
 
134
						break;
-
 
135
					}
-
 
136
				}).focus(function() {
-
 
137
			hasFocus++;
-
 
138
		}).blur(function() {
-
 
139
			hasFocus = 0;
-
 
140
			if (!config.mouseDownOnSelect) {
-
 
141
				hideResults();
-
 
142
			}
-
 
143
		}).click(function() {
-
 
144
			if (hasFocus++ > 1 && !select.visible()) {
-
 
145
				onChange(0, true);
-
 
146
			}
-
 
147
		}).bind(
-
 
148
				"search",
-
 
149
				function() {
-
 
150
					var fn = (arguments.length > 1) ? arguments[1] : null;
-
 
151
					function findValueCallback(q, data) {
-
 
152
						var result;
-
 
153
						if (data && data.length) {
-
 
154
							for ( var i = 0; i < data.length; i++) {
-
 
155
								if (data[i].result.toLowerCase() == q
-
 
156
										.toLowerCase()) {
-
 
157
									result = data[i];
-
 
158
									break;
-
 
159
								}
-
 
160
							}
-
 
161
						}
-
 
162
						if (typeof fn == "function")
-
 
163
							fn(result);
-
 
164
						else
-
 
165
							$input.trigger("result", result
-
 
166
									&& [ result.data, result.value ]);
-
 
167
					}
-
 
168
					$.each(trimWords($input.val()), function(i, value) {
-
 
169
						request(value, findValueCallback, findValueCallback);
-
 
170
					});
-
 
171
				}).bind("flushCache", function() {
-
 
172
			cache.flush();
-
 
173
		}).bind("setOptions", function() {
-
 
174
			$.extend(options, arguments[1]);
-
 
175
			if ("data" in arguments[1])
-
 
176
				cache.populate();
-
 
177
		}).bind("unautocomplete", function() {
-
 
178
			select.unbind();
-
 
179
			$input.unbind();
-
 
180
			$(input.form).unbind(".autocomplete");
-
 
181
		});
-
 
182
		function selectCurrent() {
-
 
183
			var selected = select.selected();
-
 
184
			if (!selected)
-
 
185
				return false;
-
 
186
			var v = selected.result;
-
 
187
			previousValue = v;
-
 
188
			if (options.multiple) {
-
 
189
				var words = trimWords($input.val());
-
 
190
				if (words.length > 1) {
-
 
191
					var seperator = options.multipleSeparator.length;
-
 
192
					var cursorAt = $(input).selection().start;
-
 
193
					var wordAt, progress = 0;
-
 
194
					$.each(words, function(i, word) {
-
 
195
						progress += word.length;
-
 
196
						if (cursorAt <= progress) {
-
 
197
							wordAt = i;
-
 
198
							return false;
-
 
199
						}
-
 
200
						progress += seperator;
-
 
201
					});
-
 
202
					words[wordAt] = v;
-
 
203
					v = words.join(options.multipleSeparator);
-
 
204
				}
-
 
205
				v += options.multipleSeparator;
-
 
206
			}
-
 
207
			$input.val(v);
-
 
208
			hideResultsNow();
-
 
209
			$input.trigger("result", [ selected.data, selected.value ]);
-
 
210
			return true;
-
 
211
		}
-
 
212
		function onChange(crap, skipPrevCheck) {
-
 
213
			if (lastKeyPressCode == KEY.DEL) {
-
 
214
				select.hide();
-
 
215
				return;
-
 
216
			}
-
 
217
			var currentValue = $input.val();
-
 
218
			if (!skipPrevCheck && currentValue == previousValue)
-
 
219
				return;
-
 
220
			previousValue = currentValue;
-
 
221
			currentValue = lastWord(currentValue);
-
 
222
			if (currentValue.length >= options.minChars) {
-
 
223
				$input.addClass(options.loadingClass);
-
 
224
				if (!options.matchCase)
-
 
225
					currentValue = currentValue.toLowerCase();
-
 
226
				request(currentValue, receiveData, hideResultsNow);
-
 
227
			} else {
-
 
228
				stopLoading();
-
 
229
				select.hide();
-
 
230
			}
-
 
231
		}
-
 
232
		;
-
 
233
		function trimWords(value) {
-
 
234
			if (!value)
-
 
235
				return [ "" ];
-
 
236
			if (!options.multiple)
-
 
237
				return [ $.trim(value) ];
-
 
238
			return $.map(value.split(options.multipleSeparator),
-
 
239
					function(word) {
-
 
240
						return $.trim(value).length ? $.trim(word) : null;
-
 
241
					});
-
 
242
		}
-
 
243
		function lastWord(value) {
-
 
244
			if (!options.multiple)
-
 
245
				return value;
-
 
246
			var words = trimWords(value);
-
 
247
			if (words.length == 1)
-
 
248
				return words[0];
-
 
249
			var cursorAt = $(input).selection().start;
-
 
250
			if (cursorAt == value.length) {
-
 
251
				words = trimWords(value)
-
 
252
			} else {
-
 
253
				words = trimWords(value.replace(value.substring(cursorAt), ""));
-
 
254
			}
-
 
255
			return words[words.length - 1];
-
 
256
		}
-
 
257
		function autoFill(q, sValue) {
-
 
258
			if (options.autoFill
-
 
259
					&& (lastWord($input.val()).toLowerCase() == q.toLowerCase())
-
 
260
					&& lastKeyPressCode != KEY.BACKSPACE) {
-
 
261
				$input.val($input.val()
-
 
262
						+ sValue.substring(lastWord(previousValue).length));
-
 
263
				$(input).selection(previousValue.length,
-
 
264
						previousValue.length + sValue.length);
-
 
265
			}
-
 
266
		}
-
 
267
		;
-
 
268
		function hideResults() {
-
 
269
			clearTimeout(timeout);
-
 
270
			timeout = setTimeout(hideResultsNow, 200);
-
 
271
		}
-
 
272
		;
-
 
273
		function hideResultsNow() {
-
 
274
			var wasVisible = select.visible();
-
 
275
			select.hide();
-
 
276
			clearTimeout(timeout);
-
 
277
			stopLoading();
-
 
278
			if (options.mustMatch) {
-
 
279
				$input.search(function(result) {
-
 
280
					if (!result) {
-
 
281
						if (options.multiple) {
-
 
282
							var words = trimWords($input.val()).slice(0, -1);
-
 
283
							$input.val(words.join(options.multipleSeparator)
-
 
284
									+ (words.length ? options.multipleSeparator
-
 
285
											: ""));
-
 
286
						} else {
-
 
287
							$input.val("");
-
 
288
							$input.trigger("result", null);
-
 
289
						}
-
 
290
					}
-
 
291
				});
-
 
292
			}
-
 
293
		}
-
 
294
		;
-
 
295
		function receiveData(q, data) {
-
 
296
			if (data && data.length && hasFocus) {
-
 
297
				stopLoading();
-
 
298
				select.display(data, q);
-
 
299
				autoFill(q, data[0].value);
-
 
300
				select.show();
-
 
301
			} else {
-
 
302
				hideResultsNow();
-
 
303
			}
-
 
304
		}
-
 
305
		;
-
 
306
		function request(term, success, failure) {
-
 
307
			if (!options.matchCase)
-
 
308
				term = term.toLowerCase();
-
 
309
			var data = cache.load(term);
-
 
310
			if (data && data.length) {
-
 
311
				success(term, data);
-
 
312
			} else if ((typeof options.url == "string")
-
 
313
					&& (options.url.length > 0)) {
-
 
314
				var extraParams = {
-
 
315
					timestamp : +new Date()
-
 
316
				};
-
 
317
				$.each(options.extraParams, function(key, param) {
-
 
318
					extraParams[key] = typeof param == "function" ? param()
-
 
319
							: param;
-
 
320
				});
-
 
321
				$.ajax({
-
 
322
					mode : "abort",
-
 
323
					port : "autocomplete" + input.name,
-
 
324
					dataType : options.dataType,
-
 
325
					url : options.url,
-
 
326
					data : $.extend({
-
 
327
						q : lastWord(term),
-
 
328
						limit : options.max
-
 
329
					}, extraParams),
-
 
330
					success : function(data) {
-
 
331
						var parsed = options.parse && options.parse(data)
-
 
332
								|| parse(data);
-
 
333
						cache.add(term, parsed);
-
 
334
						success(term, parsed);
-
 
335
					}
-
 
336
				});
-
 
337
			} else {
-
 
338
				select.emptyList();
-
 
339
				failure(term);
-
 
340
			}
-
 
341
		}
-
 
342
		;
-
 
343
		function parse(data) {
-
 
344
			var parsed = [];
-
 
345
			var rows = data.split("\n");
-
 
346
			for ( var i = 0; i < rows.length; i++) {
-
 
347
				var row = $.trim(rows[i]);
-
 
348
				if (row) {
-
 
349
					row = row.split("|");
-
 
350
					parsed[parsed.length] = {
-
 
351
						data : row,
-
 
352
						value : row[0],
-
 
353
						result : options.formatResult
-
 
354
								&& options.formatResult(row, row[0]) || row[0]
-
 
355
					};
-
 
356
				}
-
 
357
			}
-
 
358
			return parsed;
-
 
359
		}
-
 
360
		;
-
 
361
		function stopLoading() {
-
 
362
			$input.removeClass(options.loadingClass);
-
 
363
		}
-
 
364
		;
-
 
365
	};
-
 
366
	$.Autocompleter.defaults = {
-
 
367
		inputClass : "ac_input",
-
 
368
		resultsClass : "ac_results",
-
 
369
		loadingClass : "ac_loading",
-
 
370
		minChars : 1,
-
 
371
		delay : 400,
-
 
372
		matchCase : false,
-
 
373
		matchSubset : true,
-
 
374
		matchContains : false,
-
 
375
		cacheLength : 10,
-
 
376
		max : 100,
-
 
377
		mustMatch : false,
-
 
378
		extraParams : {},
-
 
379
		selectFirst : true,
-
 
380
		formatItem : function(row) {
-
 
381
			return row[0];
-
 
382
		},
-
 
383
		formatMatch : null,
-
 
384
		autoFill : false,
-
 
385
		width : 0,
-
 
386
		multiple : false,
-
 
387
		multipleSeparator : ", ",
-
 
388
		highlight : function(value, term) {
-
 
389
			return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)("
-
 
390
					+ term
-
 
391
							.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi,
-
 
392
									"\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"),
-
 
393
					"<strong>$1</strong>");
-
 
394
		},
-
 
395
		scroll : true,
-
 
396
		scrollHeight : 180
-
 
397
	};
-
 
398
	$.Autocompleter.Cache = function(options) {
-
 
399
		var data = {};
-
 
400
		var length = 0;
-
 
401
		function matchSubset(s, sub) {
-
 
402
			if (!options.matchCase)
-
 
403
				s = s.toLowerCase();
-
 
404
			var i = s.indexOf(sub);
-
 
405
			if (options.matchContains == "word") {
-
 
406
				i = s.toLowerCase().search("\\b" + sub.toLowerCase());
-
 
407
			}
-
 
408
			if (i == -1)
-
 
409
				return false;
-
 
410
			return i == 0 || options.matchContains;
-
 
411
		}
-
 
412
		;
-
 
413
		function add(q, value) {
-
 
414
			if (length > options.cacheLength) {
-
 
415
				flush();
-
 
416
			}
-
 
417
			if (!data[q]) {
-
 
418
				length++;
-
 
419
			}
-
 
420
			data[q] = value;
-
 
421
		}
-
 
422
		function populate() {
-
 
423
			if (!options.data)
-
 
424
				return false;
-
 
425
			var stMatchSets = {}, nullData = 0;
-
 
426
			if (!options.url)
-
 
427
				options.cacheLength = 1;
-
 
428
			stMatchSets[""] = [];
-
 
429
			for ( var i = 0, ol = options.data.length; i < ol; i++) {
-
 
430
				var rawValue = options.data[i];
-
 
431
				rawValue = (typeof rawValue == "string") ? [ rawValue ]
-
 
432
						: rawValue;
-
 
433
				var value = options.formatMatch(rawValue, i + 1,
-
 
434
						options.data.length);
-
 
435
				if (value === false)
-
 
436
					continue;
-
 
437
				var firstChar = value.charAt(0).toLowerCase();
-
 
438
				if (!stMatchSets[firstChar])
-
 
439
					stMatchSets[firstChar] = [];
-
 
440
				var row = {
-
 
441
					value : value,
-
 
442
					data : rawValue,
-
 
443
					result : options.formatResult
-
 
444
							&& options.formatResult(rawValue) || value
-
 
445
				};
-
 
446
				stMatchSets[firstChar].push(row);
-
 
447
				if (nullData++ < options.max) {
-
 
448
					stMatchSets[""].push(row);
-
 
449
				}
-
 
450
			}
-
 
451
			;
-
 
452
			$.each(stMatchSets, function(i, value) {
-
 
453
				options.cacheLength++;
-
 
454
				add(i, value);
-
 
455
			});
-
 
456
		}
-
 
457
		setTimeout(populate, 25);
-
 
458
		function flush() {
-
 
459
			data = {};
-
 
460
			length = 0;
-
 
461
		}
-
 
462
		return {
-
 
463
			flush : flush,
-
 
464
			add : add,
-
 
465
			populate : populate,
-
 
466
			load : function(q) {
-
 
467
				if (!options.cacheLength || !length)
-
 
468
					return null;
-
 
469
				if (!options.url && options.matchContains) {
-
 
470
					var csub = [];
-
 
471
					for ( var k in data) {
-
 
472
						if (k.length > 0) {
-
 
473
							var c = data[k];
-
 
474
							$.each(c, function(i, x) {
-
 
475
								if (matchSubset(x.value, q)) {
-
 
476
									csub.push(x);
-
 
477
								}
-
 
478
							});
-
 
479
						}
-
 
480
					}
-
 
481
					return csub;
-
 
482
				} else if (data[q]) {
-
 
483
					return data[q];
-
 
484
				} else if (options.matchSubset) {
-
 
485
					for ( var i = q.length - 1; i >= options.minChars; i--) {
-
 
486
						var c = data[q.substr(0, i)];
-
 
487
						if (c) {
-
 
488
							var csub = [];
-
 
489
							$.each(c, function(i, x) {
-
 
490
								if (matchSubset(x.value, q)) {
-
 
491
									csub[csub.length] = x;
-
 
492
								}
-
 
493
							});
-
 
494
							return csub;
-
 
495
						}
-
 
496
					}
-
 
497
				}
-
 
498
				return null;
-
 
499
			}
-
 
500
		};
-
 
501
	};
-
 
502
	$.Autocompleter.Select = function(options, input, select, config) {
-
 
503
		var CLASSES = {
-
 
504
			ACTIVE : "ac_over"
-
 
505
		};
-
 
506
		var listItems, active = -1, data, term = "", needsInit = true, element, list;
-
 
507
		function init() {
-
 
508
			if (!needsInit)
-
 
509
				return;
-
 
510
			element = $("<div/>").hide().addClass(options.resultsClass).css(
-
 
511
					"position", "absolute").appendTo(document.body);
-
 
512
			list = $("<ul/>")
-
 
513
					.appendTo(element)
-
 
514
					.mouseover(
-
 
515
							function(event) {
-
 
516
								if (target(event).nodeName
-
 
517
										&& target(event).nodeName.toUpperCase() == 'LI') {
-
 
518
									active = $("li", list).removeClass(
-
 
519
											CLASSES.ACTIVE)
-
 
520
											.index(target(event));
-
 
521
									$(target(event)).addClass(CLASSES.ACTIVE);
-
 
522
								}
-
 
523
							}).click(function(event) {
-
 
524
						$(target(event)).addClass(CLASSES.ACTIVE);
-
 
525
						select();
-
 
526
						input.focus();
-
 
527
						return false;
-
 
528
					}).mousedown(function() {
-
 
529
						config.mouseDownOnSelect = true;
-
 
530
					}).mouseup(function() {
-
 
531
						config.mouseDownOnSelect = false;
-
 
532
					});
-
 
533
			if (options.width > 0){
-
 
534
				element.css("width", options.width);
-
 
535
			}else{
-
 
536
				options.width = 232;
-
 
537
				element.css("width", options.width);
-
 
538
			}
-
 
539
			needsInit = false;
-
 
540
		}
-
 
541
		function target(event) {
-
 
542
			var element = event.target;
-
 
543
			while (element && element.tagName != "LI")
-
 
544
				element = element.parentNode;
-
 
545
			if (!element)
-
 
546
				return [];
-
 
547
			return element;
-
 
548
		}
-
 
549
		function moveSelect(step) {
-
 
550
			listItems.slice(active, active + 1).removeClass(CLASSES.ACTIVE);
-
 
551
			movePosition(step);
-
 
552
			var activeItem = listItems.slice(active, active + 1).addClass(
-
 
553
					CLASSES.ACTIVE);
-
 
554
			if (options.scroll) {
-
 
555
				var offset = 0;
-
 
556
				listItems.slice(0, active).each(function() {
-
 
557
					offset += this.offsetHeight;
-
 
558
				});
-
 
559
				if ((offset + activeItem[0].offsetHeight - list.scrollTop()) > list[0].clientHeight) {
-
 
560
					list.scrollTop(offset + activeItem[0].offsetHeight
-
 
561
							- list.innerHeight());
-
 
562
				} else if (offset < list.scrollTop()) {
-
 
563
					list.scrollTop(offset);
-
 
564
				}
-
 
565
			}
-
 
566
		}
-
 
567
		;
-
 
568
		function movePosition(step) {
-
 
569
			active += step;
-
 
570
			if (active < 0) {
-
 
571
				active = listItems.size() - 1;
-
 
572
			} else if (active >= listItems.size()) {
-
 
573
				active = 0;
-
 
574
			}
-
 
575
		}
-
 
576
		function limitNumberOfItems(available) {
-
 
577
			return options.max && options.max < available ? options.max
-
 
578
					: available;
-
 
579
		}
-
 
580
		function fillList() {
-
 
581
			list.empty();
-
 
582
			var max = limitNumberOfItems(data.length);
-
 
583
			for ( var i = 0; i < max; i++) {
-
 
584
				if (!data[i])
-
 
585
					continue;
-
 
586
				var formatted = options.formatItem(data[i].data, i + 1, max,
-
 
587
						data[i].value, term);
-
 
588
				if (formatted === false)
-
 
589
					continue;
-
 
590
				var li = $("<li/>").html(options.highlight(formatted, term))
-
 
591
						.addClass(i % 2 == 0 ? "ac_even" : "ac_odd").appendTo(
-
 
592
								list)[0];
-
 
593
				$.data(li, "ac_data", data[i]);
-
 
594
			}
-
 
595
			listItems = list.find("li");
-
 
596
			if (options.selectFirst) {
-
 
597
				listItems.slice(0, 1).addClass(CLASSES.ACTIVE);
-
 
598
				active = 0;
-
 
599
			}
-
 
600
			if ($.fn.bgiframe)
-
 
601
				list.bgiframe();
-
 
602
		}
-
 
603
		return {
-
 
604
			display : function(d, q) {
-
 
605
				init();
-
 
606
				data = d;
-
 
607
				term = q;
-
 
608
				fillList();
-
 
609
			},
-
 
610
			next : function() {
-
 
611
				moveSelect(1);
-
 
612
			},
-
 
613
			prev : function() {
-
 
614
				moveSelect(-1);
-
 
615
			},
-
 
616
			pageUp : function() {
-
 
617
				if (active != 0 && active - 8 < 0) {
-
 
618
					moveSelect(-active);
-
 
619
				} else {
-
 
620
					moveSelect(-8);
-
 
621
				}
-
 
622
			},
-
 
623
			pageDown : function() {
-
 
624
				if (active != listItems.size() - 1
-
 
625
						&& active + 8 > listItems.size()) {
-
 
626
					moveSelect(listItems.size() - 1 - active);
-
 
627
				} else {
-
 
628
					moveSelect(8);
-
 
629
				}
-
 
630
			},
-
 
631
			hide : function() {
-
 
632
				element && element.hide();
-
 
633
				listItems && listItems.removeClass(CLASSES.ACTIVE);
-
 
634
				active = -1;
-
 
635
			},
-
 
636
			visible : function() {
-
 
637
				return element && element.is(":visible");
-
 
638
			},
-
 
639
			current : function() {
-
 
640
				return this.visible()
-
 
641
						&& (listItems.filter("." + CLASSES.ACTIVE)[0] || options.selectFirst
-
 
642
								&& listItems[0]);
-
 
643
			},
-
 
644
			show : function() {
-
 
645
				var offset = $(input).offset();
-
 
646
				element.css(
-
 
647
						{
-
 
648
							width : typeof options.width == "string"
-
 
649
									|| options.width > 0 ? options.width : $(
-
 
650
									input).width(),
-
 
651
							top : offset.top + input.offsetHeight,
-
 
652
							left : offset.left
-
 
653
						}).show();
-
 
654
				if (options.scroll) {
-
 
655
					list.scrollTop(0);
-
 
656
					list.css({
-
 
657
						//maxHeight : options.scrollHeight,
-
 
658
						overflow : 'auto'
-
 
659
					});
-
 
660
					if ($.browser.msie
-
 
661
							&& typeof document.body.style.maxHeight === "undefined") {
-
 
662
						var listHeight = 0;
-
 
663
						listItems.each(function() {
-
 
664
							listHeight += this.offsetHeight;
-
 
665
						});
-
 
666
						var scrollbarsVisible = listHeight > options.scrollHeight;
-
 
667
						list.css('height',
-
 
668
								scrollbarsVisible ? options.scrollHeight
-
 
669
										: listHeight);
-
 
670
						if (!scrollbarsVisible) {
-
 
671
							listItems.width(list.width()
-
 
672
									- parseInt(listItems.css("padding-left"))
-
 
673
									- parseInt(listItems.css("padding-right")));
-
 
674
						}
-
 
675
					}
-
 
676
				}
-
 
677
			},
-
 
678
			selected : function() {
-
 
679
				var selected = listItems
-
 
680
						&& listItems.filter("." + CLASSES.ACTIVE).removeClass(
-
 
681
								CLASSES.ACTIVE);
-
 
682
				return selected && selected.length
-
 
683
						&& $.data(selected[0], "ac_data");
-
 
684
			},
-
 
685
			emptyList : function() {
-
 
686
				list && list.empty();
-
 
687
			},
-
 
688
			unbind : function() {
-
 
689
				element && element.remove();
-
 
690
			}
-
 
691
		};
-
 
692
	};
-
 
693
	$.fn.selection = function(start, end) {
-
 
694
		if (start !== undefined) {
-
 
695
			return this.each(function() {
-
 
696
				if (this.createTextRange) {
-
 
697
					var selRange = this.createTextRange();
-
 
698
					if (end === undefined || start == end) {
-
 
699
						selRange.move("character", start);
-
 
700
						selRange.select();
-
 
701
					} else {
-
 
702
						selRange.collapse(true);
-
 
703
						selRange.moveStart("character", start);
-
 
704
						selRange.moveEnd("character", end);
-
 
705
						selRange.select();
-
 
706
					}
-
 
707
				} else if (this.setSelectionRange) {
-
 
708
					this.setSelectionRange(start, end);
-
 
709
				} else if (this.selectionStart) {
-
 
710
					this.selectionStart = start;
-
 
711
					this.selectionEnd = end;
-
 
712
				}
-
 
713
			});
-
 
714
		}
-
 
715
		var field = this[0];
-
 
716
		if (field.createTextRange) {
-
 
717
			var range = document.selection.createRange(), orig = field.value, teststring = "<->", textLength = range.text.length;
-
 
718
			range.text = teststring;
-
 
719
			var caretAt = field.value.indexOf(teststring);
-
 
720
			field.value = orig;
-
 
721
			this.selection(caretAt, caretAt + textLength);
-
 
722
			return {
-
 
723
				start : caretAt,
-
 
724
				end : caretAt + textLength
-
 
725
			}
-
 
726
		} else if (field.selectionStart !== undefined) {
-
 
727
			return {
-
 
728
				start : field.selectionStart,
-
 
729
				end : field.selectionEnd
-
 
730
			}
-
 
731
		}
-
 
732
	};
-
 
733
})(jQuery);
-
 
734
1
/**
-
 
2
*  Ajax Autocomplete for jQuery, version 1.2.7
-
 
3
*  (c) 2013 Tomas Kirda
-
 
4
*
-
 
5
*  Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
-
 
6
*  For details, see the web site: http://www.devbridge.com/projects/autocomplete/jquery/
-
 
7
*
-
 
8
*/
-
 
9
(function(e){"function"===typeof define&&define.amd?define(["jquery"],e):e(jQuery)})(function(e){function g(a,b){var c=function(){},c={autoSelectFirst:!1,appendTo:"body",serviceUrl:null,lookup:null,onSelect:null,width:"auto",minChars:1,maxHeight:300,deferRequestBy:0,params:{},formatResult:g.formatResult,delimiter:null,zIndex:9999,type:"GET",noCache:!1,onSearchStart:c,onSearchComplete:c,containerClass:"autocomplete-suggestions",tabDisabled:!1,dataType:"text",lookupFilter:function(a,b,c){return-1!==
-
 
10
a.value.toLowerCase().indexOf(c)},paramName:"query",transformResult:function(a){return"string"===typeof a?e.parseJSON(a):a}};this.element=a;this.el=e(a);this.suggestions=[];this.badQueries=[];this.selectedIndex=-1;this.currentValue=this.element.value;this.intervalId=0;this.cachedResponse=[];this.onChange=this.onChangeInterval=null;this.isLocal=this.ignoreValueChange=!1;this.suggestionsContainer=null;this.options=e.extend({},c,b);this.classes={selected:"autocomplete-selected",suggestion:"autocomplete-suggestion"};
-
 
11
this.initialize();this.setOptions(b)}var h={extend:function(a,b){return e.extend(a,b)},createNode:function(a){var b=document.createElement("div");b.innerHTML=a;return b.firstChild}};g.utils=h;e.Autocomplete=g;g.formatResult=function(a,b){var c="("+b.replace(RegExp("(\\/|\\.|\\*|\\+|\\?|\\||\\(|\\)|\\[|\\]|\\{|\\}|\\\\)","g"),"\\$1")+")";return a.value.replace(RegExp(c,"gi"),"<strong>$1</strong>")};g.prototype={killerFn:null,initialize:function(){var a=this,b="."+a.classes.suggestion,c=a.classes.selected,
-
 
12
d=a.options,f;a.element.setAttribute("autocomplete","off");a.killerFn=function(b){0===e(b.target).closest("."+a.options.containerClass).length&&(a.killSuggestions(),a.disableKillerFn())};if(!d.width||"auto"===d.width)d.width=a.el.outerWidth();a.suggestionsContainer=g.utils.createNode('<div class="'+d.containerClass+'" style="position: absolute; display: none;"></div>');f=e(a.suggestionsContainer);f.appendTo(d.appendTo).width(d.width);f.on("mouseover.autocomplete",b,function(){a.activate(e(this).data("index"))});
-
 
13
f.on("mouseout.autocomplete",function(){a.selectedIndex=-1;f.children("."+c).removeClass(c)});f.on("click.autocomplete",b,function(){a.select(e(this).data("index"),!1)});a.fixPosition();if(window.opera)a.el.on("keypress.autocomplete",function(b){a.onKeyPress(b)});else a.el.on("keydown.autocomplete",function(b){a.onKeyPress(b)});a.el.on("keyup.autocomplete",function(b){a.onKeyUp(b)});a.el.on("blur.autocomplete",function(){a.onBlur()});a.el.on("focus.autocomplete",function(){a.fixPosition()})},onBlur:function(){this.enableKillerFn()},
-
 
14
setOptions:function(a){var b=this.options;h.extend(b,a);if(this.isLocal=e.isArray(b.lookup))b.lookup=this.verifySuggestionsFormat(b.lookup);e(this.suggestionsContainer).css({"max-height":b.maxHeight+"px",width:b.width+"px","z-index":b.zIndex})},clearCache:function(){this.cachedResponse=[];this.badQueries=[]},clear:function(){this.clearCache();this.currentValue=null;this.suggestions=[]},disable:function(){this.disabled=!0},enable:function(){this.disabled=!1},fixPosition:function(){var a;"body"===this.options.appendTo&&
-
 
15
(a=this.el.offset(),e(this.suggestionsContainer).css({top:a.top+this.el.outerHeight()+"px",left:a.left+"px"}))},enableKillerFn:function(){e(document).on("click.autocomplete",this.killerFn)},disableKillerFn:function(){e(document).off("click.autocomplete",this.killerFn)},killSuggestions:function(){var a=this;a.stopKillSuggestions();a.intervalId=window.setInterval(function(){a.hide();a.stopKillSuggestions()},300)},stopKillSuggestions:function(){window.clearInterval(this.intervalId)},onKeyPress:function(a){if(!this.disabled&&
-
 
16
!this.visible&&40===a.keyCode&&this.currentValue)this.suggest();else if(!this.disabled&&this.visible){switch(a.keyCode){case 27:this.el.val(this.currentValue);this.hide();break;case 9:case 13:if(-1===this.selectedIndex){this.hide();return}this.select(this.selectedIndex,13===a.keyCode);if(9===a.keyCode&&!1===this.options.tabDisabled)return;break;case 38:this.moveUp();break;case 40:this.moveDown();break;default:return}a.stopImmediatePropagation();a.preventDefault()}},onKeyUp:function(a){var b=this;
-
 
17
if(!b.disabled){switch(a.keyCode){case 38:case 40:return}clearInterval(b.onChangeInterval);if(b.currentValue!==b.el.val())if(0<b.options.deferRequestBy)b.onChangeInterval=setInterval(function(){b.onValueChange()},b.options.deferRequestBy);else b.onValueChange()}},onValueChange:function(){var a;clearInterval(this.onChangeInterval);this.currentValue=this.element.value;a=this.getQuery(this.currentValue);this.selectedIndex=-1;this.ignoreValueChange?this.ignoreValueChange=!1:a.length<this.options.minChars?
-
 
18
this.hide():this.getSuggestions(a)},getQuery:function(a){var b=this.options.delimiter;if(!b)return e.trim(a);a=a.split(b);return e.trim(a[a.length-1])},getSuggestionsLocal:function(a){var b=a.toLowerCase(),c=this.options.lookupFilter;return{suggestions:e.grep(this.options.lookup,function(d){return c(d,a,b)})}},getSuggestions:function(a){var b,c=this,d=c.options,f=d.serviceUrl;(b=c.isLocal?c.getSuggestionsLocal(a):c.cachedResponse[a])&&e.isArray(b.suggestions)?(c.suggestions=b.suggestions,c.suggest()):
-
 
19
c.isBadQuery(a)||(d.params[d.paramName]=a,!1!==d.onSearchStart.call(c.element,d.params)&&(e.isFunction(d.serviceUrl)&&(f=d.serviceUrl.call(c.element,a)),e.ajax({url:f,data:d.ignoreParams?null:d.params,type:d.type,dataType:d.dataType}).done(function(b){c.processResponse(b,a);d.onSearchComplete.call(c.element,a)})))},isBadQuery:function(a){for(var b=this.badQueries,c=b.length;c--;)if(0===a.indexOf(b[c]))return!0;return!1},hide:function(){this.visible=!1;this.selectedIndex=-1;e(this.suggestionsContainer).hide()},
-
 
20
suggest:function(){if(0===this.suggestions.length)this.hide();else{var a=this.options.formatResult,b=this.getQuery(this.currentValue),c=this.classes.suggestion,d=this.classes.selected,f=e(this.suggestionsContainer),g="";e.each(this.suggestions,function(d,e){g+='<div class="'+c+'" data-index="'+d+'">'+a(e,b)+"</div>"});f.html(g).show();this.visible=!0;this.options.autoSelectFirst&&(this.selectedIndex=0,f.children().first().addClass(d))}},verifySuggestionsFormat:function(a){return a.length&&"string"===
-
 
21
typeof a[0]?e.map(a,function(a){return{value:a,data:null}}):a},processResponse:function(a,b){var c=this.options,d=c.transformResult(a,b);d.suggestions=this.verifySuggestionsFormat(d.suggestions);c.noCache||(this.cachedResponse[d[c.paramName]]=d,0===d.suggestions.length&&this.badQueries.push(d[c.paramName]));b===this.getQuery(this.currentValue)&&(this.suggestions=d.suggestions,this.suggest())},activate:function(a){var b=this.classes.selected,c=e(this.suggestionsContainer),d=c.children();c.children("."+
-
 
22
b).removeClass(b);this.selectedIndex=a;return-1!==this.selectedIndex&&d.length>this.selectedIndex?(a=d.get(this.selectedIndex),e(a).addClass(b),a):null},select:function(a,b){var c=this.suggestions[a];c&&(this.el.val(c),this.ignoreValueChange=b,this.hide(),this.onSelect(a))},moveUp:function(){-1!==this.selectedIndex&&(0===this.selectedIndex?(e(this.suggestionsContainer).children().first().removeClass(this.classes.selected),this.selectedIndex=-1,this.el.val(this.currentValue)):this.adjustScroll(this.selectedIndex-
-
 
23
1))},moveDown:function(){this.selectedIndex!==this.suggestions.length-1&&this.adjustScroll(this.selectedIndex+1)},adjustScroll:function(a){var b=this.activate(a),c,d;b&&(b=b.offsetTop,c=e(this.suggestionsContainer).scrollTop(),d=c+this.options.maxHeight-25,b<c?e(this.suggestionsContainer).scrollTop(b):b>d&&e(this.suggestionsContainer).scrollTop(b-this.options.maxHeight+25),this.el.val(this.getValue(this.suggestions[a].value)))},onSelect:function(a){var b=this.options.onSelect;a=this.suggestions[a];
-
 
24
this.el.val(this.getValue(a.value));e.isFunction(b)&&b.call(this.element,a)},getValue:function(a){var b=this.options.delimiter,c;if(!b)return a;c=this.currentValue;b=c.split(b);return 1===b.length?a:c.substr(0,c.length-b[b.length-1].length)+a},dispose:function(){this.el.off(".autocomplete").removeData("autocomplete");this.disableKillerFn();e(this.suggestionsContainer).remove()}};e.fn.autocomplete=function(a,b){return 0===arguments.length?this.first().data("autocomplete"):this.each(function(){var c=
-
 
25
e(this),d=c.data("autocomplete");if("string"===typeof a){if(d&&"function"===typeof d[a])d[a](b)}else d&&d.dispose&&d.dispose(),d=new g(this,a),c.data("autocomplete",d)})}});
-
 
26
735
27