MediaWiki:Gadget-CategoryAboveBelowImage.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
/**
* @description: Move catlinks to top and leave clones at bottom.
* @author: [[User:Ianezz]] 2009 ([[Commons:Village_pump/Archive/2009Sep#CSS_placement_of_categories]]), based on [[:wikinews:Help:User_style#Moving_categories_to_top]]
* @author: [[User:Perhelion]] 2016/2017 
**/
/*global mw*/
/*jshint curly:false*/
(function () {
'use strict';
if (mw.config.get('wgNamespaceNumber') !== -1) {
	var c = document.getElementById('catlinks'),
		b = document.getElementById('bodyContent') || document.getElementById('mw-content-text'), //|| c.parentNode
		f = document.getElementById('file'),
		cc = c.cloneNode(1); // Clone with secondary priority
	// Insert clone at original position
	if (cc.hasChildNodes()) {
		cc.id = "";
		cc.firstChild.id = "";
		cc.lastChild.id = "";
		b.insertBefore(cc, c);
	}
	// Move catlinks
	if (f) f.appendChild(c);
	else b.insertBefore(c, b.childNodes[0]);
}
})();