Page MenuHomePhabricator
Paste P8248

ext.pageTriage.toolbarView.js
ActivePublic

Authored by kostajh on Mar 21 2019, 2:28 AM.
Tags
None
Referenced Files
F28432710: raw.txt
Mar 21 2019, 2:28 AM
Subscribers
None
diff --git a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.toolbarView.js b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.toolbarView.js
index c5e3761..0fa8bd8 100644
--- a/modules/ext.pageTriage.views.toolbar/ext.pageTriage.toolbarView.js
+++ b/modules/ext.pageTriage.views.toolbar/ext.pageTriage.toolbarView.js
@@ -127,20 +127,19 @@ $( function () {
// create a link to open or close the toolbar and append it
$( '#p-tb' ).find( 'ul' ).append(
$( '<li>' ).attr( 'id', 't-curationtoolbar' ).append(
- $( '<a>' ).attr( 'href', '#' )
+ $( '<a>' )
+ .attr( 'href', '#' )
+ .text( that.getUpdatedLinkText() )
+ .on( 'click', function () {
+ $( '#mwe-pt-toolbar' ).toggle();
+ $( '#mw-content-text .patrollink' ).toggle();
+ that.setToolbarPreference(
+ $( 'mwe-pt-toolbar' ).is( ':hidden' ) ? 'hidden' : 'maximized'
+ )
+ that.updateLinkText();
+ } )
)
);
- // get the link working
- $( '#t-curationtoolbar' ).find( 'a' ).on( 'click', function () {
- $( '#mwe-pt-toolbar' ).toggle();
- $( '#mw-content-text .patrollink' ).toggle();
- if ( $( 'mwe-pt-toolbar' ).is( ':hidden' ) ) {
- that.setToolbarPreference( 'hidden' );
- } else {
- that.setToolbarPreference( 'maximized' );
- }
- that.updateLinkText();
- } );
// Show the toolbar based on saved prefs.
switch ( mw.user.options.get( 'userjs-curationtoolbar' ) ) {
@@ -227,8 +226,6 @@ $( function () {
$( '#mwe-pt-toolbar' ).removeClass( 'mwe-pt-toolbar-small' ).addClass( 'mwe-pt-toolbar-big' )
// reset alignment to the side of the screen (since the toolbar is wider now)
.css( toolbarPosCss );
- // update sidebar link text
- this.updateLinkText();
// set a pref for the user so the minimize state is remembered
if ( typeof savePref !== 'undefined' && savePref === true ) {
this.setToolbarPreference( 'maximized' );
@@ -238,13 +235,20 @@ $( function () {
setToolbarPreference: function ( state ) {
return new mw.Api().saveOption( 'userjs-curationtoolbar', state );
},
+ /**
+ * Update the page curation toolbar link text based on toolbar open/closed status.
+ */
updateLinkText: function () {
- var $link = $( '#t-curationtoolbar' ).find( 'a' );
- if ( $( '#mwe-pt-toolbar' ).is( ':hidden' ) ) {
- $link.text( mw.msg( 'pagetriage-toolbar-linktext-open' ) );
- } else {
- $link.text( mw.msg( 'pagetriage-toolbar-linktext-hide' ) );
- }
+ $( '#t-curationtoolbar' )
+ .find( 'a' )
+ .text( this.getUpdatedLinkText() );
+ },
+ /**
+ * Get text to show with the page curation toolbar link.
+ * @returns {string}
+ */
+ getUpdatedLinkText: function () {
+ return $( '#mwe-pt-toolbar' ).is( ':hidden' ) ? mw.msg( 'pagetriage-toolbar-linktext-open' ) : mw.msg( 'pagetriage-toolbar-linktext-hide' );
}
} );