2021-12-08 21:08:18 +00:00
|
|
|
var watchstar = mw.loader.require( 'mediawiki.page.watch.ajax' ).watchstar;
|
|
|
|
|
2020-09-14 20:46:26 +00:00
|
|
|
( function () {
|
2019-09-19 21:19:07 +00:00
|
|
|
|
2023-08-08 23:33:28 +00:00
|
|
|
var
|
|
|
|
WATCHED_ICON_CLASS = 'mw-ui-icon-wikimedia-unStar-progressive',
|
|
|
|
TEMP_WATCHED_ICON_CLASS = 'mw-ui-icon-wikimedia-halfStar-progressive',
|
|
|
|
UNWATCHED_ICON_CLASS = 'mw-ui-icon-wikimedia-star-base20';
|
2020-09-14 20:46:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tweaks the global watchstar handler in core to use the correct classes for Minerva.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Object} $icon
|
|
|
|
*/
|
|
|
|
function init( $icon ) {
|
2021-12-08 21:08:18 +00:00
|
|
|
var $watchlink = $icon.find( 'a' );
|
|
|
|
watchstar( $watchlink, mw.config.get( 'wgRelevantPageName' ), toggleClasses );
|
2020-09-14 20:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2021-12-08 21:08:18 +00:00
|
|
|
* @param {jQuery.Object} $link
|
|
|
|
* @param {boolean} isWatched
|
2020-09-14 20:46:26 +00:00
|
|
|
* @param {string} expiry
|
|
|
|
*/
|
2021-12-08 21:08:18 +00:00
|
|
|
function toggleClasses( $link, isWatched, expiry ) {
|
2023-08-11 17:14:11 +00:00
|
|
|
var $icon = $link.find( '.minerva-icon, .mw-ui-icon' );
|
2023-08-08 23:33:28 +00:00
|
|
|
$icon.removeClass( [ WATCHED_ICON_CLASS, UNWATCHED_ICON_CLASS, TEMP_WATCHED_ICON_CLASS ] )
|
|
|
|
.addClass( function () {
|
|
|
|
var 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
|
|
|
}
|
2023-08-08 23:33:28 +00:00
|
|
|
return classes;
|
|
|
|
} );
|
2020-09-14 20:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init: init,
|
|
|
|
test: {
|
2023-08-08 23:33:28 +00:00
|
|
|
toggleClasses,
|
|
|
|
TEMP_WATCHED_ICON_CLASS,
|
|
|
|
WATCHED_ICON_CLASS,
|
|
|
|
UNWATCHED_ICON_CLASS
|
2020-09-14 20:46:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}() );
|