summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2006-04-06 02:41:48 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2006-04-06 02:41:48 +0000
commit482120068966928c902338630946f0ead9a17191 (patch)
tree917a4931802eb23b4dbf56b101380ebd009686ef
parentb3c245c08c121ec6915d58b3709d0fa9e3469f56 (diff)
downloadbrdo-482120068966928c902338630946f0ead9a17191.tar.gz
brdo-482120068966928c902338630946f0ead9a17191.tar.bz2
#57415: Replace drupal_implode_autocomplete() by drupal_to_js()
-rw-r--r--includes/common.inc18
-rw-r--r--misc/autocomplete.js39
-rw-r--r--modules/taxonomy.module2
-rw-r--r--modules/taxonomy/taxonomy.module2
-rw-r--r--modules/user.module2
-rw-r--r--modules/user/user.module2
6 files changed, 23 insertions, 42 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 77c64ed90..0aa3a2c6e 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -1237,24 +1237,6 @@ function drupal_to_js($var) {
}
/**
- * Implode a PHP array into a string that can be decoded by the autocomplete JS routines.
- *
- * Items are separated by double pipes. Each item consists of a key-value pair
- * separated by single pipes. Entities are used to ensure pipes in the strings
- * pass unharmed.
- *
- * The key is what is filled in in the text-box (plain-text), the value is what
- * is displayed in the suggestion list (HTML).
- */
-function drupal_implode_autocomplete($array) {
- $output = array();
- foreach ($array as $k => $v) {
- $output[] = str_replace('|', '&#124;', $k) .'|'. str_replace('|', '&#124;', $v);
- }
- return implode('||', $output);
-}
-
-/**
* Wrapper around urlencode() which avoids Apache quirks.
*
* Should be used when placing arbitrary data in an URL. Note that Drupal paths
diff --git a/misc/autocomplete.js b/misc/autocomplete.js
index 93d5bf55d..10fc1fa59 100644
--- a/misc/autocomplete.js
+++ b/misc/autocomplete.js
@@ -197,18 +197,20 @@ jsAC.prototype.found = function (matches) {
}
var ul = document.createElement('ul');
var ac = this;
- if (matches.length > 0) {
- for (var i = 0; i < matches.length; i++) {
- li = document.createElement('li');
- div = document.createElement('div');
- div.innerHTML = matches[i][1];
- li.appendChild(div);
- li.autocompleteValue = matches[i][0];
- li.onmousedown = function() { ac.select(this); };
- li.onmouseover = function() { ac.highlight(this); };
- li.onmouseout = function() { ac.unhighlight(this); };
- ul.appendChild(li);
- }
+
+ for (key in matches) {
+ var li = document.createElement('li');
+ var div = document.createElement('div');
+ div.innerHTML = matches[key];
+ li.appendChild(div);
+ li.autocompleteValue = key;
+ li.onmousedown = function() { ac.select(this); };
+ li.onmouseover = function() { ac.highlight(this); };
+ li.onmouseout = function() { ac.unhighlight(this); };
+ ul.appendChild(li);
+ }
+
+ if (ul.childNodes.length > 0) {
this.popup.appendChild(ul);
}
else {
@@ -253,15 +255,12 @@ ACDB.prototype.receive = function(string, xmlhttp, acdb) {
removeClass(acdb.owner.input, 'throbbing');
return alert('An HTTP error '+ xmlhttp.status +' occured.\n'+ acdb.uri);
}
- // Split into array of key->value pairs
- var matches = string.length > 0 ? string.split('||') : [];
- for (var i = 0; i < matches.length; i++) {
- matches[i] = matches[i].length > 0 ? matches[i].split('|') : [];
- // Decode textfield pipes back to plain-text
- matches[i][0] = eregReplace('&#124;', '|', matches[i][0]);
+ // Parse back result
+ var matches = parseJson(string);
+ if (typeof matches['status'] == 'undefined' || matches['status'] != 0) {
+ acdb.cache[acdb.searchString] = matches;
+ acdb.owner.found(matches);
}
- acdb.cache[acdb.searchString] = matches;
- acdb.owner.found(matches);
}
/**
diff --git a/modules/taxonomy.module b/modules/taxonomy.module
index b14ca95f7..c4e8c7fd1 100644
--- a/modules/taxonomy.module
+++ b/modules/taxonomy.module
@@ -1360,7 +1360,7 @@ function taxonomy_autocomplete($vid, $string = '') {
}
$matches[$prefix . $n] = check_plain($tag->name);
}
- print drupal_implode_autocomplete($matches);
+ print drupal_to_js($matches);
exit();
}
}
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index b14ca95f7..c4e8c7fd1 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -1360,7 +1360,7 @@ function taxonomy_autocomplete($vid, $string = '') {
}
$matches[$prefix . $n] = check_plain($tag->name);
}
- print drupal_implode_autocomplete($matches);
+ print drupal_to_js($matches);
exit();
}
}
diff --git a/modules/user.module b/modules/user.module
index d22ad64f6..26e087f19 100644
--- a/modules/user.module
+++ b/modules/user.module
@@ -2083,6 +2083,6 @@ function user_autocomplete($string) {
while ($user = db_fetch_object($result)) {
$matches[$user->name] = check_plain($user->name);
}
- print drupal_implode_autocomplete($matches);
+ print drupal_to_js($matches);
exit();
}
diff --git a/modules/user/user.module b/modules/user/user.module
index d22ad64f6..26e087f19 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -2083,6 +2083,6 @@ function user_autocomplete($string) {
while ($user = db_fetch_object($result)) {
$matches[$user->name] = check_plain($user->name);
}
- print drupal_implode_autocomplete($matches);
+ print drupal_to_js($matches);
exit();
}