summaryrefslogtreecommitdiff
path: root/static/f
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-07-05 14:09:22 +0200
committerYorhel <git@yorhel.nl>2009-07-05 14:09:22 +0200
commitbad413455b746bbfe9c85bc4950d1736b07f0ef8 (patch)
tree6ba7f789480261807f09b8b1b430b548b25abc90 /static/f
parenta7b5f3d5318c59728dc71be2dd093033fe0d2a79 (diff)
Auto-complete the tag filters on VN search
Diffstat (limited to 'static/f')
-rw-r--r--static/f/forms.js9
-rw-r--r--static/f/script.js23
2 files changed, 27 insertions, 5 deletions
diff --git a/static/f/forms.js b/static/f/forms.js
index b9770203..96f0d753 100644
--- a/static/f/forms.js
+++ b/static/f/forms.js
@@ -18,7 +18,8 @@ function shorten(v, l) {
\***********************************/
-function dsInit(obj, url, trfunc, serfunc, retfunc) {
+function dsInit(obj, url, trfunc, serfunc, retfunc, parfunc) {
+ obj.setAttribute('autocomplete', 'off');
obj.onkeydown = dsKeyDown;
obj.onblur = function() {
// timeout to make sure the tr.onclick event is called before we've hidden the object
@@ -31,6 +32,7 @@ function dsInit(obj, url, trfunc, serfunc, retfunc) {
obj.returnFunc = retfunc;
obj.trFunc = trfunc;
obj.serFunc = serfunc;
+ obj.parFunc = parfunc;
obj.searchURL = url;
obj.selectedId = 0;
}
@@ -102,9 +104,10 @@ function dsKeyDown(ev) {
function dsSearch(obj) {
var b = x('ds_box');
+ var v = obj.parFunc ? obj.parFunc(obj.value) : obj.value;
// show/hide the ds_box div
- if(obj.value.length < 2) {
+ if(v.length < 2) {
if(b) {
b.style.top = '-500px';
b.innerHTML = '<b>Loading...</b>';
@@ -134,7 +137,7 @@ function dsSearch(obj) {
b.style.width = obj.offsetWidth+'px';
// perform search
- ajax(obj.searchURL + encodeURIComponent(obj.value), function(hr) {
+ ajax(obj.searchURL + encodeURIComponent(v), function(hr) {
dsResults(hr, obj);
});
}
diff --git a/static/f/script.js b/static/f/script.js
index e6eab3bb..23131749 100644
--- a/static/f/script.js
+++ b/static/f/script.js
@@ -446,7 +446,6 @@ DOMLoad(function() {
};
}
-
// Advanced search
cl('advselect', function() {
var e = x('advoptions');
@@ -455,7 +454,27 @@ DOMLoad(function() {
return false;
});
-
+ // auto-complete tag search
+ if(x('advselect') && x('ti')) {
+ dsInit(x('ti'), '/xml/tags.xml?q=',
+ function(item, tr) {
+ var td = document.createElement('td');
+ td.innerHTML = shorten(item.firstChild.nodeValue, 40);
+ if(item.getAttribute('meta') == 'yes')
+ td.innerHTML += ' <b class="grayedout">meta</b>';
+ else if(item.getAttribute('state') == 0)
+ td.innerHTML += ' <b class="grayedout">awaiting moderation</b>';
+ tr.appendChild(td);
+ },
+ function(item) {
+ var tags = x('ti').value.split(/ *, */);
+ tags[tags.length-1] = item.firstChild.nodeValue;
+ return tags.join(', ');
+ },
+ function() { false; },
+ function(val) { return (val.split(/, */))[val.split(/, */).length-1]; }
+ );
+ }
// show/hide NSFW VN image
if(x('nsfw_show'))