2020-09-14 20:46:26 +00:00
|
|
|
( function () {
|
2019-09-19 21:19:07 +00:00
|
|
|
|
2020-09-14 20:46:26 +00:00
|
|
|
var WATCHED_CLASS = [ 'watched', 'mw-ui-icon-wikimedia-unStar-progressive' ],
|
|
|
|
TEMP_WATCHED_CLASS = [ 'temp-watched', 'mw-ui-icon-wikimedia-halfStar-progressive' ],
|
|
|
|
UNWATCHED_CLASS = 'mw-ui-icon-wikimedia-star-base20';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tweaks the global watchstar handler in core to use the correct classes for Minerva.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Object} $icon
|
|
|
|
*/
|
|
|
|
function init( $icon ) {
|
|
|
|
$icon.on( 'watchpage.mw', function ( _ev, action, expiry ) {
|
|
|
|
toggleClasses( $( this ).find( 'a' ), action, expiry );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {jQuery.Object} $elem
|
|
|
|
* @param {string} action
|
|
|
|
* @param {string} expiry
|
|
|
|
*/
|
|
|
|
function toggleClasses( $elem, action, expiry ) {
|
|
|
|
$elem.removeClass(
|
|
|
|
[].concat( WATCHED_CLASS, TEMP_WATCHED_CLASS, UNWATCHED_CLASS )
|
2020-09-09 22:00:06 +00:00
|
|
|
).addClass( function () {
|
|
|
|
var classes = UNWATCHED_CLASS;
|
|
|
|
if ( action === 'watch' ) {
|
2020-09-14 20:46:26 +00:00
|
|
|
if ( expiry !== null && expiry !== undefined ) {
|
|
|
|
classes = TEMP_WATCHED_CLASS;
|
2020-09-09 22:00:06 +00:00
|
|
|
} else {
|
2020-09-14 20:46:26 +00:00
|
|
|
classes = WATCHED_CLASS;
|
2020-09-09 22:00:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return classes;
|
|
|
|
} );
|
2020-09-14 20:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init: init,
|
|
|
|
test: {
|
|
|
|
toggleClasses: toggleClasses
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}() );
|