| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
mw.echo.ui.SpecialHelpMenuWidget = function MwEchoUiSpecialHelpMenuWidget( manager, config ) { |
| 10 |
config = config || {}; |
| 11 |
|
| 12 |
|
| 13 |
mw.echo.ui.SpecialHelpMenuWidget.super.call( this, Object.assign( { |
| 14 |
icon: 'settings', |
| 15 |
label: mw.msg( 'echo-specialpage-special-help-menu-widget-aria-label' ), |
| 16 |
indicator: 'down', |
| 17 |
invisibleLabel: true, |
| 18 |
menu: { |
| 19 |
classes: [ 'mw-echo-ui-specialHelpMenuWidget-menu' ], |
| 20 |
horizontalPosition: 'end', |
| 21 |
width: 'auto' |
| 22 |
} |
| 23 |
}, config ) ); |
| 24 |
|
| 25 |
this.manager = manager; |
| 26 |
|
| 27 |
this.markAllReadOption = new OO.ui.MenuOptionWidget( { |
| 28 |
icon: 'checkAll', |
| 29 |
label: this.getMarkAllReadOptionLabel( |
| 30 |
this.manager.getPaginationModel().getCurrentPageItemCount() |
| 31 |
), |
| 32 |
data: 'markAllRead' |
| 33 |
} ); |
| 34 |
this.markAllReadOption.toggle( false ); |
| 35 |
|
| 36 |
this.menu.addItems( [ this.markAllReadOption ] ); |
| 37 |
if ( config.prefLink ) { |
| 38 |
this.menu.addItems( [ |
| 39 |
|
| 40 |
new OO.ui.MenuOptionWidget( { |
| 41 |
|
| 42 |
$element: $( '<a>' ).attr( 'href', config.prefLink ), |
| 43 |
icon: 'settings', |
| 44 |
label: mw.msg( 'mypreferences' ), |
| 45 |
data: { href: config.prefLink } |
| 46 |
} ) |
| 47 |
] ); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
this.manager.connect( this, { |
| 52 |
localCountChange: 'onLocalCountChange' |
| 53 |
} ); |
| 54 |
this.manager.getFiltersModel().getSourcePagesModel().connect( this, { update: 'onSourcePageUpdate' } ); |
| 55 |
this.menu.connect( this, { choose: 'onMenuChoose' } ); |
| 56 |
|
| 57 |
this.$element.addClass( 'mw-echo-ui-specialHelpMenuWidget' ); |
| 58 |
}; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
OO.inheritClass( mw.echo.ui.SpecialHelpMenuWidget, OO.ui.ButtonMenuSelectWidget ); |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
mw.echo.ui.SpecialHelpMenuWidget.prototype.onSourcePageUpdate = function () { |
| 78 |
const sourcePagesModel = this.manager.getFiltersModel().getSourcePagesModel(), |
| 79 |
source = sourcePagesModel.getCurrentSource(), |
| 80 |
sourcePages = sourcePagesModel.getSourcePages( source ), |
| 81 |
currentPage = sourcePagesModel.getCurrentPage(), |
| 82 |
currentCount = currentPage ? |
| 83 |
sourcePages[ currentPage ].count : |
| 84 |
sourcePagesModel.getSourceTotalCount( source ); |
| 85 |
|
| 86 |
this.markAllReadOption.setLabel( this.getMarkAllReadOptionLabel( currentCount ) ); |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
mw.echo.ui.SpecialHelpMenuWidget.prototype.onLocalCountChange = function ( count ) { |
| 95 |
this.markAllReadOption.setLabel( this.getMarkAllReadOptionLabel( count ) ); |
| 96 |
this.markAllReadOption.toggle( count > 0 ); |
| 97 |
}; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
mw.echo.ui.SpecialHelpMenuWidget.prototype.onMenuChoose = function ( item ) { |
| 106 |
const data = item.getData(); |
| 107 |
if ( data.href ) { |
| 108 |
location.href = data.href; |
| 109 |
} else if ( data === 'markAllRead' ) { |
| 110 |
this.emit( 'markAllRead' ); |
| 111 |
} |
| 112 |
}; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
mw.echo.ui.SpecialHelpMenuWidget.prototype.getMarkAllReadOptionLabel = function ( count ) { |
| 121 |
const pageModel = this.manager.getFiltersModel().getSourcePagesModel(), |
| 122 |
source = pageModel.getCurrentSource(), |
| 123 |
sourceTitle = pageModel.getSourceTitle( source ); |
| 124 |
|
| 125 |
return sourceTitle ? |
| 126 |
mw.msg( 'echo-mark-wiki-as-read', sourceTitle, count ) : |
| 127 |
mw.msg( 'echo-mark-all-as-read', count ); |
| 128 |
}; |
| 129 |
|
| 130 |
}() ); |