Created
November 15, 2016 14:55
-
-
Save finwo/6439801fee243496353f92d175aa7ff8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define('autocomplete', ['jquery'], function($) { | |
| return function(selector) { | |
| $(selector).each(function() { | |
| var $element = $(this), | |
| source = $element.data('autocomplete'), | |
| cache = {}; | |
| $element.attr('autocomplete', 'off'); | |
| $element.typeahead({ | |
| source : function(query, done) { | |
| if (cache[query]) { | |
| return cache[query]; | |
| } | |
| var uri = source.replace('%s', query); | |
| $.get(uri) | |
| .done(function(result) { | |
| done(cache[query] = result.shift()); | |
| }); | |
| } | |
| }); | |
| }) | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment