diff options
author | Scott González <scott.gonzalez@gmail.com> | 2013-02-05 09:33:48 -0500 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2013-02-05 09:34:32 -0500 |
commit | 101a09d31f65ab62c7bc68e54aacd68028c1765b (patch) | |
tree | 5078d37aacf467cce42561b05d84992e44ffc902 | |
parent | df077abfc2a236a373d2080a9ceae97bb48c2620 (diff) | |
download | jquery-ui-101a09d31f65ab62c7bc68e54aacd68028c1765b.tar.gz jquery-ui-101a09d31f65ab62c7bc68e54aacd68028c1765b.zip |
Autocomplete: Optimize element type checks for speed and size.
-rw-r--r-- | ui/jquery.ui.autocomplete.js | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index af1acb02b..f8470a8a1 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -54,10 +54,21 @@ $.widget( "ui.autocomplete", { // so we use the suppressKeyPressRepeat flag to avoid handling keypress // events when we know the keydown event was used to modify the // search term. #7799 - var suppressKeyPress, suppressKeyPressRepeat, suppressInput; - - this.isMultiLine = this._isMultiLine(); - this.valueMethod = this.element[ this.element.is( "input,textarea" ) ? "val" : "text" ]; + var suppressKeyPress, suppressKeyPressRepeat, suppressInput, + nodeName = this.element[0].nodeName.toLowerCase(), + isTextarea = nodeName === "textarea", + isInput = nodeName === "input"; + + this.isMultiLine = + // Textareas are always multi-line + isTextarea ? true : + // Inputs are always single-line, even if inside a contentEditable element + // IE also treats inputs as contentEditable + isInput ? false : + // All other element types are determined by whether or not they're contentEditable + this.element.prop( "isContentEditable" ); + + this.valueMethod = this.element[ isTextarea || isInput ? "val" : "text" ]; this.isNewMenu = true; this.element @@ -341,20 +352,6 @@ $.widget( "ui.autocomplete", { return element; }, - _isMultiLine: function() { - // Textareas are always multi-line - if ( this.element.is( "textarea" ) ) { - return true; - } - // Inputs are always single-line, even if inside a contentEditable element - // IE also treats inputs as contentEditable - if ( this.element.is( "input" ) ) { - return false; - } - // All other element types are determined by whether or not they're contentEditable - return this.element.prop( "isContentEditable" ); - }, - _initSource: function() { var array, url, that = this; |