? .DS_Store ? autocomplete-exchangeableACDB.patch ? sites/default/files ? sites/default/private ? sites/default/settings.php Index: includes/form.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/form.inc,v retrieving revision 1.425 diff -u -p -r1.425 form.inc --- includes/form.inc 3 Jan 2010 21:01:04 -0000 1.425 +++ includes/form.inc 6 Jan 2010 06:06:53 -0000 @@ -2838,7 +2838,8 @@ function theme_textfield($variables) { if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) { drupal_add_js('misc/autocomplete.js'); $class[] = 'form-autocomplete'; - $extra = ''; + $autocomplete_uri = check_url(url($element['#autocomplete_path'], array('absolute' => TRUE))); + drupal_add_js(array('autocomplete' => array($autocomplete_uri => array('Drupal.ACDB' => array('#' . $element['#id'])))), 'setting'); } _form_set_class($element, $class); Index: misc/autocomplete.js =================================================================== RCS file: /cvs/drupal/drupal/misc/autocomplete.js,v retrieving revision 1.34 diff -u -p -r1.34 autocomplete.js --- misc/autocomplete.js 5 Sep 2009 12:03:31 -0000 1.34 +++ misc/autocomplete.js 6 Jan 2010 06:06:53 -0000 @@ -6,17 +6,19 @@ */ Drupal.behaviors.autocomplete = { attach: function (context, settings) { - var acdb = []; - $('input.autocomplete', context).once('autocomplete', function () { - var uri = this.value; - if (!acdb[uri]) { - acdb[uri] = new Drupal.ACDB(uri); + if (settings.autocomplete) { + for (uri in settings.autocomplete) { + for (type in settings.autocomplete[uri]) { + var acdb = eval('new ' + type + '(uri)'); + for (i = 0; i < settings.autocomplete[uri][type].length; i++) { + $(settings.autocomplete[uri][type][i]).attr('autocomplete', 'OFF').once('autocomplete', function () { + $(this.form).submit(Drupal.autocompleteSubmit); + new Drupal.jsAC(this, acdb); + }); + } + } } - var input = $('#' + this.id.substr(0, this.id.length - 13)) - .attr('autocomplete', 'OFF')[0]; - $(input.form).submit(Drupal.autocompleteSubmit); - new Drupal.jsAC(input, acdb[uri]); - }); + } } }; @@ -26,7 +28,7 @@ Drupal.behaviors.autocomplete = { */ Drupal.autocompleteSubmit = function () { return $('#autocomplete').each(function () { - this.owner.hidePopup(); + this.owner.db.hidePopup(); }).size() == 0; }; @@ -37,11 +39,12 @@ Drupal.jsAC = function (input, db) { var ac = this; this.input = input; this.db = db; + this.db.ac = this; $(this.input) .keydown(function (event) { return ac.onkeydown(this, event); }) .keyup(function (event) { ac.onkeyup(this, event); }) - .blur(function () { ac.hidePopup(); ac.db.cancel(); }); + .blur(function () { ac.db.hidePopup(); ac.db.cancel(); }); }; @@ -89,14 +92,14 @@ Drupal.jsAC.prototype.onkeyup = function case 9: // tab. case 13: // enter. case 27: // esc. - this.hidePopup(e.keyCode); + this.db.hidePopup(e.keyCode); return true; default: // All other keys. if (input.value.length > 0) this.populatePopup(); else - this.hidePopup(e.keyCode); + this.db.hidePopup(e.keyCode); return true; } }; @@ -152,23 +155,6 @@ Drupal.jsAC.prototype.unhighlight = func }; /** - * Hides the autocomplete suggestions. - */ -Drupal.jsAC.prototype.hidePopup = function (keycode) { - // Select item if the right key or mousebutton was pressed. - if (this.selected && ((keycode && keycode != 46 && keycode != 8 && keycode != 27) || !keycode)) { - this.input.value = $(this.selected).data('autocompleteValue'); - } - // Hide popup. - var popup = this.popup; - if (popup) { - this.popup = null; - $(popup).fadeOut('fast', function () { $(popup).remove(); }); - } - this.selected = false; -}; - -/** * Positions the suggestions popup and starts a search. */ Drupal.jsAC.prototype.populatePopup = function () { @@ -220,7 +206,7 @@ Drupal.jsAC.prototype.found = function ( } else { $(this.popup).css({ visibility: 'hidden' }); - this.hidePopup(); + this.db.hidePopup(); } } }; @@ -304,4 +290,22 @@ Drupal.ACDB.prototype.cancel = function this.searchString = ''; }; + +/** + * Hides the autocomplete suggestions. + */ +Drupal.ACDB.prototype.hidePopup = function (keycode) { + // Select item if the right key or mousebutton was pressed. + if (this.ac.selected && ((keycode && keycode != 46 && keycode != 8 && keycode != 27) || !keycode)) { + this.ac.input.value = $(this.ac.selected).data('autocompleteValue'); + } + // Hide popup. + var popup = this.ac.popup; + if (popup) { + this.ac.popup = null; + $(popup).fadeOut('fast', function () { $(popup).remove(); }); + } + this.ac.selected = false; +}; + })(jQuery);