2024-03-24 20:53:43 +00:00
|
|
|
const watchstar = require( 'mediawiki.page.watch.ajax' ).watchstar;
|
2024-06-26 13:17:23 +00:00
|
|
|
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';
|
2021-12-08 21:08:18 +00:00
|
|
|
|
2024-06-26 13:17:23 +00:00
|
|
|
/**
|
|
|
|
* Tweaks the global watchstar handler in core to use the correct classes for Minerva.
|
|
|
|
*
|
|
|
|
* @param {jQuery} $icon
|
2024-06-26 13:23:40 +00:00
|
|
|
* @ignore
|
2024-06-26 13:17:23 +00:00
|
|
|
*/
|
|
|
|
function init( $icon ) {
|
|
|
|
const $watchlink = $icon.find( 'a' );
|
|
|
|
watchstar( $watchlink, mw.config.get( 'wgRelevantPageName' ), toggleClasses );
|
|
|
|
}
|
2019-09-19 21:19:07 +00:00
|
|
|
|
2024-06-26 13:17:23 +00:00
|
|
|
/**
|
|
|
|
* @param {jQuery} $link
|
|
|
|
* @param {boolean} isWatched
|
|
|
|
* @param {string} expiry
|
2024-06-26 13:23:40 +00:00
|
|
|
* @private
|
2024-06-26 13:17:23 +00:00
|
|
|
*/
|
|
|
|
function toggleClasses( $link, isWatched, expiry ) {
|
|
|
|
const $icon = $link.find( '.minerva-icon' );
|
|
|
|
$icon.removeClass( [ WATCHED_ICON_CLASS, UNWATCHED_ICON_CLASS, TEMP_WATCHED_ICON_CLASS ] )
|
|
|
|
.addClass( () => {
|
|
|
|
let classes = UNWATCHED_ICON_CLASS;
|
|
|
|
if ( isWatched ) {
|
|
|
|
if ( expiry !== null && expiry !== undefined && expiry !== 'infinity' ) {
|
|
|
|
classes = TEMP_WATCHED_ICON_CLASS;
|
|
|
|
} else {
|
|
|
|
classes = WATCHED_ICON_CLASS;
|
2020-09-09 22:00:06 +00:00
|
|
|
}
|
2024-06-26 13:17:23 +00:00
|
|
|
}
|
|
|
|
return classes;
|
|
|
|
} );
|
|
|
|
}
|
2020-09-14 20:46:26 +00:00
|
|
|
|
2024-06-26 13:17:23 +00:00
|
|
|
module.exports = {
|
|
|
|
init: init,
|
|
|
|
test: {
|
|
|
|
toggleClasses,
|
|
|
|
TEMP_WATCHED_ICON_CLASS,
|
|
|
|
WATCHED_ICON_CLASS,
|
|
|
|
UNWATCHED_ICON_CLASS
|
|
|
|
}
|
|
|
|
};
|