mediawiki-extensions-Echo/modules/alert/ext.echo.alert.js
Timo Tijhof 72c8aba10e alert: Make selectors less overly specific and clean up js
Follows-up 383a818.

* There is no need for the additional element ("a") or
  descendant ("#pt-mytalk") selector.
  It isn't overrriding anything, only hardcodes details that make
  it harder to maintain or extend this stylesheet. For example,
  there is a gadget that makes  user messages green instead of
  orange, it now was required to hardcode the "#pt-mytalk a" part
  of the selector eventhough those are subject to change.
  Separation of concerns.

* Cache/reuse the jQuery object instead of executing the same
  query to the document, again. It also avoids a potential bug
  where the second query matches different elements (e.g. after
  appending alertMessage, there could potentially be an additional
  nested anchor link; there isn't now though, as the message is
  plain text).

* Add comment about weird echoNewMsgAlertDisplayed variable.

Change-Id: I682182fe15a868969f25fa5bfe2412e2a6f3dddf
2013-10-06 23:52:47 +00:00

15 lines
561 B
JavaScript

( function ( $, mw ) {
'use strict';
// TODO: What is this extra echoNewMsgAlertDisplayed check for? This should only run once
// and that variable isn't used anywhere else in the repository.
if ( mw.config.get( 'wgUserNewMsgRevisionId' ) && !mw.config.get( 'echoNewMsgAlertDisplayed' ) ) {
var alertMessage = mw.html.escape( mw.msg( 'colon-separator' ) + mw.msg( 'echo-new-messages' ) );
$( '#pt-mytalk a' )
.append( alertMessage )
.addClass( 'mw-echo-alert' );
mw.config.set( 'echoNewMsgAlertDisplayed', true );
}
} )( jQuery, mediaWiki );