Mercurial > hip
diff hip.js @ 1:a31bdc4de955
Added autocomplete popup and querysource class
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 09 May 2008 16:48:45 -0700 |
parents | 9e6054e41bdc |
children | 4ea09b7ce820 |
line wrap: on
line diff
--- a/hip.js Fri May 09 13:53:40 2008 -0700 +++ b/hip.js Fri May 09 16:48:45 2008 -0700 @@ -1,3 +1,46 @@ +Array.prototype.tagify = function(tagName) { + var result = ""; + + for (var i = 0; i < this.length; i++) { + result += ("<" + tagName + ">" + this[i] + + "</" + tagName + ">" ); + } + return result; +} + +function QuerySource() { + var self = this; + + var methods = { + getSuggestions : function(query, callback) { + callback([query + " suggestion 1", + query + " suggestion 2"]); + } + }; + + for (name in methods) { + this[name] = methods[name]; + } +} + +var gQs = new QuerySource(); + +function searchBoxQuery( event ) { + gQs.getSuggestions( + event.target.value, + function(suggestions) { + var ac = $("#autocomplete-popup"); + ac.html( suggestions.tagify("div") ); + ac.show(); + } + ); +} + $(document).ready( function() { $("#search-box").focus(); + $("#search-box").keyup( searchBoxQuery ); + $("#autocomplete-popup").css( + "width", + $("#search-box").css("width") + ); });