Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJacob Thornton <jacobthornton@gmail.com>2012-01-28 10:27:06 +0400
committerJacob Thornton <jacobthornton@gmail.com>2012-01-28 10:27:06 +0400
commit7cbb5868259ef95aacbd16812c25ac73ea76ca2d (patch)
treeb93148cb5befef147b4cc34f084ef1b74181d4f3 /js
parente726b231ba0c0c0effb13c9458842d64bda0e58c (diff)
move the matcher and sorter into the options - encourage people to override them...
Diffstat (limited to 'js')
-rw-r--r--js/bootstrap-typeahead.js21
1 files changed, 12 insertions, 9 deletions
diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js
index b4d839c936..39331816e8 100644
--- a/js/bootstrap-typeahead.js
+++ b/js/bootstrap-typeahead.js
@@ -24,6 +24,8 @@
var Typeahead = function ( element, options ) {
this.$element = $(element)
this.options = $.extend({}, $.fn.typeahead.defaults, options)
+ this.matcher = this.options.matcher
+ this.sorter = this.options.sorter
this.$menu = $(this.options.menu).appendTo('body')
this.source = this.options.source
this.shown = false
@@ -34,11 +36,6 @@
constructor: Typeahead
- , matcher: function (item, query) {
- // ;_; http://jsperf.com/asdfdfasdfa
- return ~item.toLowerCase().indexOf(query)
- }
-
, select: function () {
var val = this.$menu.find('.active').attr('data-value')
this.$element.val(val)
@@ -77,12 +74,12 @@
return this.shown ? this.hide() : this
}
- q = this.query.toLowerCase()
-
- items = jQuery.grep(this.source, function (item) {
- if (that.matcher(item, q)) return item
+ items = $.grep(this.source, function (item) {
+ if (that.matcher(item)) return item
})
+ items = this.sorter(items)
+
if (!items.length) {
return this.shown ? this.hide() : this
}
@@ -233,6 +230,12 @@
, items: 8
, menu: '<ul class="typeahead dropdown-menu"></ul>'
, item: '<li><a href="#"></a></li>'
+ , matcher: function (item) {
+ return ~item.indexOf(this.query)
+ }
+ , sorter: function (items) {
+ return items
+ }
}
$.fn.typeahead.Constructor = Typeahead