User:Proteins/unindent.js

This is an old revision of this page, as edited by Proteins (talk | contribs) at 11:48, 23 October 2008 (another step). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<pre>
// Unindent discusions for accessibility
 
function unindent() {
	var alert_string = "";

	var indent_level = 0;

	var DL_elements;
	var num_DL_elements = 0;

	var DT_elements;
	var num_DT_elements = 0;

	var DD_elements;
	var temp_DD_element;
	var num_DD_elements = 0;
	var DD_element_index = 0;
	var num_unindented_DD_elements = 0;

	var parent_node;

	// Colors to help sighted people after the unindenting
	var colors = ["black", "red", "blue", "green", "magenta", "cyan", "orange", "purple", "darkgreen", "brown"];


	DD_elements = document.getElementById('bodyContent').getElementsByTagName("DD");
	num_DD_elements = DD_elements.length;
	for (DD_element_index=0; DD_element_index<num_DD_elements; DD_element_index++) { 
		temp_DD_element = DD_elements[DD_element_index];

		indent_level = 0;

		// Find the parental DL element for this DD node
		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; }

		// Check whether that DL element has any DT elements
		num_DT_elements = parent_node.getElementsByTagName("DT");
		if (num_DT_elements > 0) { continue; } // if so, don't unindent to the higher level

	} // closes loop over the DD elements of the document

//Acknowledgment
	alert_string = "Unindented " + num_unindented_DD_elements + " paragraphs of " + num_DD_elements + " possible.";
	window.alert(alert_string);

} // closes unindent() function

addOnloadHook(function () {
            addPortletLink('p-cactions', 'javascript:unindent()', 'unindent', 'ca-unindent', 'Unindent discussions', '', '');
});
 
//</pre>