Content deleted Content added
visual refinement of the output when the script is repeated on the same article |
m Maintenance: Replacing addPortletLink() with mw.util.addPortletLink() (mw:ResourceLoader/Migration_guide_(users)#addPortletLink) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 1:
//<pre>
// Unindent discussions for accessibility
// WARNING WARNING WARNING ----- DO NOT USE THIS SCRIPT
// OBSOLETE AND BUGGY ----- DO NOT USE THIS SCRIPT
// NOT DELETED ONLY BECAUSE I WANT TO REMEMBER SOME CODING IDEAS AND PITFALLS IN JAVASCRIPT
function unindent() {
Line 8 ⟶ 11:
var indent_level = 0;
var indent_level_string = "";
var prev_indent_level_string = "";
var prepended_string = "";
var empty_prepended_string = " ";
var DL_elements;
Line 26 ⟶ 33:
var child_node;
var parent_node;
var top_DL_node;▼
var top_DD_node;
▲ var top_DL_node;
var prev_top_DL_node;
var temp_DD_text;
Line 56 ⟶ 65:
num_unindented_DD_elements = 0;
num_higher_level_DD_elements = 0;
top_DL_node = null;
prev_top_DL_node = null;
prepended_string = "";
indent_level_string = "";
prev_indent_level_string = "";
for (DD_element_index=0; DD_element_index<num_DD_elements; DD_element_index++) {
Line 109 ⟶ 125:
parent_node = parent_node.parentNode;
} // closes loop climbing up the document tree
if (top_DL_node != prev_top_DL_node) {
prev_indent_level_string = "";
}
prev_top_DL_node = top_DL_node;
if (indent_level > 2) { num_higher_level_DD_elements++; }
Line 122 ⟶ 143:
// indent_level_string += "[ " + num_sub_DL_elements + " " + byte_count + " " + untagged_text + " ] ";
// }
if (indent_level_string == prev_indent_level_string) {
prepended_string = empty_prepended_string;
} else {
prepended_string = indent_level_string;
}
prev_indent_level_string = indent_level_string;
child_node = temp_DD_element.firstChild;
if (child_node) {
if ((child_node.nodeType != 3) || (!child_node.data.match(/^\(Indent\s\d+\)/))) {
temp_DD_element.insertBefore(document.createTextNode(
} // add "(Indent #)" to beginning if it isn't there already
} else {
indent_level_string += "No text in this DD element.\n";
temp_DD_element.appendChild(document.createTextNode(
}
temp_DD_element.normalize();
Line 211 ⟶ 239:
addOnloadHook(function () {
mw.util.addPortletLink('p-cactions', 'javascript:unindent()', 'unindent', 'ca-unindent', 'Unindent discussions', 'i', '');
});
|