? misc/collapse.js Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.452 diff -u -r1.452 common.inc --- includes/common.inc 31 May 2005 21:14:25 -0000 1.452 +++ includes/common.inc 1 Jun 2005 19:56:49 -0000 @@ -1110,6 +1110,33 @@ } /** + * Format a group of form items. + * + * @param $legend + * The label for the form item group. + * @param $group + * The form items within the group, as an HTML string. + * @param $collapsed + * A boolean value decided whether the group starts collapsed. + * @param $description + * Explanatory text to display after the form item group. + * @param $attributes + * An associative array of HTML attributes to add to the fieldset tag. + * @return + * A themed HTML string representing the form item group. + */ +function form_group_collapsible($legend, $group, $collapsed = FALSE, $description = NULL, $attributes = NULL) { + drupal_add_js('misc/collapse.js'); + + $attributes['class'] .= ' collapsible'; + if ($collapsed) { + $attributes['class'] .= ' collapsed'; + } + + return '' . ($legend ? ''. $legend .'' : '') . $group . ($description ? '
'. $description .'
' : '') . "\n"; +} + +/** * Format a radio button. * * @param $title @@ -1813,7 +1840,7 @@ * Encodes MIME/HTTP header values that contain non-ASCII, UTF-8 encoded * characters. * - * For example, mime_header_encode('tést.txt') returns "=?UTF-8?B?dMOpc3QudHh0?=". + * For example, mime_header_encode('tést.txt') returns "=?UTF-8?B?dMOpc3QudHh0?=". * * See http://www.rfc-editor.org/rfc/rfc2047.txt for more information. * Index: misc/drupal.css =================================================================== RCS file: /cvs/drupal/drupal/misc/drupal.css,v retrieving revision 1.107 diff -u -r1.107 drupal.css --- misc/drupal.css 31 May 2005 23:23:48 -0000 1.107 +++ misc/drupal.css 1 Jun 2005 19:56:43 -0000 @@ -586,3 +586,30 @@ input.throbbing { background-position: 100% -18px; } + +/* +** Collapsing fieldsets +*/ +html.js fieldset.collapsed { + border-bottom-width: 0; + border-left-width: 0; + border-right-width: 0; +} + +html.js fieldset.collapsed * { + display: none; +} + +html.js fieldset.collapsed legend, +html.js fieldset.collapsed legend * { + display: inline; +} + +html.js fieldset.collapsible legend a { + padding-left: 15px; + background: url('menu-expanded.png') 5px 50% no-repeat; +} + +html.js fieldset.collapsed legend a { + background-image: url('menu-collapsed.png'); +} Index: misc/drupal.js =================================================================== RCS file: /cvs/drupal/drupal/misc/drupal.js,v retrieving revision 1.2 diff -u -r1.2 drupal.js --- misc/drupal.js 1 Jun 2005 17:43:33 -0000 1.2 +++ misc/drupal.js 3 Jun 2005 17:54:58 -0000 @@ -2,7 +2,7 @@ * Only enable Javascript functionality if all required features are supported. */ function isJsEnabled() { - if (typeof document.jsEnabled == 'undefined') { + if (document.jsEnabled == undefined) { // Note: ! casts to boolean implicitly. document.jsEnabled = !( !document.getElementsByTagName || @@ -15,7 +15,7 @@ // Global Killswitch if (isJsEnabled()) { - + document.documentElement.className = 'js'; } /** --- misc/collapse.js +++ misc/collapse.js @@ -0,0 +1,47 @@ +addLoadEvent(collapse_auto_attach); + +var collapse_action = false; + +function collapse_auto_attach() { + var fieldsets = document.getElementsByTagName('fieldset'); + var i, legend, fieldset, a; + for (i=0; fieldset = fieldsets[i]; i++) { + if (!hasClass(fieldset, 'collapsible')) { + continue; + } + legend = fieldset.getElementsByTagName('legend'); + if (legend.length > 0) { + legend = legend[0]; + } + else { + continue; + } + var a = document.createElement('a'); + a.href = '#'; + a.onclick = function() { + collapse_toggle(this); + this.blur(); + return false; + }; + a.innerHTML = legend.innerHTML; + while (legend.hasChildNodes()) removeNode(legend.childNodes[0]); + legend.appendChild(a); + } +} + +function collapse_toggle(node) { + var fieldset = node.parentNode.parentNode; + var inputs = []; + inputs = inputs.concat(fieldset.getElementsByTagName('input')); + inputs = inputs.concat(fieldset.getElementsByTagName('textarea')); + inputs = inputs.concat(fieldset.getElementsByTagName('select')); + var i,j; + for (j=0; j<3; j++) { + for (i=0; i < inputs[j].length; i++) { + if (hasClass(inputs[j][i], 'error')) { + return removeClass(fieldset, 'collapsed'); + } + } + } + return toggleClass(fieldset, 'collapsed'); +}