User:Proteins/unindent.js: Difference between revisions

Content deleted Content added
Proteins (talk | contribs)
new architecture for the code: combine first- and second-pass loops
Proteins (talk | contribs)
undo radical change for now
Line 47:
// First-pass loop colors the links and adds the level to the beginning
diagnostic_string = "";
for (DD_element_index=num_DD_elements0; DD_element_index>0<num_DD_elements; DD_element_index--++) {
temp_DD_element = DD_elements[DD_element_index-1];
 
num_sub_DL_elements = temp_DD_element.getElementsByTagName("DL").length;
if (num_sub_DL_elements) { continue; }
 
// Skip empty DD elements
Line 58 ⟶ 57:
 
//Alternative approach: skip all DD elements that have a sub DL element within
// untagged_text = temp_DD_element.innerHTML.replace(/(<dl([^>]*)>)(.*<\/dl>)/ig,""); // remove inner DL's
untagged_text = untagged_text.replace(/(<([^>]+)>)/ig,""); // remove other HTML tags
unspaced_text = untagged_text.replace(/\s/ig, ""); // remove whitespaces
byte_count = unspaced_text.length; // remove whitespaces
if (byte_count < 1) { continue; }
 
 
// Find the topmost DL element for this DD node
Line 109:
diagnostic_string += "DD element " + DD_element_index + " is indented to level " + indent_level + ".\n";
} // check for unindenting
 
if (indent_level > 0) {
if ((top_DD_node) && (top_DL_node)) {
// top_DL_node.insertBefore(temp_DD_element, top_DD_element);
 
sibling_node = top_DD_node.nextSibling;
while ((sibling_node) && (sibling_node.nodeType != 1)) {
sibling_node = sibling_node.nextSibling;
}
if (sibling_node) {
top_DL_node.insertBefore(temp_DD_element, sibling_code);
} else {
top_DL_node.appendChild(temp_DD_element);
}
} // check that both the top_DD and top_DL elements are defined
} // check for unindenting
 
} // closes loop over the DD elements of the document
// window.alert(diagnostic_string);
 
 
/*
// Second-pass loop changes the document tree structure
diagnostic_string = "";
Line 183 ⟶ 164:
} // closes loop over the DD elements of the document
// window.alert(diagnostic_string);
*/
 
// Third-pass loop to uncreate empty discursive lists