Skip to content

Commit 101a09d

Browse files
committed
Autocomplete: Optimize element type checks for speed and size.
1 parent df077ab commit 101a09d

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

ui/jquery.ui.autocomplete.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,21 @@ $.widget( "ui.autocomplete", {
5454
// so we use the suppressKeyPressRepeat flag to avoid handling keypress
5555
// events when we know the keydown event was used to modify the
5656
// search term. #7799
57-
var suppressKeyPress, suppressKeyPressRepeat, suppressInput;
58-
59-
this.isMultiLine = this._isMultiLine();
60-
this.valueMethod = this.element[ this.element.is( "input,textarea" ) ? "val" : "text" ];
57+
var suppressKeyPress, suppressKeyPressRepeat, suppressInput,
58+
nodeName = this.element[0].nodeName.toLowerCase(),
59+
isTextarea = nodeName === "textarea",
60+
isInput = nodeName === "input";
61+
62+
this.isMultiLine =
63+
// Textareas are always multi-line
64+
isTextarea ? true :
65+
// Inputs are always single-line, even if inside a contentEditable element
66+
// IE also treats inputs as contentEditable
67+
isInput ? false :
68+
// All other element types are determined by whether or not they're contentEditable
69+
this.element.prop( "isContentEditable" );
70+
71+
this.valueMethod = this.element[ isTextarea || isInput ? "val" : "text" ];
6172
this.isNewMenu = true;
6273

6374
this.element
@@ -341,20 +352,6 @@ $.widget( "ui.autocomplete", {
341352
return element;
342353
},
343354

344-
_isMultiLine: function() {
345-
// Textareas are always multi-line
346-
if ( this.element.is( "textarea" ) ) {
347-
return true;
348-
}
349-
// Inputs are always single-line, even if inside a contentEditable element
350-
// IE also treats inputs as contentEditable
351-
if ( this.element.is( "input" ) ) {
352-
return false;
353-
}
354-
// All other element types are determined by whether or not they're contentEditable
355-
return this.element.prop( "isContentEditable" );
356-
},
357-
358355
_initSource: function() {
359356
var array, url,
360357
that = this;

0 commit comments

Comments
 (0)