Debian Codegraph @

skins/MinervaNeue/resources/skins.minerva.scripts/watchstar.js

raw symbols SCIP
1 const watchstar = require( 'mediawiki.page.watch.ajax' ).watchstar;
2 const WATCHED_ICON_CLASS = 'minerva-icon--unStar';
3 const TEMP_WATCHED_ICON_CLASS = 'minerva-icon--halfStar';
4 const UNWATCHED_ICON_CLASS = 'minerva-icon--star';
5
6 /**
7 * Tweaks the global watchstar handler in core to use the correct classes for Minerva.
8 *
9 * @param {jQuery} $icon
10 * @ignore
11 */
12 function init( $icon ) {
13 const $watchlink = $icon.find( 'a' );
14 watchstar( $watchlink, mw.config.get( 'wgRelevantPageName' ), toggleClasses );
15 }
16
17 /**
18 * @param {jQuery} $link
19 * @param {boolean} isWatched
20 * @param {string} expiry
21 * @private
22 */
23 function toggleClasses( $link, isWatched, expiry ) {
24 const $icon = $link.find( '.minerva-icon' );
25 $icon.removeClass( [ WATCHED_ICON_CLASS, UNWATCHED_ICON_CLASS, TEMP_WATCHED_ICON_CLASS ] )
26 .addClass( () => {
27 let classes = UNWATCHED_ICON_CLASS;
28 if ( isWatched ) {
29 if ( expiry !== null && expiry !== undefined && expiry !== 'infinity' ) {
30 classes = TEMP_WATCHED_ICON_CLASS;
31 } else {
32 classes = WATCHED_ICON_CLASS;
33 }
34 }
35 return classes;
36 } );
37 }
38
39 module.exports = {
40 init: init,
41 test: {
42 toggleClasses,
43 TEMP_WATCHED_ICON_CLASS,
44 WATCHED_ICON_CLASS,
45 UNWATCHED_ICON_CLASS
46 }
47 };