summaryrefslogtreecommitdiff
path: root/misc/collapse.js
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-06-21 09:45:45 +0000
committerDries Buytaert <dries@buytaert.net>2005-06-21 09:45:45 +0000
commite550f8416210489aedd88a73cdc3c5b614edc574 (patch)
tree4bfe99c1e26afb24555e144a284abb67fae52df8 /misc/collapse.js
parente16e048d577236daded1ad13a3913ba202d7db0f (diff)
downloadbrdo-e550f8416210489aedd88a73cdc3c5b614edc574.tar.gz
brdo-e550f8416210489aedd88a73cdc3c5b614edc574.tar.bz2
- Patch #16204 by Thox: committed the collapsible form elements patch.
NOTE: this patch works well, but the improved node edit form still has some rough edges. It is important that we continue to improve usability. Give it a try.
Diffstat (limited to 'misc/collapse.js')
-rw-r--r--misc/collapse.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/misc/collapse.js b/misc/collapse.js
new file mode 100644
index 000000000..a689b1fd4
--- /dev/null
+++ b/misc/collapse.js
@@ -0,0 +1,48 @@
+if (isJsEnabled()) {
+ addLoadEvent(collapseAutoAttach);
+}
+
+function collapseAutoAttach() {
+ var fieldsets = document.getElementsByTagName('fieldset');
+ var legend, fieldset;
+ for (var i = 0; fieldset = fieldsets[i]; i++) {
+ if (!hasClass(fieldset, 'collapsible')) {
+ continue;
+ }
+ legend = fieldset.getElementsByTagName('legend');
+ if (legend.length == 0) {
+ continue;
+ }
+ legend = legend[0];
+ var a = document.createElement('a');
+ a.href = '#';
+ a.onclick = function() {
+ toggleClass(this.parentNode.parentNode, 'collapsed');
+ this.blur();
+ return false;
+ };
+ a.innerHTML = legend.innerHTML;
+ while (legend.hasChildNodes()) {
+ removeNode(legend.childNodes[0]);
+ }
+ legend.appendChild(a);
+ collapseEnsureErrorsVisible(fieldset);
+ }
+}
+
+function collapseEnsureErrorsVisible(fieldset) {
+ if (!hasClass(fieldset, 'collapsed')) {
+ return;
+ }
+ var inputs = [];
+ inputs = inputs.concat(fieldset.getElementsByTagName('input'));
+ inputs = inputs.concat(fieldset.getElementsByTagName('textarea'));
+ inputs = inputs.concat(fieldset.getElementsByTagName('select'));
+ for (var j = 0; j<3; j++) {
+ for (var i = 0; i < inputs[j].length; i++) {
+ if (hasClass(inputs[j][i], 'error')) {
+ return removeClass(fieldset, 'collapsed');
+ }
+ }
+ }
+}