User talk:Mdmahir/langlink.js

Feedback
Hi Mahir78,

Following the section you opened at mediawiki.org and WP:VPT I've reviewed User:Mahir78/langlink.js and would like to make a few comments about it.

A) Loading jQuery plugins

I see you use a script-tag to load jquery and/or plugins from googleapis.com, please know that MediaWiki ships with many plugins all of which are either loaded by default or can be loaded on the fly, this also gives you the ability to make sure your script will not initiate/fail untill the plugin is ready loading.

For one, a -tag in JavaScript does nothing since it's HTML, not JavaScript, all it will do is cause a warning to the browser and it moves on ignoring it.

Although the plugin from jQuery you need may be loaded by default you should not assume that it is, as at anytime the extension that loads this could perhaps change its mind. If you need a plugin, let mediawiki know like this:

if jQuery ui's dialog is already loaded it will continue right away, otherwise it'll load it and when it's ready continue with the function wrapper that is your application.

B) Prototyping

It is recommended not to use any prototyping on native constructors. Instead extend the jQuery object (read how – ie. ). Also look at the Default modules' prototypes. "escape for regex", for example, is already present in the default software as $.escapeRE, no need to re-create that locally.

C) Good practice

A few side notes that may help you learn more about JavaScript and the many functions in jQuery: To create a map/array of something that you retrieve for a set of elements you can use the $.fn.map function. For example, instead of you can use. loops through the jQuery collection, just like .each. However the return value of the function in map is added to the array. Which in turn is what is returned by map itself, thus set to $redlinks
 * Mapping

If you need to do a post request, $.post works fine:
 * JSON

Otherwise getJSON may be easier:

Greetings, Krinkle (talk) 21:51, 2 March 2011 (UTC)