Created
March 8, 2012 02:38
-
-
Save matthuhiggins/1998191 to your computer and use it in GitHub Desktop.
delayed query
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
| function SearchPlaces(inputSelector) { | |
| var input = $(inputSelector).hintInput(), | |
| baseUrl = input.attr('data-source'); | |
| function currentQuery() { | |
| if (input.hasClass('empty')) { | |
| return ''; | |
| } else { | |
| return input.val(); | |
| } | |
| } | |
| function runQuery(url) { | |
| $('#vote-places-wrap').addClass('loading'); | |
| $.getScript(url); | |
| } | |
| function delayAndQuery(query) { | |
| var queryIfUnchanged = function() { | |
| if (query == currentQuery()) { | |
| runQuery(baseUrl + '?q=' + currentQuery()) | |
| } | |
| }; | |
| setTimeout(queryIfUnchanged, 300); | |
| } | |
| var previousQuery = currentQuery(); | |
| setInterval(function() { | |
| var newQuery = currentQuery(); | |
| if (previousQuery != newQuery) { | |
| delayAndQuery(newQuery); | |
| previousQuery = newQuery; | |
| } | |
| }, 150); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment