diff --git a/docs/assets/css/bootstrap.css b/docs/assets/css/bootstrap.css
index 2fddd8f41c..cc58533a0e 100644
--- a/docs/assets/css/bootstrap.css
+++ b/docs/assets/css/bootstrap.css
@@ -1983,7 +1983,7 @@ table .span12 {
.navbar-search .search-query :-moz-placeholder {
color: #eeeeee;
}
-.navbar-search .search-query ::-webkit-input-placeholder {
+.navbar-search .search-query::-webkit-input-placeholder {
color: #eeeeee;
}
.navbar-search .search-query:hover {
diff --git a/docs/javascript.html b/docs/javascript.html
index f1ce98658b..a35b44dd37 100644
--- a/docs/javascript.html
+++ b/docs/javascript.html
@@ -1362,7 +1362,7 @@ $('.myCarousel').carousel({
Name |
type |
- default |
+ default |
description |
@@ -1382,15 +1382,21 @@ $('.myCarousel').carousel({
matcher |
function |
- case sensitive |
+ case insensitive |
The method used to determine if a query matches an item. Accepts a single argument, the item against which to test the query. Access the current query with this.query . Return a boolean true if query is a match. |
sorter |
function |
- no sort |
+ exact match, case sensitive, case insensitive |
Method used to sort autocomplete results. Accepts a single argument items and has the scope of the typeahead instance. Reference the current query with this.query . |
+
+ highlighter |
+ function |
+ highlights all default matches |
+ Method used to highlight autocomplete results. Accepts a single argument item and has the scope of the typeahead instance. Should return html. |
+
diff --git a/docs/templates/pages/javascript.mustache b/docs/templates/pages/javascript.mustache
index 46420660a7..cba75ac08e 100644
--- a/docs/templates/pages/javascript.mustache
+++ b/docs/templates/pages/javascript.mustache
@@ -1297,7 +1297,7 @@ $('.myCarousel').carousel({
{{_i}}Name{{/i}} |
{{_i}}type{{/i}} |
- {{_i}}default{{/i}} |
+ {{_i}}default{{/i}} |
{{_i}}description{{/i}} |
@@ -1317,15 +1317,21 @@ $('.myCarousel').carousel({
{{_i}}matcher{{/i}} |
{{_i}}function{{/i}} |
- case sensitive |
+ {{_i}}case insensitive{{/i}} |
{{_i}}The method used to determine if a query matches an item. Accepts a single argument, the item against which to test the query. Access the current query with this.query . Return a boolean true if query is a match.{{/i}} |
{{_i}}sorter{{/i}} |
{{_i}}function{{/i}} |
- no sort |
+ {{_i}}exact match, case sensitive, case insensitive{{/i}} |
{{_i}}Method used to sort autocomplete results. Accepts a single argument items and has the scope of the typeahead instance. Reference the current query with this.query .{{/i}} |
+
+ {{_i}}highlighter{{/i}} |
+ {{_i}}function{{/i}} |
+ {{_i}}highlights all default matches{{/i}} |
+ {{_i}}Method used to highlight autocomplete results. Accepts a single argument item and has the scope of the typeahead instance. Should return html.{{/i}} |
+
diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js
index 39331816e8..1426185afc 100644
--- a/js/bootstrap-typeahead.js
+++ b/js/bootstrap-typeahead.js
@@ -24,8 +24,9 @@
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.matcher = this.options.matcher || this.matcher
+ this.sorter = this.options.sorter || this.sorter
+ this.highlighter = this.options.highlighter || this.highlighter
this.$menu = $(this.options.menu).appendTo('body')
this.source = this.options.source
this.shown = false
@@ -87,17 +88,37 @@
return this.render(items.slice(0, this.options.items)).show()
}
+ , matcher: function (item) {
+ return ~item.toLowerCase().indexOf(this.query.toLowerCase())
+ }
+
+ , sorter: function (items) {
+ var beginswith = []
+ , caseSensitive = []
+ , caseInsensitive = []
+ , item
+
+ while (item = items.shift()) {
+ if (!item.toLowerCase().indexOf(this.query.toLowerCase())) beginswith.push(item)
+ else if (~item.indexOf(this.query)) caseSensitive.push(item)
+ else caseInsensitive.push(item)
+ }
+
+ return beginswith.concat(caseSensitive, caseInsensitive)
+ }
+
+ , highlighter: function (item) {
+ return item.replace(new RegExp('(' + this.query + ')', 'ig'), function ($1, match) {
+ return '' + match + ''
+ })
+ }
+
, render: function (items) {
var that = this
- , QUERY = new RegExp('(' + this.query + ')', 'ig')
items = $(items).map(function (i, item) {
i = $(that.options.item).attr('data-value', item)
-
- i.find('a').html(item.replace(QUERY, function ($1, match) {
- return '' + match + ''
- }))
-
+ i.find('a').html(that.highlighter(item))
return i[0]
})
@@ -230,12 +251,6 @@
, items: 8
, menu: ''
, item: ''
- , matcher: function (item) {
- return ~item.indexOf(this.query)
- }
- , sorter: function (items) {
- return items
- }
}
$.fn.typeahead.Constructor = Typeahead