diff options
Diffstat (limited to 'js/bootstrap-typeahead.js')
-rw-r--r-- | js/bootstrap-typeahead.js | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index c2ccdea218..3c8416f8c6 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -1,5 +1,5 @@ /* ============================================================= - * bootstrap-typeahead.js v2.1.1 + * bootstrap-typeahead.js v2.2.0 * http://twitter.github.com/bootstrap/javascript.html#typeahead * ============================================================= * Copyright 2012 Twitter, Inc. @@ -174,7 +174,7 @@ .on('keypress', $.proxy(this.keypress, this)) .on('keyup', $.proxy(this.keyup, this)) - if ($.browser.chrome || $.browser.webkit || $.browser.msie) { + if (this.eventSupported('keydown')) { this.$element.on('keydown', $.proxy(this.keydown, this)) } @@ -183,6 +183,15 @@ .on('mouseenter', 'li', $.proxy(this.mouseenter, this)) } + , eventSupported: function(eventName) { + var isSupported = eventName in this.$element + if (!isSupported) { + this.$element.setAttribute(eventName, 'return;') + isSupported = typeof this.$element[eventName] === 'function' + } + return isSupported + } + , move: function (e) { if (!this.shown) return @@ -221,6 +230,9 @@ switch(e.keyCode) { case 40: // down arrow case 38: // up arrow + case 16: // shift + case 17: // ctrl + case 18: // alt break case 9: // tab @@ -288,13 +300,11 @@ /* TYPEAHEAD DATA-API * ================== */ - $(function () { - $('body').on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) { - var $this = $(this) - if ($this.data('typeahead')) return - e.preventDefault() - $this.typeahead($this.data()) - }) + $(document).on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) { + var $this = $(this) + if ($this.data('typeahead')) return + e.preventDefault() + $this.typeahead($this.data()) }) }(window.jQuery); |