From ae5e50883c7636210a908fa49a23cf0392662147 Mon Sep 17 00:00:00 2001 From: Neil Drumm <drumm@3064.no-reply.drupal.org> Date: Sat, 20 May 2006 07:23:47 +0000 Subject: [PATCH] #63630 by Zen, Remove hardcoded statements from the acdb prototype. --- misc/autocomplete.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/misc/autocomplete.js b/misc/autocomplete.js index c00edc96daef..49e7e0210e7f 100644 --- a/misc/autocomplete.js +++ b/misc/autocomplete.js @@ -216,7 +216,19 @@ jsAC.prototype.found = function (matches) { else { this.hidePopup(); } - removeClass(this.input, 'throbbing'); +} + +jsAC.prototype.setStatus = function (status) { + switch (status) { + case 'begin': + addClass(this.input, 'throbbing'); + break; + case 'cancel': + case 'error': + case 'found': + removeClass(this.input, 'throbbing'); + break; + } } /** @@ -241,7 +253,7 @@ ACDB.prototype.search = function(searchString) { } var db = this; this.timer = setTimeout(function() { - addClass(db.owner.input, 'throbbing'); + db.owner.setStatus('begin'); db.transport = HTTPGet(db.uri +'/'+ encodeURIComponent(searchString), db.receive, db); }, this.delay); } @@ -252,7 +264,7 @@ ACDB.prototype.search = function(searchString) { ACDB.prototype.receive = function(string, xmlhttp, acdb) { // Note: Safari returns 'undefined' status if the request returns no data. if (xmlhttp.status != 200 && typeof xmlhttp.status != 'undefined') { - removeClass(acdb.owner.input, 'throbbing'); + acdb.owner.setStatus('error'); return alert('An HTTP error '+ xmlhttp.status +' occured.\n'+ acdb.uri); } // Parse back result @@ -260,6 +272,7 @@ ACDB.prototype.receive = function(string, xmlhttp, acdb) { if (typeof matches['status'] == 'undefined' || matches['status'] != 0) { acdb.cache[acdb.searchString] = matches; acdb.owner.found(matches); + acdb.owner.setStatus('found'); } } @@ -267,7 +280,7 @@ ACDB.prototype.receive = function(string, xmlhttp, acdb) { * Cancels the current autocomplete request */ ACDB.prototype.cancel = function() { - if (this.owner) removeClass(this.owner.input, 'throbbing'); + if (this.owner) this.owner.setStatus('cancel'); if (this.timer) clearTimeout(this.timer); if (this.transport) { this.transport.onreadystatechange = function() {}; -- GitLab