Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.470 diff -u -r1.470 common.inc --- includes/common.inc 19 Aug 2005 11:10:35 -0000 1.470 +++ includes/common.inc 19 Aug 2005 12:58:37 -0000 @@ -1464,6 +1464,10 @@ * The internal name used to refer to the field. * @param $value * The stored data. + * @param $edit + * The array name to prefix to the $name. + * @param $attributes + * An array of HTML attributes for the input tag. * @return * A themed HTML string representing the hidden field. * @@ -1471,8 +1475,8 @@ * but be sure to validate the data on the receiving page as it is possible for * an attacker to change the value before it is submitted. */ -function form_hidden($name, $value, $edit = 'edit') { - return '\n"; +function form_hidden($name, $value, $edit = 'edit', $attributes = NULL) { + return '\n"; } /** @@ -1491,7 +1495,7 @@ * A themed HTML string representing the button. */ function form_button($value, $name = 'op', $type = 'submit', $attributes = NULL) { - return '\n"; + return '\n"; } /** @@ -1809,6 +1813,51 @@ } /** + * Generates a Javascript call, while importing the arguments as is. + * PHP arrays are turned into JS objects to preserve keys. This means the array + * keys must conform to JS's member naming rules. + * + * @param $function + * The name of the function to call. + * @param $arguments + * An array of arguments. + */ +function drupal_call_js($function) { + $arguments = func_get_args(); + array_shift($arguments); + $args = array(); + foreach ($arguments as $arg) { + $args[] = drupal_to_js($arg); + } + $output = ''; + return $output; +} + +/** + * Converts a PHP variable into its Javascript equivalent. + */ +function drupal_to_js($var) { + switch (gettype($var)) { + case 'boolean': + case 'integer': + case 'double': + return $var; + case 'resource': + case 'string': + return '"'. str_replace(array("\r", "\n"), array('\r', '\n'), addslashes($var)) .'"'; + case 'array': + case 'object': + $output = array(); + foreach ($var as $k => $v) { + $output[] = $k .': '. drupal_to_js($v); + } + return '{ '. implode(', ', $output) .' }'; + default: + return 'null'; + } +} + +/** * 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 cvs diff: Diffing misc Index: misc/autocomplete.js =================================================================== RCS file: /cvs/drupal/drupal/misc/autocomplete.js,v retrieving revision 1.4 diff -u -r1.4 autocomplete.js --- misc/autocomplete.js 11 Aug 2005 13:00:17 -0000 1.4 +++ misc/autocomplete.js 19 Aug 2005 12:58:37 -0000 @@ -17,10 +17,9 @@ if (!acdb[uri]) { acdb[uri] = new ACDB(uri); } - id = input.id.substr(0, input.id.length - 13); - input = document.getElementById(id); + input = $(input.id.substr(0, input.id.length - 13)); input.setAttribute('autocomplete', 'OFF'); - input.form.onsubmit = autocompleteSubmit; + addSubmitEvent(input.form, autocompleteSubmit); new jsAC(input, acdb[uri]); } } Index: misc/drupal.css =================================================================== RCS file: /cvs/drupal/drupal/misc/drupal.css,v retrieving revision 1.112 diff -u -r1.112 drupal.css --- misc/drupal.css 16 Aug 2005 18:06:18 -0000 1.112 +++ misc/drupal.css 19 Aug 2005 12:58:38 -0000 @@ -597,6 +597,28 @@ } /* +** Progressbar styles +*/ +.progress { + font-weight: bold; +} +.progress .bar { + background: #fff url('progress.gif'); + border: 1px solid #00375a; + height: 1.5em; + margin-top: 0.2em; +} +.progress .filled { + background: #0072b9; + height: 1.33em; + border-bottom: 0.67em solid #004a73; + width: 0%; +} +.progress .percentage { + float: right; +} + +/* ** Collapsing fieldsets */ html.js fieldset.collapsed { Index: misc/drupal.js =================================================================== RCS file: /cvs/drupal/drupal/misc/drupal.js,v retrieving revision 1.6 diff -u -r1.6 drupal.js --- misc/drupal.js 18 Aug 2005 05:14:06 -0000 1.6 +++ misc/drupal.js 19 Aug 2005 12:58:39 -0000 @@ -102,6 +102,42 @@ } /** + * Redirects a button's form submission to a hidden iframe and displays the result + * in a given wrapper. The iframe should contain a call to + * window.parent.iframeHandler() after submission. + */ +function redirectFormButton(uri, button, handler) { + // Insert the iframe + var div = document.createElement('div'); + div.innerHTML = ''; + button.parentNode.appendChild(div); + + // Trap the button + button.onfocus = function() { + button.onclick = function() { + // Prepare vars for use in anonymous function. + var button = this; + var action = button.form.action; + var target = button.form.target; + // Redirect form submission + this.form.action = uri; + this.form.target = 'redirect-target'; + handler.onsubmit(); + // Set iframe handler for later + window.iframeHandler = function (data) { + // Restore form submission + button.form.action = action; + button.form.target = target; + handler.oncomplete(data); + } + } + } + button.onblur = function() { + button.onclick = null; + } +} + +/** * Adds a function to the window onload event */ function addLoadEvent(func) { @@ -118,6 +154,21 @@ } /** + * Adds a function to the window onload event + */ +function addSubmitEvent(form, func) { + var oldSubmit = form.onsubmit; + if (typeof oldSubmit != 'function') { + form.onsubmit = func; + } + else { + form.onsubmit = function() { + return oldSubmit() && func(); + } + } +} + +/** * Retrieves the absolute position of an element on the screen */ function absolutePosition(el) { @@ -196,7 +247,7 @@ */ function removeNode(node) { if (typeof node == 'string') { - node = document.getElementById(node); + node = $(node); } if (node && node.parentNode) { return node.parentNode.removeChild(node); @@ -205,3 +256,10 @@ return false; } } + +/** + * Wrapper around document.getElementById(). + */ +function $(id) { + return document.getElementById(id); +} Index: misc/progress.gif =================================================================== RCS file: misc/progress.gif diff -N misc/progress.gif Binary files /dev/null and progress.gif differ Index: misc/progress.js =================================================================== RCS file: misc/progress.js diff -N misc/progress.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ misc/progress.js 19 Aug 2005 12:58:39 -0000 @@ -0,0 +1,80 @@ +/** + * A progressbar object. Initialized with the given id. Must be inserted into + * the DOM afterwards through progressBar.element. + * + * e.g. pb = new progressBar('myProgressBar'); + * some_element.appendChild(pb.element); + */ +function progressBar(id) { + var pb = this; + this.id = id; + + this.element = document.createElement('div'); + this.element.id = id; + this.element.className = 'progress'; + this.element.innerHTML = '
'+ + '