MediaWiki:Common.js/watchlist.js
Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.
- Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5.
/** Add dismiss buttons to watchlist-message
* Allows multiple dismiss buttons on [[MediaWiki:Watchlist-details]] with bumpable cookie IDs.
* Note: HTML is backwards compatible with old version, new version ignores old syntax, except for dismissed IDs.
* @author: [[:en:User:Ruud Koot]]
* @author: [[:en:User:MZMcBride]]
* @author: [[:en:User:Merlissimo]]
* @source: [[:de:MediaWiki:Common.js/watchlist.js]] ([[de:Special:PermaLink/66626366]])
*/
/*jslint white: true, regexp: true */
/*global jQuery, mediaWiki */
( function ( mw, $ ) {
'use strict';
var cookiePrefix = mw.config.get( 'wgCookiePrefix' ) + '-hidewatchlistmessage-';
function dismissWatchlistMessage (event) {
event.preventDefault();
$( event.target ).closest( '.watchlist-message' )
.hide();
mw.cookie.get(
cookiePrefix + $( event.target ).data( 'cookieId' ),
'yes', {
expires: 21, // 3 weeks
path: '/'
}
);
}
function addDismissButton() {
mw.util.addCSS( '.watchlist-message > span { font-size: 0.6em; float:right; position: relative; padding-right: 4px; }' );
mw.util.$content
.find( '.watchlist-message' )
.each(function(){
var $link,
$button,
$this = $(this),
cookieId = parseInt(
$this.attr( 'class' )
.replace( /.*cookie\-ID\_(\d*).*/ig, '$1' ),
10
);
if ( isNaN( cookieId ) ) {
return true;
}
$link = $( '<a>' )
.text( 'esconder' )
.attr( {
href: '#',
title: 'Esconda esta mensagem'
} )
.addClass( 'dismissButton' )
.data( 'cookieId', cookieId )
.click( dismissWatchlistMessage );
$button = $( '<span>' )
.append( '[' )
.append( $link )
.append( ']' );
$this
.toggle( mw.cookie.get( cookiePrefix + cookieId ) !== 'yes' )
.prepend( $button );
});
$( '#watchlist-message' ).show();
}
$.when(
mw.loader.using( [
'mediawiki.cookie',
'mediawiki.util',
'mediawiki.page.ready'
] ),
$.ready
).then( addDismissButton );
}( mediaWiki, jQuery ) );