Debian Codegraph @

extensions/Echo/modules/ui/mw.echo.ui.ToggleReadCircleButtonWidget.js

raw symbols SCIP
1 ( function () {
2 /**
3 * A button showing a circle that represents either 'mark as read' or 'mark as unread' states.
4 *
5 * @class
6 * @extends OO.ui.ButtonWidget
7 *
8 * @constructor
9 * @param {Object} [config] Configuration options
10 * @param {boolean} [config.markAsRead=true] Display mark as read state. If false, the button displays
11 * mark as unread state.
12 */
13 mw.echo.ui.ToggleReadCircleButtonWidget = function MwEchoUiToggleReadCircleButtonWidget( config ) {
14 config = config || {};
15
16 // Parent constructor
17 mw.echo.ui.ToggleReadCircleButtonWidget.super.call( this, Object.assign( {
18 invisibleLabel: true,
19 // Set a dummy icon so we get focus styles
20 icon: '_'
21 }, config ) );
22
23 this.$circle = $( '<div>' )
24 .addClass( 'mw-echo-ui-toggleReadCircleButtonWidget-circle' );
25 this.$button.append( this.$circle );
26
27 this.toggleState( config.markAsRead === undefined ? true : !!config.markAsRead );
28
29 this.$element
30 .addClass( 'mw-echo-ui-toggleReadCircleButtonWidget' );
31 };
32
33 /* Initialization */
34
35 OO.inheritClass( mw.echo.ui.ToggleReadCircleButtonWidget, OO.ui.ButtonWidget );
36
37 /* Methods */
38
39 /**
40 * Toggle the state of the button from 'mark as read' to 'mark as unread'
41 * and vice versa.
42 *
43 * @param {boolean} [isMarkAsRead] The state is mark as read
44 */
45 mw.echo.ui.ToggleReadCircleButtonWidget.prototype.toggleState = function ( isMarkAsRead ) {
46 isMarkAsRead = isMarkAsRead === undefined ? !this.markAsRead : !!isMarkAsRead;
47
48 this.markAsRead = isMarkAsRead;
49
50 this.$circle.toggleClass( 'mw-echo-ui-toggleReadCircleButtonWidget-circle-unread', !this.markAsRead );
51 const label = this.markAsRead ?
52 mw.msg( 'echo-notification-markasread' ) :
53 mw.msg( 'echo-notification-markasunread' );
54 this.setLabel( label );
55 this.setTitle( label );
56 };
57 }() );