From 83a7a698939b5b4cba3c04a86befc12b9005df3d Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Mon, 19 Mar 2012 15:33:28 -0700 Subject: typeahead should escape regexp special chars --- js/bootstrap-typeahead.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/bootstrap-typeahead.js') diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index dc2f88221..804e60dc4 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -109,7 +109,8 @@ } , highlighter: function (item) { - return item.replace(new RegExp('(' + this.query + ')', 'ig'), function ($1, match) { + var query = this.query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') + return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) { return '' + match + '' }) } -- cgit v1.2.3 From 663e41d74f6369812da29a1dd66b0b1fcfd22827 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Mon, 19 Mar 2012 23:13:55 -0700 Subject: prevent dropdowns from closing when clicking inside form element inside dropdown --- 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 804e60dc4..f4d26186c 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -39,8 +39,9 @@ , select: function () { var val = this.$menu.find('.active').attr('data-value') - this.$element.val(val) - this.$element.change(); + this.$element + .val(val) + .change() return this.hide() } -- cgit v1.2.3 From f02d017ffa2f63609db034410979f62fde328816 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 24 Mar 2012 18:59:04 -0700 Subject: return matcher value directly + cleanup first lines of files --- js/bootstrap-typeahead.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/bootstrap-typeahead.js') diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index f4d26186c..f366bea63 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -17,6 +17,7 @@ * limitations under the License. * ============================================================ */ + !function( $ ){ "use strict" @@ -78,7 +79,7 @@ } items = $.grep(this.source, function (item) { - if (that.matcher(item)) return item + return that.matcher(item) }) items = this.sorter(items) -- cgit v1.2.3 From 08fee005a8a879498255611c18dede3112896d3d Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 7 Apr 2012 21:26:46 -0700 Subject: https://github.com/twitter/bootstrap/issues/2954 --- js/bootstrap-typeahead.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/bootstrap-typeahead.js') diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index f366bea63..3876e6307 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -204,11 +204,13 @@ 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 -- cgit v1.2.3 From 575f18aaf49abb0289185f6409bee031947ccf69 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 14 Apr 2012 16:29:53 -0700 Subject: add jshint support + a few minor stylistic changes --- js/bootstrap-typeahead.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'js/bootstrap-typeahead.js') diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index 3876e6307..526cf320c 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -18,11 +18,15 @@ * ============================================================ */ -!function( $ ){ +!function($){ - "use strict" + "use strict"; // jshint ;_; - var Typeahead = function ( element, options ) { + + /* TYPEAHEAD PUBLIC CLASS DEFINITION + * ================================= */ + + var Typeahead = function (element, options) { this.$element = $(element) this.options = $.extend({}, $.fn.typeahead.defaults, options) this.matcher = this.options.matcher || this.matcher @@ -111,7 +115,7 @@ } , highlighter: function (item) { - var query = this.query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') + var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&') return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) { return '' + match + '' }) @@ -241,7 +245,7 @@ /* TYPEAHEAD PLUGIN DEFINITION * =========================== */ - $.fn.typeahead = function ( option ) { + $.fn.typeahead = function (option) { return this.each(function () { var $this = $(this) , data = $this.data('typeahead') @@ -273,4 +277,4 @@ }) }) -}( window.jQuery ); \ No newline at end of file +}(window.jQuery); \ No newline at end of file -- cgit v1.2.3 From 8e8b1ad03df4f1e723cb58696ebace642fce3946 Mon Sep 17 00:00:00 2001 From: Nirav Sanghani Date: Mon, 16 Apr 2012 17:05:35 -0700 Subject: Allow updater function (updates the value of the input field) to be overridden. --- js/bootstrap-typeahead.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'js/bootstrap-typeahead.js') diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index 526cf320c..4c562f753 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -32,6 +32,7 @@ this.matcher = this.options.matcher || this.matcher this.sorter = this.options.sorter || this.sorter this.highlighter = this.options.highlighter || this.highlighter + this.updater = this.options.updater || this.updater this.$menu = $(this.options.menu).appendTo('body') this.source = this.options.source this.shown = false @@ -45,11 +46,15 @@ , select: function () { var val = this.$menu.find('.active').attr('data-value') this.$element - .val(val) + .val(this.updater(val)) .change() return this.hide() } + , updater: function (item) { + return item + } + , show: function () { var pos = $.extend({}, this.$element.offset(), { height: this.$element[0].offsetHeight -- cgit v1.2.3 From 8f98c4fbf6085e613314892de5da871dce862b34 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 18 Apr 2012 13:15:13 -0700 Subject: offset -> position #3088 --- 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 4c562f753..429ea989b 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -56,7 +56,7 @@ } , show: function () { - var pos = $.extend({}, this.$element.offset(), { + var pos = $.extend({}, this.$element.position(), { height: this.$element[0].offsetHeight }) -- cgit v1.2.3 From 839ef3a030b355d0f0c35d6c9e42ecba8b072036 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 24 Apr 2012 02:19:02 -0700 Subject: 2.0.2 -> 2.0.3 --- 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 429ea989b..ada0526f9 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -1,5 +1,5 @@ /* ============================================================= - * bootstrap-typeahead.js v2.0.2 + * bootstrap-typeahead.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#typeahead * ============================================================= * Copyright 2012 Twitter, Inc. -- cgit v1.2.3