2002/css-validator toggle.js,1.3,1.4

Update of /sources/public/2002/css-validator
In directory hutz:/tmp/cvs-serv21655

Modified Files:
	toggle.js 
Log Message:
updated toggle script, based on David Dorward's work:
the toggle script will now build the pseudo link outside of the collapsed block, 
by looking for an element with class="toggletext" within the block, and using the
element's text to build the new element and pseudo-link.




Index: toggle.js
===================================================================
RCS file: /sources/public/2002/css-validator/toggle.js,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- toggle.js	5 Jan 2007 18:47:34 -0000	1.3
+++ toggle.js	15 Jan 2007 01:37:24 -0000	1.4
@@ -16,6 +16,7 @@
 		this.toggleClass = toggle;
 		this.toggleClosed = closed;
 		this.toggleHidden = hidden;
+		this.toggleText = "toggletext";
 		// crawl through the document, look for toggled elements
 		this.crawl(document.body);
 	},
@@ -31,29 +32,33 @@
 		 	for (i=0;i<el.childNodes.length;i++)
 		  	{
 		    	  current_child_node=el.childNodes[i];
-			  if (current_child_node.tagName)
+			  if (current_child_node.tagName && current_child_node.className && current_child_node.className.match(this.toggleText))
+			  // we only want to match an element with a class
 			  {
-			    if (current_child_node.tagName.toLowerCase() == "legend")
-			    {
-			      current_child_node.className += 'hideme';
-			    }
+			            current_child_node.className = 'hideme';
+        			    if (current_child_node.tagName.toLowerCase() == "legend")
+        			    {
+        			            var paragraph = document.createElement('p');
+        			    }
+            			    else 
+            			    {
+            		                    var paragraph = document.createElement(current_child_node.tagName.toLowerCase());
+            		            }
+            		            var link = document.createElement('a');
+            			    var text = current_child_node.childNodes[0].nodeValue;
+            			    
+            			    //text = text.replace("_", " ", "g");
+            			    //var text = "Show/Hide extra validation options";
+            			    text = document.createTextNode(text);
+            			    link.appendChild(text);
+            			    link.href="#" + el.id;
+            			    link.onclick = this.newToggleState(this,paragraph,el);
+            			    paragraph.appendChild(link);
+            			    paragraph.className += ' toggle closed';
+            			    el.parentNode.insertBefore(paragraph, el);
 			  }
 			}
 
-			// Generate a paragraph for the pseudo-link we're adding
-			var paragraph = document.createElement('p');
-			var link = document.createElement('a');
-			//var text = el.className.match(/linkText_(\S*)/)[1];
-			//text = text.replace("_", " ", "g");
-			var text = "Show/Hide extra validation options";
-			text = document.createTextNode(text);
-			link.appendChild(text);
-			link.href="#" + el.id;
-			link.onclick = this.newToggleState(this,paragraph,el);
-			paragraph.appendChild(link);
-			paragraph.className += ' toggle closed';
-			el.parentNode.insertBefore(paragraph, el);
-
 
 			// if the next sib ought to be hidden and it isn't already, hide it
 			// you can hard-code class=hidden in the HTML if you like, and avoid the Flash of Unstyled Content

Received on Monday, 15 January 2007 01:37:37 UTC