User:Proteins/unindent.js: Difference between revisions

Content deleted Content added
Proteins (talk | contribs)
another step
Proteins (talk | contribs)
navigate up tree to determine indent level
Line 4:
function unindent() {
var alert_string = "";
var diagnostic_string = "";
 
var indent_level = 0;
Line 19 ⟶ 20:
var num_unindented_DD_elements = 0;
 
var top_node;
var parent_node;
var top_DL_node;
 
// Colors to help sighted people after the unindenting
Line 25 ⟶ 28:
 
 
DD_elementstop_node = document.getElementById('bodyContent');
DD_elements = top_node.getElementsByTagName("DD");
 
diagnostic_string = "";
num_DD_elements = DD_elements.length;
for (DD_element_index=0; DD_element_index<num_DD_elements; DD_element_index++) {
Line 32 ⟶ 38:
indent_level = 0;
 
// Find the parentaltopmost DL element for this DD node
top_DL_node = null;
parent_node = temp_DD_element.parentNode;
if (!parent_node) { continue; }
while (parent_node.nodeName != "DL") {
parent_node = parent_node.parentNode;
if (!parent_node) { break; }
}
if (!parent_node) { continue; }
 
while ((parent_node) && (parent_node.nodeName != "DL"top_node)) {
// Check whether that DL element has any DT elements
if (!parent_node.nodeType != 1) { continue; } // examine only Element nodes
num_DT_elements = parent_node.getElementsByTagName("DT");
 
if (num_DT_elements > 0) { continue; } // if so, don't unindent to the higher level
if (!parent_node.nodeName == "DL") { continue; }
// Check whether thatthe parent DL element has any DT elements
num_DT_elements = parent_node.getElementsByTagName("DT");
if (num_DT_elements > 0) { continuebreak; } // if so, don'tstop unindent to the higher levelunindenting...
 
// ...else make this the new indent level
indent_level++;
parent_node top_DL_node = parent_node.parentNode;
} // closes check for a parental DL element
} // closes loop climbing up the document tree
 
diagnostic_string += "DD element " + DD_element_index + " is indented to level " + indent_level + ".\n";
if (indent_level > 0) { num_unindented_DD_elements++; }
 
} // closes loop over the DD elements of the document
window.alert(diagnostic_string);
 
//Acknowledgment