/[drupal]/contributions/sandbox/thox/ajax/collapse.js
ViewVC logotype

Contents of /contributions/sandbox/thox/ajax/collapse.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Thu Mar 30 13:17:37 2006 UTC (3 years, 7 months ago) by thox
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +18 -0 lines
File MIME type: text/javascript
Update to get ajax_chat module working in 4.6.6
1 // $Id: collapse.js,v 1.3 2006/02/07 02:29:06 unconed Exp $
2
3 if (isJsEnabled()) {
4 addLoadEvent(collapseAutoAttach);
5 }
6
7 function collapseAutoAttach() {
8 var fieldsets = document.getElementsByTagName('fieldset');
9 var legend, fieldset;
10 for (var i = 0; fieldset = fieldsets[i]; i++) {
11 if (!hasClass(fieldset, 'collapsible')) {
12 continue;
13 }
14 legend = fieldset.getElementsByTagName('legend');
15 if (legend.length == 0) {
16 continue;
17 }
18 legend = legend[0];
19 var a = document.createElement('a');
20 a.href = '#';
21 a.onclick = function() {
22 toggleClass(this.parentNode.parentNode, 'collapsed');
23 if (!hasClass(this.parentNode.parentNode, 'collapsed')) {
24 collapseScrollIntoView(this.parentNode.parentNode);
25 }
26 this.blur();
27 return false;
28 };
29 a.innerHTML = legend.innerHTML;
30 while (legend.hasChildNodes()) {
31 removeNode(legend.childNodes[0]);
32 }
33 legend.appendChild(a);
34 collapseEnsureErrorsVisible(fieldset);
35 }
36 }
37
38 function collapseEnsureErrorsVisible(fieldset) {
39 if (!hasClass(fieldset, 'collapsed')) {
40 return;
41 }
42 var inputs = [];
43 inputs = inputs.concat(fieldset.getElementsByTagName('input'));
44 inputs = inputs.concat(fieldset.getElementsByTagName('textarea'));
45 inputs = inputs.concat(fieldset.getElementsByTagName('select'));
46 for (var j = 0; j<3; j++) {
47 for (var i = 0; i < inputs[j].length; i++) {
48 if (hasClass(inputs[j][i], 'error')) {
49 return removeClass(fieldset, 'collapsed');
50 }
51 }
52 }
53 }
54
55 function collapseScrollIntoView(node) {
56 var h = self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0;
57 var offset = self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
58 var pos = absolutePosition(node);
59 if (pos.y + node.scrollHeight > h + offset) {
60 if (node.scrollHeight > h) {
61 window.scrollTo(0, pos.y);
62 } else {
63 window.scrollTo(0, pos.y + node.scrollHeight - h);
64 }
65 }
66 }

  ViewVC Help
Powered by ViewVC 1.1.2