Commit 48212006 authored by Steven Wittens's avatar Steven Wittens

#57415: Replace drupal_implode_autocomplete() by drupal_to_js()

parent b3c245c0
......@@ -1236,24 +1236,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('|', '|', $k) .'|'. str_replace('|', '|', $v);
}
return implode('||', $output);
}
/**
* Wrapper around urlencode() which avoids Apache quirks.
*
......
......@@ -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);
}
/**
......
......@@ -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();
}
}
......@@ -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();
}
}
......@@ -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();
}
......@@ -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();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment