MediaWiki:Common.js: Difference between revisions

From Auranogi
No edit summary
mNo edit summary
 
(27 intermediate revisions by the same user not shown)
Line 10: Line 10:
$(function () {
$(function () {
// document.querySelector('.CategoryTreeSection [href="/view/Category:Dungeon_Variants"').parentElement.parentElement.remove();
// document.querySelector('.CategoryTreeSection [href="/view/Category:Dungeon_Variants"').parentElement.parentElement.remove();
console.log("Checking for datatables");
function TryDataTables() {
if (!DataTable) {
setTimeout(function() {
TryDataTables();
}, 50);
return;
}
document.querySelectorAll('.datatable').forEach(function(node) {
console.log("Setting up datatable", node);
const headerClone = node.querySelector('tr').cloneNode(true);
const thead = document.createElement('thead');
thead.appendChild(headerClone);
node.prepend(thead);
node.querySelector('tbody tr').remove();
var order = [];
if (node.dataset.defaultorder) {
order = [ [ Number.parseInt(node.dataset.defaultorder, 10), 'desc'] ];
}
new DataTable(node, {
paging: false,
lengthChange: false,
order: order,
search: {
smart: true,
}
});
});
}
setTimeout(function() {
TryDataTables();
}, 120);
// Remove generated subcategories if page has a CategoryTree
// Remove generated subcategories if page has a CategoryTree
Line 16: Line 52:
console.log('Checking to remove gened subcats', cat);
console.log('Checking to remove gened subcats', cat);
if (!cat) document.querySelector('.mw-category-generated').style.display = "block";
if (!cat) {
}, 700);
const generated = document.querySelector('.mw-category-generated');
if (generated) generated.style.display = "block";
}
}, 130);


}());
}());

Latest revision as of 18:28, 6 April 2024

/* Any JavaScript here will be loaded for all users on every page load. */
function importPage(name, type) {
	return mw.loader.load( '/index.php?title=' + name + '&action=raw&ctype=' + type, type );
}

function importScript(name) { return importPage(name, 'text/javascript'); }

importScript('MediaWiki:DynamicNav.js');

$(function () {
	// document.querySelector('.CategoryTreeSection [href="/view/Category:Dungeon_Variants"').parentElement.parentElement.remove();
	
	console.log("Checking for datatables");
	
	function TryDataTables() {
		if (!DataTable) {
			setTimeout(function() {
				TryDataTables();
			}, 50);
			return;
		}
		document.querySelectorAll('.datatable').forEach(function(node) {
			console.log("Setting up datatable", node);
			const headerClone = node.querySelector('tr').cloneNode(true);
			const thead = document.createElement('thead');
			thead.appendChild(headerClone);
			node.prepend(thead);
			node.querySelector('tbody tr').remove();
			var order = [];
			if (node.dataset.defaultorder) {
				order = [ [ Number.parseInt(node.dataset.defaultorder, 10), 'desc'] ];
			}
			new DataTable(node, {
				paging: false,
				lengthChange: false,
				order: order,
				search: {
					smart: true,
				}
			});
		});
	}

	setTimeout(function() {
		TryDataTables();
	}, 120);

	
	// Remove generated subcategories if page has a CategoryTree
	setTimeout(function() {
		const cat = document.querySelector('.CategoryTreeTag');
		console.log('Checking to remove gened subcats', cat);
		
		if (!cat) {
			const generated = document.querySelector('.mw-category-generated');
			if (generated) generated.style.display = "block";
		}
	}, 130);

}());