mediawiki-skins-MinervaNeue/resources/skins.minerva.scripts/watchstar.js
Fomafix effd4fe133 Use eslint rule "no-var": "error" and replace all var
Change-Id: I67acf88e1b8de55054248d7cf8ca622d5772ea6f
2024-03-29 07:40:22 +00:00

51 lines
1.3 KiB
JavaScript

const watchstar = require( 'mediawiki.page.watch.ajax' ).watchstar;
( function () {
const WATCHED_ICON_CLASS = 'minerva-icon--unStar-progressive';
const TEMP_WATCHED_ICON_CLASS = 'minerva-icon--halfStar-progressive';
const UNWATCHED_ICON_CLASS = 'minerva-icon--star-base20';
/**
* Tweaks the global watchstar handler in core to use the correct classes for Minerva.
*
* @param {jQuery} $icon
*/
function init( $icon ) {
const $watchlink = $icon.find( 'a' );
watchstar( $watchlink, mw.config.get( 'wgRelevantPageName' ), toggleClasses );
}
/**
* @param {jQuery} $link
* @param {boolean} isWatched
* @param {string} expiry
*/
function toggleClasses( $link, isWatched, expiry ) {
const $icon = $link.find( '.minerva-icon' );
$icon.removeClass( [ WATCHED_ICON_CLASS, UNWATCHED_ICON_CLASS, TEMP_WATCHED_ICON_CLASS ] )
.addClass( function () {
let classes = UNWATCHED_ICON_CLASS;
if ( isWatched ) {
if ( expiry !== null && expiry !== undefined && expiry !== 'infinity' ) {
classes = TEMP_WATCHED_ICON_CLASS;
} else {
classes = WATCHED_ICON_CLASS;
}
}
return classes;
} );
}
module.exports = {
init: init,
test: {
toggleClasses,
TEMP_WATCHED_ICON_CLASS,
WATCHED_ICON_CLASS,
UNWATCHED_ICON_CLASS
}
};
}() );