Topic on Talk:ResourceLoader/Legacy JavaScript

Summary by Krinkle

The killEvent() function was deprecated. No direct replacement is needed because it's functionality is obsolete with jQuery's event.preventDefault. In addition, you can also simply return false; from any event handler to achieve the same effect, which is supported in all JS-enabled browsers.

Krinkle (talkcontribs)

In wikibits.js, killEvt() is used to kill window events so that, for instance, a link's onClick doesn't also trigger navigation to its href target. Is there a replacement for killEvt? I haven't yet seen how newer MediaWiki code deals with event killing without this. -Memethief 01:33, 12 November 2010 (UTC)

This post was posted by Krinkle, but signed as Memethief.

Krinkle (talkcontribs)

jQuery provides event.preventDefault() for any browsers that ignore w3 standards and returning false from a jQuery event handler will also stop the default action from happening, which presumably means killEvt() isn't needed any more to kill window events. ATM I think they haven't completely stopped using it yet. --Darklama 00:12, 4 December 2010 (UTC)

This post was posted by Krinkle, but signed as Darklama.

Krinkle (talkcontribs)

The name of the event object is different per browser and the way to stop the default action (ie. following a link) is also different per browser. However jQuery takes care of this since it maps it all to event.preventDefault. Meaning something like the following works in all browsers (IE 6.0+, FF 2+, Safari 3.0+, Opera 9.0+, Chrome)

$( 'a#mw-veryspeciallink' ).click( function(e){
  e.preventDefault();
  alert( 'Hi, we just hijacked this link.' );
});

Also, don't use return false unless there is a specific reason you want to do that. It stops other handlers from being triggered and has other downsides. Use e.preventDefault() when all you want is stopping the browser from doing it's own thing.

wikibit's killEvt() was a (fairly complete) function that takes care of a lot of variations in different browsers but does exactly what e.preventDefault() does in jQuery it is therefor redundant and not ported to the new ResourceLoader code, since jQuery is now available on all pages by default.

Also I'd like to emphasize here that wikibits and the new mw resources are not mutually exclusive. There will be a period of time in which both are available (read also the intro paragraph on ResourceLoader/JavaScript Deprecations). Krinkle 13:07, 11 December 2010 (UTC)