From bf9d8fcc070fa826c342282e102fe00e1af76d10 Mon Sep 17 00:00:00 2001 From: Matt Morgan Date: Thu, 26 Apr 2012 14:09:20 -0400 Subject: Alter typeahead to accept synchronous/asynchronous data source via function/callback --- js/bootstrap-typeahead.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'js/bootstrap-typeahead.js') diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index 95a0fcdb7..281bdd6b3 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -77,9 +77,7 @@ } , lookup: function (event) { - var that = this - , items - , q + var items this.query = this.$element.val() @@ -87,7 +85,15 @@ return this.shown ? this.hide() : this } - items = $.grep(this.source, function (item) { + items = $.isFunction(this.source) ? this.source(this.query, $.proxy(this.process, this)) : this.source + + return items ? this.process(items) : this + } + + , process: function (items) { + var that = this + + items = $.grep(items, function (item) { return that.matcher(item) }) @@ -282,4 +288,4 @@ }) }) -}(window.jQuery); \ No newline at end of file +}(window.jQuery); -- cgit v1.2.3 From 0b827965d36f87feddcee1ecb3f6e2f9c6dec9dc Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 2 Jun 2012 19:31:30 -0700 Subject: fix regression in typeahead #3313 --- js/bootstrap-typeahead.js | 62 ++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 27 deletions(-) (limited to 'js/bootstrap-typeahead.js') diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index ad44b9085..e5197a331 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -169,7 +169,7 @@ .on('keyup', $.proxy(this.keyup, this)) if ($.browser.webkit || $.browser.msie) { - this.$element.on('keydown', $.proxy(this.keypress, this)) + this.$element.on('keydown', $.proxy(this.keydown, this)) } this.$menu @@ -177,6 +177,40 @@ .on('mouseenter', 'li', $.proxy(this.mouseenter, this)) } + , move: function (e) { + if (!this.shown) return + + switch(e.keyCode) { + case 9: // tab + case 13: // enter + case 27: // escape + e.preventDefault() + break + + case 38: // up arrow + e.preventDefault() + this.prev() + break + + case 40: // down arrow + e.preventDefault() + this.next() + break + } + + e.stopPropagation() + } + + , keydown: function (e) { + this.suppressKeyPressRepeat = !~[40,38,9,13,27].indexOf(e.keyCode) + this.move(e) + } + + , keypress: function (e) { + if (this.suppressKeyPressRepeat) return + this.move(e) + } + , keyup: function (e) { switch(e.keyCode) { case 40: // down arrow @@ -202,32 +236,6 @@ e.preventDefault() } - , keypress: function (e) { - if (!this.shown) return - - switch(e.keyCode) { - case 9: // tab - case 13: // enter - case 27: // escape - e.preventDefault() - break - - case 38: // up arrow - if (e.type != 'keydown') break - e.preventDefault() - this.prev() - break - - case 40: // down arrow - if (e.type != 'keydown') break - e.preventDefault() - this.next() - break - } - - e.stopPropagation() - } - , blur: function (e) { var that = this setTimeout(function () { that.hide() }, 150) -- cgit v1.2.3 From fae6c36874b102408b53c6e5d980b247a9779dea Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 22 Jul 2012 14:50:52 -0700 Subject: adds minLength #3960 --- js/bootstrap-typeahead.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'js/bootstrap-typeahead.js') diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index 6e896bb98..65b1ddab1 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -81,7 +81,7 @@ this.query = this.$element.val() - if (!this.query) { + if (!this.query || this.query.length < this.options.minLength) { return this.shown ? this.hide() : this } @@ -279,12 +279,13 @@ , items: 8 , menu: '' , item: '
  • ' + , minLength: 1 } $.fn.typeahead.Constructor = Typeahead - /* TYPEAHEAD DATA-API + /* TYPEAHEAD DATA-API * ================== */ $(function () { -- cgit v1.2.3 From 2b2b3303e1e93d627bf57d145173a523d991803c Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Thu, 2 Aug 2012 16:58:25 -0700 Subject: fix indexof on array for ie8 --- js/bootstrap-typeahead.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-typeahead.js') diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index 65b1ddab1..a90767c3b 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -208,7 +208,7 @@ } , keydown: function (e) { - this.suppressKeyPressRepeat = !~[40,38,9,13,27].indexOf(e.keyCode) + this.suppressKeyPressRepeat = !~$.inArray(e.keyCode, [40,38,9,13,27]) this.move(e) } -- cgit v1.2.3 From e510306196b6433dc73302d24ca58313d3a31ec7 Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Sun, 19 Aug 2012 23:07:18 -0700 Subject: bump versions to 2.1.0 --- js/bootstrap-typeahead.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-typeahead.js') diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index a90767c3b..ae57221c1 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -1,5 +1,5 @@ /* ============================================================= - * bootstrap-typeahead.js v2.0.4 + * bootstrap-typeahead.js v2.1.0 * http://twitter.github.com/bootstrap/javascript.html#typeahead * ============================================================= * Copyright 2012 Twitter, Inc. -- cgit v1.2.3