diff options
author | Christopher Lenz <cmlenz@apache.org> | 2009-01-16 21:27:43 +0000 |
---|---|---|
committer | Christopher Lenz <cmlenz@apache.org> | 2009-01-16 21:27:43 +0000 |
commit | 3d7f5af97379a28f4ee4937b0a654c6d1f345fd6 (patch) | |
tree | bd2819a5918b7d335f62a6463f0685af4ad8576c /share/www/script/jquery.suggest.js | |
parent | 4c921ff6730e63a17c5be5b5ac01da44818833a4 (diff) |
Some cleanup of the suggest and editinline jQuery plugins.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@735146 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script/jquery.suggest.js')
-rw-r--r-- | share/www/script/jquery.suggest.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/share/www/script/jquery.suggest.js b/share/www/script/jquery.suggest.js index cc8fe549..54217390 100644 --- a/share/www/script/jquery.suggest.js +++ b/share/www/script/jquery.suggest.js @@ -65,9 +65,9 @@ var newVal = $.trim(input.val()); if (force || newVal != prevVal) { if (force || newVal.length >= options.minChars) { - options.callback($.trim(input.val()), function(items) { - show(items); - }); + options.callback.apply(elem, [$.trim(input.val()), function(items, render) { + show(items, render); + }]); } else { dropdown.hide(); } @@ -75,14 +75,22 @@ } } - function show(items) { + function show(items, render) { if (!items) return; if (!items.length) { dropdown.hide(); return; } - var html = []; + render = render || function(idx, value) { return value; } + dropdown.empty(); for (var i = 0; i < items.length; i++) { - html.push('<li>' + items[i] + '</li>'); + var item = $("<li></li>").data("value", items[i]); + var rendered = render(i, items[i]); + if (typeof(rendered) == "string") { + item.text(rendered); + } else { + item.append(rendered); + } + item.appendTo(dropdown); } - dropdown.html(html.join("")).slideDown("fast"); + dropdown.slideDown("fast"); dropdown.children('li').click(function(e) { $(this).addClass("selected"); commit(); @@ -92,7 +100,7 @@ function commit() { var sel = getSelection(); if (sel) { - prevVal = sel.text(); + prevVal = sel.data("value"); input.val(prevVal); dropdown.hide(); } |