aboutsummaryrefslogtreecommitdiff
path: root/js/bootstrap-typeahead.js
diff options
context:
space:
mode:
authorJacob Thornton <[email protected]>2012-06-02 21:57:18 -0700
committerJacob Thornton <[email protected]>2012-06-02 21:57:18 -0700
commit4a276b1620f84da7343635731f6b3dbfa301d381 (patch)
tree8bb846859d4e4335cd52d5b6fc7eb154c2d9a643 /js/bootstrap-typeahead.js
parent91a7274a43836484cdf27e34c45856e4b715f778 (diff)
parentaf14f6db5dddd15556b2c932e29ea1fc7a811594 (diff)
downloadbootstrap-4a276b1620f84da7343635731f6b3dbfa301d381.tar.xz
bootstrap-4a276b1620f84da7343635731f6b3dbfa301d381.zip
Merge pull request #3682 from mlmorg/2.1.0-wip
Alter typeahead to accept synchronous/asynchronous data source
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 e5197a331..6e896bb98 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)
})
@@ -290,4 +296,4 @@
})
})
-}(window.jQuery); \ No newline at end of file
+}(window.jQuery);