? balloon
? select.html
? misc/theme.js
? modules/user/access_control.js
? sites/all/modules
? sites/all/modules_repository
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.194
diff -u -d -F^\s*function -r1.194 form.inc
--- includes/form.inc 7 May 2007 10:15:57 -0000 1.194
+++ includes/form.inc 12 May 2007 12:09:03 -0000
@@ -1421,13 +1421,12 @@ function theme_token($element) {
function theme_textfield($element) {
$size = $element['#size'] ? ' size="'. $element['#size'] .'"' : '';
$class = array('form-text');
- $extra = '';
$output = '';
if ($element['#autocomplete_path']) {
drupal_add_js('misc/autocomplete.js');
+ drupal_add_js(array('autocomplete' => array($element['#id'] => url($element['#autocomplete_path']))), 'setting');
$class[] = 'form-autocomplete';
- $extra = '';
}
_form_set_class($element, $class);
@@ -1441,7 +1440,7 @@ function theme_textfield($element) {
$output .= ' '. $element['#field_suffix'] .'';
}
- return theme('form_element', $element, $output) . $extra;
+ return theme('form_element', $element, $output);
}
/**
Index: misc/autocomplete.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/autocomplete.js,v
retrieving revision 1.17
diff -u -d -F^\s*function -r1.17 autocomplete.js
--- misc/autocomplete.js 9 Jan 2007 07:31:04 -0000 1.17
+++ misc/autocomplete.js 12 May 2007 12:09:03 -0000
@@ -1,54 +1,63 @@
// $Id: autocomplete.js,v 1.17 2007/01/09 07:31:04 drumm Exp $
-/**
- * Attaches the autocomplete behaviour to all required fields
- */
-Drupal.autocompleteAutoAttach = function () {
- var acdb = [];
- $('input.autocomplete').each(function () {
- var uri = this.value;
- if (!acdb[uri]) {
- acdb[uri] = new Drupal.ACDB(uri);
- }
- 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]);
- });
-}
+Drupal.autocomplete = { handlers: {} };
/**
* Prevents the form from submitting if the suggestions popup is open
* and closes the suggestions popup when doing so.
*/
-Drupal.autocompleteSubmit = function () {
+Drupal.autocomplete.submit = function () {
return $('#autocomplete').each(function () {
this.owner.hidePopup();
}).size() == 0;
}
/**
+ * Attaches the autocomplete behaviour to all required fields
+ */
+Drupal.autocomplete.attach = function () {
+ if (!Drupal.settings || !Drupal.settings.autocomplete) return;
+
+ var handlers = Drupal.autocomplete.handlers;
+ for (id in Drupal.settings.autocomplete) {
+ var url = Drupal.settings.autocomplete[id];
+ if (!handlers[url]) {
+ handlers[url] = new Drupal.autocomplete.handler(url);
+ }
+
+ new Drupal.autocomplete.field($('#' + id)[0], handlers[url]);
+ }
+}
+
+/**
* An AutoComplete object
*/
-Drupal.jsAC = function (input, db) {
+Drupal.autocomplete.field = function (input, db) {
var ac = this;
this.input = input;
this.db = db;
+ $(this.input.form).submit(Drupal.autocomplete.submit);
+
$(this.input)
+ .attr('autocomplete', 'OFF')
.keydown(function (event) { return ac.onkeydown(this, event); })
.keyup(function (event) { ac.onkeyup(this, event) })
- .blur(function () { ac.hidePopup(); ac.db.cancel(); });
+ .blur(function () {
+ var selected = ac.selected;
+ ac.hidePopup();
+ ac.db.cancel();
+ if (selected) {
+ ac.select();
+ }
+ });
};
/**
* Handler for the "keydown" event
*/
-Drupal.jsAC.prototype.onkeydown = function (input, e) {
- if (!e) {
- e = window.event;
- }
+Drupal.autocomplete.field.prototype.onkeydown = function (input, e) {
switch (e.keyCode) {
case 40: // down arrow
this.selectDown();
@@ -64,10 +73,7 @@
/**
* Handler for the "keyup" event
*/
-Drupal.jsAC.prototype.onkeyup = function (input, e) {
- if (!e) {
- e = window.event;
- }
+Drupal.autocomplete.field.prototype.onkeyup = function (input, e) {
switch (e.keyCode) {
case 16: // shift
case 17: // ctrl
@@ -101,14 +107,22 @@
/**
* Puts the currently highlighted suggestion into the autocomplete field
*/
-Drupal.jsAC.prototype.select = function (node) {
- this.input.value = node.autocompleteValue;
+Drupal.autocomplete.field.prototype.select = function (node) {
+ if (node) {
+ this.input.value = node.autocompleteValue;
+ }
+
+ if (this.input.selectionStart) {
+ this.input.select();
+ this.input.focus();
+ this.input.selectionStart = this.input.value.length;
+ }
}
/**
* Highlights the next suggestion
*/
-Drupal.jsAC.prototype.selectDown = function () {
+Drupal.autocomplete.field.prototype.selectDown = function () {
if (this.selected && this.selected.nextSibling) {
this.highlight(this.selected.nextSibling);
}
@@ -123,7 +137,7 @@
/**
* Highlights the previous suggestion
*/
-Drupal.jsAC.prototype.selectUp = function () {
+Drupal.autocomplete.field.prototype.selectUp = function () {
if (this.selected && this.selected.previousSibling) {
this.highlight(this.selected.previousSibling);
}
@@ -132,7 +146,7 @@
/**
* Highlights a suggestion
*/
-Drupal.jsAC.prototype.highlight = function (node) {
+Drupal.autocomplete.field.prototype.highlight = function (node) {
if (this.selected) {
$(this.selected).removeClass('selected');
}
@@ -143,7 +157,7 @@
/**
* Unhighlights a suggestion
*/
-Drupal.jsAC.prototype.unhighlight = function (node) {
+Drupal.autocomplete.field.prototype.unhighlight = function (node) {
$(node).removeClass('selected');
this.selected = false;
}
@@ -151,10 +165,10 @@
/**
* Hides the autocomplete suggestions
*/
-Drupal.jsAC.prototype.hidePopup = function (keycode) {
+Drupal.autocomplete.field.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.autocompleteValue;
+ this.select(this.selected);
}
// Hide popup
var popup = this.popup;
@@ -168,20 +182,18 @@
/**
* Positions the suggestions popup and starts a search
*/
-Drupal.jsAC.prototype.populatePopup = function () {
+Drupal.autocomplete.field.prototype.populatePopup = function () {
// Show popup
if (this.popup) {
$(this.popup).remove();
}
this.selected = false;
- this.popup = document.createElement('div');
- this.popup.id = 'autocomplete';
- this.popup.owner = this;
- $(this.popup).css({
+ this.popup = $('
').css({
marginTop: this.input.offsetHeight +'px',
width: (this.input.offsetWidth - 4) +'px',
display: 'none'
});
+ this.popup[0].owner = this;
$(this.input).before(this.popup);
// Do search
@@ -192,39 +204,43 @@
/**
* Fills the suggestion popup with any matches received
*/
-Drupal.jsAC.prototype.found = function (matches) {
+Drupal.autocomplete.field.prototype.found = function (matches) {
// If no value in the textfield, do not show the popup.
if (!this.input.value.length) {
return false;
}
// Prepare matches
- var ul = document.createElement('ul');
- var ac = this;
- for (key in matches) {
- var li = document.createElement('li');
- $(li)
- .html('