[[Template:catfix]] gadget improvements

Fragment of a discussion from User talk:Kephir
Jump to navigation Jump to search

I made the changes you suggested, but I'm not sure I understand how declaring dependencies works. Am I supposed to wrap the whole jQuery(document).ready(function($){ ... } in yet another function? Like this?

mw.loader.using(['mediawiki.Title'], function () { jQuery(document).ready(function($){ ... } }

I guess I just don't know enough about JS stuff to understand what I am doing. I understand the language, but not the framework.

CodeCat19:41, 7 August 2014

Exactly. Though I would do it like:

if (mw.config.get('wgNamespaceNumber') === 14) // or mw.config.get('wgNamespaceIds').category for extra readability
jQuery(document).ready(function () {
	var wrapper;
	if (!(wrapper = document.getElementById("catfix")))
		return;
	mw.loader.using(['mediawiki.Title'], function () {
		// ...
	});
});
Keφr20:17, 7 August 2014

That worked, thank you!

CodeCat20:31, 7 August 2014