Debian Codegraph @

skins/Vector/resources/skins.vector.js/watchstar.js

raw symbols SCIP
1 /**
2 * @param {HTMLElement} watchIcon
3 * @param {boolean} isWatched
4 * @param {string} expiry
5 */
6 const updateWatchIcon = ( watchIcon, isWatched, expiry ) => {
7 watchIcon.classList.remove(
8 // Vector attaches two icon classes to the element.
9 // Remove the mw-ui-icon one rather than managing both.
10 'mw-ui-icon-star',
11 'mw-ui-icon-unStar',
12 'mw-ui-icon-wikimedia-unStar',
13 'mw-ui-icon-wikimedia-star',
14 'mw-ui-icon-wikimedia-halfStar'
15 );
16
17 if ( isWatched ) {
18 if ( mw.util.isInfinity( expiry ) ) {
19 watchIcon.classList.add( 'mw-ui-icon-wikimedia-unStar' );
20 } else {
21 watchIcon.classList.add( 'mw-ui-icon-wikimedia-halfStar' );
22 }
23 } else {
24 watchIcon.classList.add( 'mw-ui-icon-wikimedia-star' );
25 }
26 };
27
28 const init = () => {
29 mw.hook( 'wikipage.watchlistChange' ).add(
30 ( /** @type {boolean} */ isWatched, /** @type {string} */ expiry ) => {
31 const watchIcons = document.querySelectorAll( '.mw-watchlink .vector-icon' );
32 if ( !watchIcons ) {
33 return;
34 }
35 Array.from( watchIcons ).forEach( ( watchIcon ) => {
36 updateWatchIcon( /** @type {HTMLElement} */ ( watchIcon ), isWatched, expiry );
37 } );
38 }
39 );
40 };
41
42 module.exports = {
43 updateWatchIcon,
44 init
45 };