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