MediaWiki:Gadget-togglePatrollerRequests.js

/** * A toggle script for hiding "patrol-requests". * This is basically just a function for hiding/redisplaying a heading with its underlying conversation. * * Created by User:Jack McKalling */ $(document).ready(function {	var objStatusses = {		"?":   "patrol-request-status-new",		"wip":  "patrol-request-status-wip",		"done": "patrol-request-status-done"	};	/**	 * Create a handler for toggling the display of "empty" headings along with their content	 * TODO: differentiate the toggling by status rather than just "all"	 * @param booShow boolean whether to display or hide the "empty" headings	 */	function toggleEmptyHeadings(booShow) {		$("h2").nextAll("h3").each(function { var headingContent = $(this).nextUntil("h3"), funcIsRelevantHeading = function { // ignore irrelevant headers that don't contain requests at all if (!$(this).is(".patrol-request")) return false; // (merged if with for-loop to only iterate over the above user defined properties) for (var strStatusKey in objStatusses) if (objStatusses.hasOwnProperty(strStatusKey)) { // detect anything with an unknown status as not hideable if (!$(this).is("[class*='patrol-request-status-']")) return false; // detect anything else than the hideable status as not hideable if (strStatusKey != "done" && $(this).is("." + objStatusses[strStatusKey])) return false; }       		return true; // only hideable statusses at this point };       	// check if heading has content at all and meets all criteria of a hideable conversation if (headingContent.length > 0 && headingContent.is(funcIsRelevantHeading)) { if (booShow) $(this).show; else $(this).hide; }   	});	}	/**	 * Create a handler for displaying hideable patrol requests	 */    $(".patrol-request-toggle-show").on("click", function { $(".patrol-request-status-done").next("dl").show; $(".patrol-request-status-done").show; toggleEmptyHeadings(true); });   /**     * Create a handler for hiding hideable patrol requests     */    $(".patrol-request-toggle-hide").on("click", function { $(".patrol-request-status-done").next("dl").hide; $(".patrol-request-status-done").hide; toggleEmptyHeadings(false); }); });