commit a566b0ee5db11e242fff5a433b71f214cf8054af Author: Oskar Schöldström Date: Sat Sep 1 17:00:05 2012 +0300 Issue 675446-108 diff --git a/core/misc/autocomplete.js b/core/misc/autocomplete.js index f0e3323..51de595 100644 --- a/core/misc/autocomplete.js +++ b/core/misc/autocomplete.js @@ -13,14 +13,7 @@ var autocomplete; */ function autocompleteSplitValues(value) { // We will match the value against comma-seperated, quoted terms. - var arr = value.match(/("[^"]+")|(\b\w+\b)/g); - // The toSource function, when available, will return an array of split terms. - if (typeof arr.toSource == "function") { - return arr.toSource(); - } - else { - return arr; - } + return value.match(/("[^"]+")|(\b\w+\b)/g) || []; } @@ -64,8 +57,6 @@ function sourceData(request, response) { * @param {Object} data */ function sourceCallbackHandler(data) { - autocomplete.cache[term] = data; - // Drupal returns an object, we need an array. var terms = []; for (var i in data) { @@ -73,6 +64,8 @@ function sourceData(request, response) { terms.push(data[i]); } } + autocomplete.cache[term] = terms; + // Send the new string array of terms to the jQuery UI list. response(terms); } @@ -131,20 +124,15 @@ Drupal.behaviors.autocomplete = { // Act on textfields with the "form-autocomplete" class. var $autocomplete = $(context).find('input.form-autocomplete').once('autocomplete'); if ($autocomplete.length) { - $autocomplete.each(function () { - // Use jQuery UI Autocomplete on the textfield. - $(this).autocomplete(autocomplete.options); - }); + // Use jQuery UI Autocomplete on the textfield. + $autocomplete.autocomplete(autocomplete.options); } }, detach: function (context, settings, trigger) { if (trigger === 'unload') { - var $autocomplete = $(context).find('input.form-autocomplete').removeOnce('autocomplete'); - if ($autocomplete.length) { - $autocomplete.each(function () { - $(this).autocomplete('destroy'); - }); - } + $(context).find('input.form-autocomplete') + .removeOnce('autocomplete') + .autocomplete('destroy'); } } };