aboutsummaryrefslogtreecommitdiff
path: root/js/bootstrap-typeahead.js
diff options
context:
space:
mode:
authorMatt Morgan <[email protected]>2012-04-26 14:09:20 -0400
committerMatt Morgan <[email protected]>2012-04-26 14:09:20 -0400
commitbf9d8fcc070fa826c342282e102fe00e1af76d10 (patch)
tree4e436dc3a31c9aa231a156a09953ae08b2a3ddc6 /js/bootstrap-typeahead.js
parentb261f9781bbf31f499cb55c49451dc0c0ad43062 (diff)
downloadbootstrap-bf9d8fcc070fa826c342282e102fe00e1af76d10.tar.xz
bootstrap-bf9d8fcc070fa826c342282e102fe00e1af76d10.zip
Alter typeahead to accept synchronous/asynchronous data source via function/callback
Diffstat (limited to 'js/bootstrap-typeahead.js')
-rw-r--r--js/bootstrap-typeahead.js16
1 files changed, 11 insertions, 5 deletions
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);