| author | Anthony Ly <anthonyly.com@gmail.com> |
| Tue, 14 May 2013 18:17:07 +0200 | |
| changeset 1 | b95aebb070b5 |
| permissions | -rw-r--r-- |
|
1
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
1 |
/*! |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
2 |
* jQuery UI Autocomplete 1.10.3 |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
3 |
* http://jqueryui.com |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
4 |
* |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
5 |
* Copyright 2013 jQuery Foundation and other contributors |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
6 |
* Released under the MIT license. |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
7 |
* http://jquery.org/license |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
8 |
* |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
9 |
* http://api.jqueryui.com/autocomplete/ |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
10 |
* |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
11 |
* Depends: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
12 |
* jquery.ui.core.js |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
13 |
* jquery.ui.widget.js |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
14 |
* jquery.ui.position.js |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
15 |
* jquery.ui.menu.js |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
16 |
*/ |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
17 |
(function( $, undefined ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
18 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
19 |
// used to prevent race conditions with remote data sources |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
20 |
var requestIndex = 0; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
21 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
22 |
$.widget( "ui.autocomplete", { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
23 |
version: "1.10.3", |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
24 |
defaultElement: "<input>", |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
25 |
options: { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
26 |
appendTo: null, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
27 |
autoFocus: false, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
28 |
delay: 300, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
29 |
minLength: 1, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
30 |
position: { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
31 |
my: "left top", |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
32 |
at: "left bottom", |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
33 |
collision: "none" |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
34 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
35 |
source: null, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
36 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
37 |
// callbacks |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
38 |
change: null, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
39 |
close: null, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
40 |
focus: null, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
41 |
open: null, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
42 |
response: null, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
43 |
search: null, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
44 |
select: null |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
45 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
46 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
47 |
pending: 0, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
48 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
49 |
_create: function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
50 |
// Some browsers only repeat keydown events, not keypress events, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
51 |
// so we use the suppressKeyPress flag to determine if we've already |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
52 |
// handled the keydown event. #7269 |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
53 |
// Unfortunately the code for & in keypress is the same as the up arrow, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
54 |
// so we use the suppressKeyPressRepeat flag to avoid handling keypress |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
55 |
// events when we know the keydown event was used to modify the |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
56 |
// search term. #7799 |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
57 |
var suppressKeyPress, suppressKeyPressRepeat, suppressInput, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
58 |
nodeName = this.element[0].nodeName.toLowerCase(), |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
59 |
isTextarea = nodeName === "textarea", |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
60 |
isInput = nodeName === "input"; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
61 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
62 |
this.isMultiLine = |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
63 |
// Textareas are always multi-line |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
64 |
isTextarea ? true : |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
65 |
// Inputs are always single-line, even if inside a contentEditable element |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
66 |
// IE also treats inputs as contentEditable |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
67 |
isInput ? false : |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
68 |
// All other element types are determined by whether or not they're contentEditable |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
69 |
this.element.prop( "isContentEditable" ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
70 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
71 |
this.valueMethod = this.element[ isTextarea || isInput ? "val" : "text" ]; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
72 |
this.isNewMenu = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
73 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
74 |
this.element |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
75 |
.addClass( "ui-autocomplete-input" ) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
76 |
.attr( "autocomplete", "off" ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
77 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
78 |
this._on( this.element, { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
79 |
keydown: function( event ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
80 |
/*jshint maxcomplexity:15*/ |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
81 |
if ( this.element.prop( "readOnly" ) ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
82 |
suppressKeyPress = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
83 |
suppressInput = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
84 |
suppressKeyPressRepeat = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
85 |
return; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
86 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
87 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
88 |
suppressKeyPress = false; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
89 |
suppressInput = false; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
90 |
suppressKeyPressRepeat = false; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
91 |
var keyCode = $.ui.keyCode; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
92 |
switch( event.keyCode ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
93 |
case keyCode.PAGE_UP: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
94 |
suppressKeyPress = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
95 |
this._move( "previousPage", event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
96 |
break; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
97 |
case keyCode.PAGE_DOWN: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
98 |
suppressKeyPress = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
99 |
this._move( "nextPage", event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
100 |
break; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
101 |
case keyCode.UP: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
102 |
suppressKeyPress = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
103 |
this._keyEvent( "previous", event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
104 |
break; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
105 |
case keyCode.DOWN: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
106 |
suppressKeyPress = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
107 |
this._keyEvent( "next", event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
108 |
break; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
109 |
case keyCode.ENTER: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
110 |
case keyCode.NUMPAD_ENTER: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
111 |
// when menu is open and has focus |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
112 |
if ( this.menu.active ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
113 |
// #6055 - Opera still allows the keypress to occur |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
114 |
// which causes forms to submit |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
115 |
suppressKeyPress = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
116 |
event.preventDefault(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
117 |
this.menu.select( event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
118 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
119 |
break; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
120 |
case keyCode.TAB: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
121 |
if ( this.menu.active ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
122 |
this.menu.select( event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
123 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
124 |
break; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
125 |
case keyCode.ESCAPE: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
126 |
if ( this.menu.element.is( ":visible" ) ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
127 |
this._value( this.term ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
128 |
this.close( event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
129 |
// Different browsers have different default behavior for escape |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
130 |
// Single press can mean undo or clear |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
131 |
// Double press in IE means clear the whole form |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
132 |
event.preventDefault(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
133 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
134 |
break; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
135 |
default: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
136 |
suppressKeyPressRepeat = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
137 |
// search timeout should be triggered before the input value is changed |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
138 |
this._searchTimeout( event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
139 |
break; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
140 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
141 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
142 |
keypress: function( event ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
143 |
if ( suppressKeyPress ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
144 |
suppressKeyPress = false; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
145 |
if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
146 |
event.preventDefault(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
147 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
148 |
return; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
149 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
150 |
if ( suppressKeyPressRepeat ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
151 |
return; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
152 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
153 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
154 |
// replicate some key handlers to allow them to repeat in Firefox and Opera |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
155 |
var keyCode = $.ui.keyCode; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
156 |
switch( event.keyCode ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
157 |
case keyCode.PAGE_UP: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
158 |
this._move( "previousPage", event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
159 |
break; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
160 |
case keyCode.PAGE_DOWN: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
161 |
this._move( "nextPage", event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
162 |
break; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
163 |
case keyCode.UP: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
164 |
this._keyEvent( "previous", event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
165 |
break; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
166 |
case keyCode.DOWN: |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
167 |
this._keyEvent( "next", event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
168 |
break; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
169 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
170 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
171 |
input: function( event ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
172 |
if ( suppressInput ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
173 |
suppressInput = false; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
174 |
event.preventDefault(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
175 |
return; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
176 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
177 |
this._searchTimeout( event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
178 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
179 |
focus: function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
180 |
this.selectedItem = null; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
181 |
this.previous = this._value(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
182 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
183 |
blur: function( event ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
184 |
if ( this.cancelBlur ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
185 |
delete this.cancelBlur; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
186 |
return; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
187 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
188 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
189 |
clearTimeout( this.searching ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
190 |
this.close( event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
191 |
this._change( event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
192 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
193 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
194 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
195 |
this._initSource(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
196 |
this.menu = $( "<ul>" ) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
197 |
.addClass( "ui-autocomplete ui-front" ) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
198 |
.appendTo( this._appendTo() ) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
199 |
.menu({ |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
200 |
// disable ARIA support, the live region takes care of that |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
201 |
role: null |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
202 |
}) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
203 |
.hide() |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
204 |
.data( "ui-menu" ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
205 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
206 |
this._on( this.menu.element, { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
207 |
mousedown: function( event ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
208 |
// prevent moving focus out of the text field |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
209 |
event.preventDefault(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
210 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
211 |
// IE doesn't prevent moving focus even with event.preventDefault() |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
212 |
// so we set a flag to know when we should ignore the blur event |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
213 |
this.cancelBlur = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
214 |
this._delay(function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
215 |
delete this.cancelBlur; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
216 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
217 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
218 |
// clicking on the scrollbar causes focus to shift to the body |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
219 |
// but we can't detect a mouseup or a click immediately afterward |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
220 |
// so we have to track the next mousedown and close the menu if |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
221 |
// the user clicks somewhere outside of the autocomplete |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
222 |
var menuElement = this.menu.element[ 0 ]; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
223 |
if ( !$( event.target ).closest( ".ui-menu-item" ).length ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
224 |
this._delay(function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
225 |
var that = this; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
226 |
this.document.one( "mousedown", function( event ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
227 |
if ( event.target !== that.element[ 0 ] && |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
228 |
event.target !== menuElement && |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
229 |
!$.contains( menuElement, event.target ) ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
230 |
that.close(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
231 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
232 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
233 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
234 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
235 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
236 |
menufocus: function( event, ui ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
237 |
// support: Firefox |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
238 |
// Prevent accidental activation of menu items in Firefox (#7024 #9118) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
239 |
if ( this.isNewMenu ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
240 |
this.isNewMenu = false; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
241 |
if ( event.originalEvent && /^mouse/.test( event.originalEvent.type ) ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
242 |
this.menu.blur(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
243 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
244 |
this.document.one( "mousemove", function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
245 |
$( event.target ).trigger( event.originalEvent ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
246 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
247 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
248 |
return; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
249 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
250 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
251 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
252 |
var item = ui.item.data( "ui-autocomplete-item" ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
253 |
if ( false !== this._trigger( "focus", event, { item: item } ) ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
254 |
// use value to match what will end up in the input, if it was a key event |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
255 |
if ( event.originalEvent && /^key/.test( event.originalEvent.type ) ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
256 |
this._value( item.value ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
257 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
258 |
} else { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
259 |
// Normally the input is populated with the item's value as the |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
260 |
// menu is navigated, causing screen readers to notice a change and |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
261 |
// announce the item. Since the focus event was canceled, this doesn't |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
262 |
// happen, so we update the live region so that screen readers can |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
263 |
// still notice the change and announce it. |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
264 |
this.liveRegion.text( item.value ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
265 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
266 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
267 |
menuselect: function( event, ui ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
268 |
var item = ui.item.data( "ui-autocomplete-item" ), |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
269 |
previous = this.previous; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
270 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
271 |
// only trigger when focus was lost (click on menu) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
272 |
if ( this.element[0] !== this.document[0].activeElement ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
273 |
this.element.focus(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
274 |
this.previous = previous; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
275 |
// #6109 - IE triggers two focus events and the second |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
276 |
// is asynchronous, so we need to reset the previous |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
277 |
// term synchronously and asynchronously :-( |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
278 |
this._delay(function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
279 |
this.previous = previous; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
280 |
this.selectedItem = item; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
281 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
282 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
283 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
284 |
if ( false !== this._trigger( "select", event, { item: item } ) ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
285 |
this._value( item.value ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
286 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
287 |
// reset the term after the select event |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
288 |
// this allows custom select handling to work properly |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
289 |
this.term = this._value(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
290 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
291 |
this.close( event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
292 |
this.selectedItem = item; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
293 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
294 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
295 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
296 |
this.liveRegion = $( "<span>", { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
297 |
role: "status", |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
298 |
"aria-live": "polite" |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
299 |
}) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
300 |
.addClass( "ui-helper-hidden-accessible" ) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
301 |
.insertBefore( this.element ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
302 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
303 |
// turning off autocomplete prevents the browser from remembering the |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
304 |
// value when navigating through history, so we re-enable autocomplete |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
305 |
// if the page is unloaded before the widget is destroyed. #7790 |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
306 |
this._on( this.window, { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
307 |
beforeunload: function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
308 |
this.element.removeAttr( "autocomplete" ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
309 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
310 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
311 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
312 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
313 |
_destroy: function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
314 |
clearTimeout( this.searching ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
315 |
this.element |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
316 |
.removeClass( "ui-autocomplete-input" ) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
317 |
.removeAttr( "autocomplete" ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
318 |
this.menu.element.remove(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
319 |
this.liveRegion.remove(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
320 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
321 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
322 |
_setOption: function( key, value ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
323 |
this._super( key, value ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
324 |
if ( key === "source" ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
325 |
this._initSource(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
326 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
327 |
if ( key === "appendTo" ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
328 |
this.menu.element.appendTo( this._appendTo() ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
329 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
330 |
if ( key === "disabled" && value && this.xhr ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
331 |
this.xhr.abort(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
332 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
333 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
334 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
335 |
_appendTo: function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
336 |
var element = this.options.appendTo; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
337 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
338 |
if ( element ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
339 |
element = element.jquery || element.nodeType ? |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
340 |
$( element ) : |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
341 |
this.document.find( element ).eq( 0 ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
342 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
343 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
344 |
if ( !element ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
345 |
element = this.element.closest( ".ui-front" ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
346 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
347 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
348 |
if ( !element.length ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
349 |
element = this.document[0].body; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
350 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
351 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
352 |
return element; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
353 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
354 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
355 |
_initSource: function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
356 |
var array, url, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
357 |
that = this; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
358 |
if ( $.isArray(this.options.source) ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
359 |
array = this.options.source; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
360 |
this.source = function( request, response ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
361 |
response( $.ui.autocomplete.filter( array, request.term ) ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
362 |
}; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
363 |
} else if ( typeof this.options.source === "string" ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
364 |
url = this.options.source; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
365 |
this.source = function( request, response ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
366 |
if ( that.xhr ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
367 |
that.xhr.abort(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
368 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
369 |
that.xhr = $.ajax({ |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
370 |
url: url, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
371 |
data: request, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
372 |
dataType: "json", |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
373 |
success: function( data ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
374 |
response( data ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
375 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
376 |
error: function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
377 |
response( [] ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
378 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
379 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
380 |
}; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
381 |
} else { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
382 |
this.source = this.options.source; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
383 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
384 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
385 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
386 |
_searchTimeout: function( event ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
387 |
clearTimeout( this.searching ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
388 |
this.searching = this._delay(function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
389 |
// only search if the value has changed |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
390 |
if ( this.term !== this._value() ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
391 |
this.selectedItem = null; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
392 |
this.search( null, event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
393 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
394 |
}, this.options.delay ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
395 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
396 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
397 |
search: function( value, event ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
398 |
value = value != null ? value : this._value(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
399 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
400 |
// always save the actual value, not the one passed as an argument |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
401 |
this.term = this._value(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
402 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
403 |
if ( value.length < this.options.minLength ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
404 |
return this.close( event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
405 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
406 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
407 |
if ( this._trigger( "search", event ) === false ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
408 |
return; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
409 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
410 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
411 |
return this._search( value ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
412 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
413 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
414 |
_search: function( value ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
415 |
this.pending++; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
416 |
this.element.addClass( "ui-autocomplete-loading" ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
417 |
this.cancelSearch = false; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
418 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
419 |
this.source( { term: value }, this._response() ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
420 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
421 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
422 |
_response: function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
423 |
var that = this, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
424 |
index = ++requestIndex; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
425 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
426 |
return function( content ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
427 |
if ( index === requestIndex ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
428 |
that.__response( content ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
429 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
430 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
431 |
that.pending--; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
432 |
if ( !that.pending ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
433 |
that.element.removeClass( "ui-autocomplete-loading" ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
434 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
435 |
}; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
436 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
437 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
438 |
__response: function( content ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
439 |
if ( content ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
440 |
content = this._normalize( content ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
441 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
442 |
this._trigger( "response", null, { content: content } ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
443 |
if ( !this.options.disabled && content && content.length && !this.cancelSearch ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
444 |
this._suggest( content ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
445 |
this._trigger( "open" ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
446 |
} else { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
447 |
// use ._close() instead of .close() so we don't cancel future searches |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
448 |
this._close(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
449 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
450 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
451 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
452 |
close: function( event ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
453 |
this.cancelSearch = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
454 |
this._close( event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
455 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
456 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
457 |
_close: function( event ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
458 |
if ( this.menu.element.is( ":visible" ) ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
459 |
this.menu.element.hide(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
460 |
this.menu.blur(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
461 |
this.isNewMenu = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
462 |
this._trigger( "close", event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
463 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
464 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
465 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
466 |
_change: function( event ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
467 |
if ( this.previous !== this._value() ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
468 |
this._trigger( "change", event, { item: this.selectedItem } ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
469 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
470 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
471 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
472 |
_normalize: function( items ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
473 |
// assume all items have the right format when the first item is complete |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
474 |
if ( items.length && items[0].label && items[0].value ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
475 |
return items; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
476 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
477 |
return $.map( items, function( item ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
478 |
if ( typeof item === "string" ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
479 |
return { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
480 |
label: item, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
481 |
value: item |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
482 |
}; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
483 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
484 |
return $.extend({ |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
485 |
label: item.label || item.value, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
486 |
value: item.value || item.label |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
487 |
}, item ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
488 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
489 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
490 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
491 |
_suggest: function( items ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
492 |
var ul = this.menu.element.empty(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
493 |
this._renderMenu( ul, items ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
494 |
this.isNewMenu = true; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
495 |
this.menu.refresh(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
496 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
497 |
// size and position menu |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
498 |
ul.show(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
499 |
this._resizeMenu(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
500 |
ul.position( $.extend({ |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
501 |
of: this.element |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
502 |
}, this.options.position )); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
503 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
504 |
if ( this.options.autoFocus ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
505 |
this.menu.next(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
506 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
507 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
508 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
509 |
_resizeMenu: function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
510 |
var ul = this.menu.element; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
511 |
ul.outerWidth( Math.max( |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
512 |
// Firefox wraps long text (possibly a rounding bug) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
513 |
// so we add 1px to avoid the wrapping (#7513) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
514 |
ul.width( "" ).outerWidth() + 1, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
515 |
this.element.outerWidth() |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
516 |
) ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
517 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
518 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
519 |
_renderMenu: function( ul, items ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
520 |
var that = this; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
521 |
$.each( items, function( index, item ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
522 |
that._renderItemData( ul, item ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
523 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
524 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
525 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
526 |
_renderItemData: function( ul, item ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
527 |
return this._renderItem( ul, item ).data( "ui-autocomplete-item", item ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
528 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
529 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
530 |
_renderItem: function( ul, item ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
531 |
return $( "<li>" ) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
532 |
.append( $( "<a>" ).text( item.label ) ) |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
533 |
.appendTo( ul ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
534 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
535 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
536 |
_move: function( direction, event ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
537 |
if ( !this.menu.element.is( ":visible" ) ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
538 |
this.search( null, event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
539 |
return; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
540 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
541 |
if ( this.menu.isFirstItem() && /^previous/.test( direction ) || |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
542 |
this.menu.isLastItem() && /^next/.test( direction ) ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
543 |
this._value( this.term ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
544 |
this.menu.blur(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
545 |
return; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
546 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
547 |
this.menu[ direction ]( event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
548 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
549 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
550 |
widget: function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
551 |
return this.menu.element; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
552 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
553 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
554 |
_value: function() { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
555 |
return this.valueMethod.apply( this.element, arguments ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
556 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
557 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
558 |
_keyEvent: function( keyEvent, event ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
559 |
if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
560 |
this._move( keyEvent, event ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
561 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
562 |
// prevents moving cursor to beginning/end of the text field in some browsers |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
563 |
event.preventDefault(); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
564 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
565 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
566 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
567 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
568 |
$.extend( $.ui.autocomplete, { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
569 |
escapeRegex: function( value ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
570 |
return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
571 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
572 |
filter: function(array, term) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
573 |
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
574 |
return $.grep( array, function(value) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
575 |
return matcher.test( value.label || value.value || value ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
576 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
577 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
578 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
579 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
580 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
581 |
// live region extension, adding a `messages` option |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
582 |
// NOTE: This is an experimental API. We are still investigating |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
583 |
// a full solution for string manipulation and internationalization. |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
584 |
$.widget( "ui.autocomplete", $.ui.autocomplete, { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
585 |
options: { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
586 |
messages: { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
587 |
noResults: "No search results.", |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
588 |
results: function( amount ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
589 |
return amount + ( amount > 1 ? " results are" : " result is" ) + |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
590 |
" available, use up and down arrow keys to navigate."; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
591 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
592 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
593 |
}, |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
594 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
595 |
__response: function( content ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
596 |
var message; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
597 |
this._superApply( arguments ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
598 |
if ( this.options.disabled || this.cancelSearch ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
599 |
return; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
600 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
601 |
if ( content && content.length ) { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
602 |
message = this.options.messages.results( content.length ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
603 |
} else { |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
604 |
message = this.options.messages.noResults; |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
605 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
606 |
this.liveRegion.text( message ); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
607 |
} |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
608 |
}); |
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
609 |
|
|
b95aebb070b5
first commit back office front metadatacomposer
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff
changeset
|
610 |
}( jQuery )); |