Permalink
Browse files

autocomplete

  • Loading branch information...
1 parent 599375d commit 0bd581d245217038e652c94b651709059ee8c48f @wycats wycats committed Dec 28, 2007
Showing with 13 additions and 11 deletions.
  1. +1 −1 jquery.ui.autocomplete.css
  2. +12 −10 jquery.ui.autocomplete.js
@@ -1,6 +1,6 @@
ul.jq-ui-autocomplete {
position: absolute;
- overflow: hidden
+ overflow: hidden;
background-color: #fff;
border: 1px solid #aaa;
margin: 0px;
@@ -13,15 +13,16 @@
$.ui = $.ui || {};
$.ui.autocomplete = {};
- $.fn.autocomplete = function(options) {
+ $.fn.autocomplete = function(opt) {
- options = $.extend({}, {
+ opt = $.extend({}, {
timeout: 1000,
- getList: function() { return options.list; },
+ getList: function() { return opt.list; },
template: function(str) { return "<li>" + str + "</li>"; },
match: function(typed) { return !!this.match(new RegExp(typed)); },
- wrapper: "<ul></ul>"
- }, options);
+ wrapper: "<ul></ul>",
+ emptyList: "None"
+ }, opt);
return this.each(function() {
@@ -31,14 +32,15 @@
if(typingTimeout) window.clearInterval(typingTimeout);
$.data(this, "typingTimeout", setTimeout(function() {
$(e.target).trigger("autocomplete");
- }, options.timeout));
+ }, opt.timeout));
})
.bind("autocomplete", function() {
var self = this;
- var container = $(options.getList())
- .filter(function() { return options.match.call(this, $(self).val()); })
- .map(function() { return options.template(this); }).get();
- console.log(container);
+ var list = $(opt.getList())
+ .filter(function() { return opt.match.call(this, $(self).val()); })
+ .map(function() { return opt.template(this); }).get().join("");
+ var container = $(list || opt.template(opt.emptyList))
+ .wrapAll(opt.wrapper).parents(":last").children();
});
});

0 comments on commit 0bd581d

Please sign in to comment.