Remove MMV options dialog in favour of Special:Preferences

MMV options dialog only allows to disable/enable MVV. Rely on Special:Preferences instead. Strips more than 2kB off the bundlesize.

Bug: T77349
Change-Id: I707ef2c0b6b8d4d13c05182078b82ddc99e32d12
This commit is contained in:
Simon Legner 2024-10-08 20:56:04 +02:00
parent 683ca2a2dd
commit e3badef708
16 changed files with 3 additions and 738 deletions

View file

@ -2,7 +2,7 @@
"modules": [
{
"resourceModule": "mmv",
"maxSize": "26.9 kB"
"maxSize": "24.7 kB"
},
{
"resourceModule": "mmv.ui.restriction",

View file

@ -68,7 +68,6 @@
"mmv/ui/mmv.ui.js",
"mmv/ui/mmv.ui.dialog.js",
"mmv/ui/mmv.ui.description.js",
"mmv/ui/mmv.ui.viewingOptions.js",
"mmv/ui/mmv.ui.canvas.js",
"mmv/ui/mmv.ui.canvasButtons.js",
"mmv/ui/mmv.ui.permission.js",
@ -81,7 +80,6 @@
],
"styles": [
"mmv/ui/mmv.ui.dialog.less",
"mmv/ui/mmv.ui.viewingOptions.less",
"mmv/ui/mmv.ui.canvas.less",
"mmv/ui/mmv.ui.canvasButtons.less",
"mmv/ui/mmv.ui.permission.less",
@ -108,13 +106,7 @@
"messages": [
"license-header",
"multimediaviewer-file-page",
"multimediaviewer-options-learn-more",
"multimediaviewer-options-dialog-header",
"multimediaviewer-option-submit-button",
"multimediaviewer-option-cancel-button",
"multimediaviewer-options-text-header",
"multimediaviewer-enable-alert",
"multimediaviewer-options-text-body",
"multimediaviewer-disable-confirmation-header",
"multimediaviewer-disable-confirmation-text",
"multimediaviewer-enable-dialog-header",
@ -131,7 +123,6 @@
"multimediaviewer-errorreport-privacywarning",
"multimediaviewer-download-link",
"multimediaviewer-reuse-link",
"multimediaviewer-options-tooltip",
"multimediaviewer-close-popup-text",
"multimediaviewer-fullscreen-popup-text",
"multimediaviewer-defullscreen-popup-text",
@ -173,12 +164,6 @@
"multimediaviewer-geoloc-coords",
"multimediaviewer-geolocation",
"multimediaviewer-about-mmv",
"multimediaviewer-optout-mmv",
"multimediaviewer-optin-mmv",
"multimediaviewer-optout-pending-mmv",
"multimediaviewer-optin-pending-mmv",
"multimediaviewer-optout-help",
"multimediaviewer-optin-help",
"mypreferences",
"multimediaviewer-metadata-error",
"multimediaviewer-title-popup-text",
@ -385,7 +370,6 @@
"tests/qunit/mmv/ui/mmv.ui.reuse.share.test.js",
"tests/qunit/mmv/ui/mmv.ui.reuse.utils.test.js",
"tests/qunit/mmv/ui/mmv.ui.truncatableTextField.test.js",
"tests/qunit/mmv/ui/mmv.ui.viewingOptions.test.js",
"tests/qunit/mmv/mmv.testhelpers.js"
],
"dependencies": [

View file

@ -58,12 +58,6 @@
"multimediaviewer-restriction-default": "This image may be restricted by legal provisions outside of copyright law. See the file description page for details.",
"multimediaviewer-restriction-default-and-others": "This image may be further restricted by other legal provisions outside of copyright law. See the file description page for details.",
"multimediaviewer-about-mmv": "About Media Viewer",
"multimediaviewer-optout-mmv": "Disable Media Viewer",
"multimediaviewer-optin-mmv": "Enable Media Viewer",
"multimediaviewer-optout-pending-mmv": "Disabling Media Viewer",
"multimediaviewer-optin-pending-mmv": "Enabling Media Viewer",
"multimediaviewer-optout-help": "Media Viewer will no longer be used to show images. To use it again, click on the \"{{int:multimediaviewer-view-expanded}}\" button next to any image. Then click on \"{{int:multimediaviewer-optin-mmv}}\".",
"multimediaviewer-optin-help": "Media Viewer will be used to show images.",
"multimediaviewer-geoloc-north": "N",
"multimediaviewer-geoloc-east": "E",
"multimediaviewer-geoloc-south": "S",
@ -137,13 +131,6 @@
"multimediaviewer-reuse-warning-generic": "Check [$1 its details] before using it.",
"multimediaviewer-attr-plain": "Plain",
"multimediaviewer-attr-html": "HTML",
"multimediaviewer-options-tooltip": "Enable or disable Media Viewer",
"multimediaviewer-options-dialog-header": "Disable Media Viewer?",
"multimediaviewer-options-text-header": "Skip this viewing feature for all files.",
"multimediaviewer-options-text-body": "You can enable it later through the file details page.",
"multimediaviewer-options-learn-more": "Learn more",
"multimediaviewer-option-submit-button": "Disable Media Viewer",
"multimediaviewer-option-cancel-button": "Cancel",
"multimediaviewer-disable-confirmation-header": "You have disabled Media Viewer",
"multimediaviewer-disable-confirmation-text": "Next time you click on a thumbnail on $1, you will directly view all file details.",
"multimediaviewer-enable-dialog-header": "Enable Media Viewer?",

View file

@ -71,12 +71,6 @@
"multimediaviewer-restriction-default": "Text of the tooltip for the default restriction label, that is displayed when hovered over.",
"multimediaviewer-restriction-default-and-others": "Text of the tooltip for the default restriction label when other restriction labels are present, that is displayed when hovered over.",
"multimediaviewer-about-mmv": "Text for a link to a page with more information about Media Viewer software.",
"multimediaviewer-optout-mmv": "Text for the opt-out link. Clicking on the link will turn off MediaViewer.\n\nSee also:\n* {{msg-mw|Multimediaviewer-optout-pending-mmv}}\n* {{msg-mw|Multimediaviewer-optin-mmv}}",
"multimediaviewer-optin-mmv": "Text for the opt-back link. Clicking it will undo the opt-out.\n\nSee also:\n* {{msg-mw|Multimediaviewer-optin-pending-mmv}}\n* {{msg-mw|Multimediaviewer-optout-mmv}}",
"multimediaviewer-optout-pending-mmv": "Text shown for the opt-out link while the optout request is being processed.\n\nSee also:\n* {{msg-mw|Multimediaviewer-optout-mmv}}\n* {{msg-mw|Multimediaviewer-optin-pending-mmv}}",
"multimediaviewer-optin-pending-mmv": "Text shown for the opt-in link while the optin request is being processed.\n\nSee also:\n* {{msg-mw|Multimediaviewer-optin-mmv}}\n* {{msg-mw|Multimediaviewer-optout-pending-mmv}}",
"multimediaviewer-optout-help": "Tooltip shown over the disabling link labeled {{msg-mw|Multimediaviewer-optout-mmv}}.\n\nRefers to {{msg-mw|Multimediaviewer-view-expanded}} and {{msg-mw|Multimediaviewer-optin-mmv}}.\n\nSee also:\n* {{msg-mw|Multimediaviewer-optin-help}}",
"multimediaviewer-optin-help": "Tooltip shown over the enabling link.\n\nThe link text is {{msg-mw|Multimediaviewer-optin-mmv}}.\n\nSee also:\n* {{msg-mw|Multimediaviewer-optout-mmv}}\n* {{msg-mw|Multimediaviewer-optout-help}}",
"multimediaviewer-geoloc-north": "{{optional}}\nSymbol for representing \"north\" in geolocation coordinates.\n\nUsed as <code>$4</code> in {{msg-mw|Multimediaviewer-geoloc-coord}}.",
"multimediaviewer-geoloc-east": "{{optional}}\nSymbol for representing \"east\" in geolocation coordinates.\n\nUsed as <code>$4</code> in {{msg-mw|Multimediaviewer-geoloc-coord}}.",
"multimediaviewer-geoloc-south": "{{optional}}\nSymbol for representing \"south\" in geolocation coordinates.\n\nUsed as <code>$4</code> in {{msg-mw|Multimediaviewer-geoloc-coord}}.",
@ -150,13 +144,6 @@
"multimediaviewer-reuse-warning-generic": "Generic message at the end of every warning. $1 is the link to the file page.\n\nIt = the file",
"multimediaviewer-attr-plain": "Label for a button that lets the user pick plain text as an output format.",
"multimediaviewer-attr-html": "{{optional}}\nLabel for a button that lets the user pick HTML as an output format.\n{{Identical|HTML}}",
"multimediaviewer-options-tooltip": "Tooltip for a button that opens a panel for enabling or disabling the media viewer.",
"multimediaviewer-options-dialog-header": "Header for a dialog that gives the user the option to disable the media viewer.",
"multimediaviewer-options-text-header": "Text explaining the changes that happen when a user disables media viewer.",
"multimediaviewer-options-text-body": "Text explaining how to re-enable the media viewer after disabling.",
"multimediaviewer-options-learn-more": "Text for a link to more information about the media viewer.",
"multimediaviewer-option-submit-button": "Button for submitting a preference change that modifies the default behavior for image clicks - disables the viewer.",
"multimediaviewer-option-cancel-button": "Button for canceling an action on a preference change that modifies the default behavior for image clicks - closes the dialog with no action.\n{{Identical|Cancel}}",
"multimediaviewer-disable-confirmation-header": "Header on a dialog that informs the user they've successfully disabled the media viewer.",
"multimediaviewer-disable-confirmation-text": "Text informing the user that they've successfully disabled the media viewer. $1 is the wiki's name.",
"multimediaviewer-enable-dialog-header": "Header for a dialog that allows users to re-enable media viewer.",

View file

@ -392,16 +392,9 @@ class MultimediaViewerBootstrap {
.append( ' ' )
.append( mw.msg( 'multimediaviewer-view-expanded' ) );
const $configButton = $( '<button>' )
.attr( 'title', mw.msg( 'multimediaviewer-view-config' ) )
.addClass( 'mw-mmv-view-config cdx-button cdx-button--icon-only' )
.append( $( '<span>' ).addClass( 'cdx-button__icon' ) )
// U+200B ZERO WIDTH SPACE to accomplish same height as $mmvButton
.append( '\u200B' );
const $filepageButtons = $( '<div>' )
.addClass( 'cdx-button-group mw-mmv-filepage-buttons' )
.append( $mmvButton, $configButton );
.append( $mmvButton );
// eslint-disable-next-line no-jquery/no-global-selector
$( '.fullMedia' ).append(
@ -425,14 +418,6 @@ class MultimediaViewerBootstrap {
return false;
} );
$configButton.on( 'click', () => {
$( document ).one( 'mmv-metadata', () => {
$( document ).trigger( 'mmv-options-open' );
} );
this.openImage( image );
return false;
} );
if ( Config.shouldShowStatusInfo() ) {
Config.disableStatusInfo();
this.showStatusInfo();

View file

@ -44,7 +44,6 @@ class DownloadDialog extends Dialog {
this.handleEvent( 'mmv-download-open', this.handleOpenCloseClick.bind( this ) );
this.handleEvent( 'mmv-reuse-open', this.closeDialog.bind( this ) );
this.handleEvent( 'mmv-options-open', this.closeDialog.bind( this ) );
}
/**

View file

@ -47,7 +47,6 @@ class ReuseDialog extends Dialog {
this.handleEvent( 'mmv-reuse-open', this.handleOpenCloseClick.bind( this ) );
this.handleEvent( 'mmv-download-open', this.closeDialog.bind( this ) );
this.handleEvent( 'mmv-options-open', this.closeDialog.bind( this ) );
}
/**

View file

@ -39,7 +39,6 @@ const Permission = require( './ui/mmv.ui.permission.js' );
const ProgressBar = require( './ui/mmv.ui.progressBar.js' );
const StripeButtons = require( './ui/mmv.ui.stripeButtons.js' );
const TruncatableTextField = require( './ui/mmv.ui.truncatableTextField.js' );
const OptionsDialog = require( './ui/mmv.ui.viewingOptions.js' );
const LightboxInterface = require( './mmv.lightboxinterface.js' );
const ThumbnailWidthCalculator = require( './mmv.ThumbnailWidthCalculator.js' );
const { extensions, useThumbnailGuessing } = require( './config.json' );
@ -884,7 +883,6 @@ module.exports = {
MetadataPanel,
MetadataPanelScroller,
MultimediaViewer,
OptionsDialog,
Permission,
ProgressBar,
StripeButtons,

View file

@ -18,7 +18,6 @@
const Canvas = require( './ui/mmv.ui.canvas.js' );
const CanvasButtons = require( './ui/mmv.ui.canvasButtons.js' );
const MetadataPanel = require( './ui/mmv.ui.metadataPanel.js' );
const OptionsDialog = require( './ui/mmv.ui.viewingOptions.js' );
const ThumbnailWidthCalculator = require( './mmv.ThumbnailWidthCalculator.js' );
const UiElement = require( './ui/mmv.ui.js' );
@ -122,7 +121,6 @@ class LightboxInterface extends UiElement {
this.downloadDialog = new DownloadDialog( this.$preDiv, this.buttons.$download );
return this.downloadDialog;
} );
this.optionsDialog = new OptionsDialog( this.$preDiv, this.buttons.$options );
}
/**
@ -248,7 +246,6 @@ class LightboxInterface extends UiElement {
this.fileReuse.attach();
this.downloadDialog.attach();
this.optionsDialog.attach();
this.attached = true;
}
@ -285,9 +282,6 @@ class LightboxInterface extends UiElement {
this.downloadDialog.unattach();
this.downloadDialog.closeDialog();
this.optionsDialog.unattach();
this.optionsDialog.closeDialog();
// Canvas listens for events from dialogs, so should be unattached at the end
this.canvas.unattach();

View file

@ -155,15 +155,9 @@ class Canvas extends UiElement {
case 'mmv-reuse-closed':
this.reuseOpen = false;
break;
case 'mmv-options-opened':
this.optionsOpen = true;
break;
case 'mmv-options-closed':
this.optionsOpen = false;
break;
}
this.dialogOpen = this.reuseOpen || this.downloadOpen || this.optionsOpen;
this.dialogOpen = this.reuseOpen || this.downloadOpen;
this.$image.toggleClass( 'mw-mmv-dialog-is-open', this.dialogOpen );
}
@ -174,16 +168,12 @@ class Canvas extends UiElement {
* @fires ReuseDialog#mmv-reuse-closed
* @fires DownloadDialog#mmv-download-opened
* @fires DownloadDialog#mmv-download-closed
* @fires OptionsDialog#mmv-options-opened
* @fires OptionsDialog#mmv-options-closed
*/
setUpImageClick() {
this.handleEvent( 'mmv-reuse-opened', this.handleDialogEvent.bind( this ) );
this.handleEvent( 'mmv-reuse-closed', this.handleDialogEvent.bind( this ) );
this.handleEvent( 'mmv-download-opened', this.handleDialogEvent.bind( this ) );
this.handleEvent( 'mmv-download-closed', this.handleDialogEvent.bind( this ) );
this.handleEvent( 'mmv-options-opened', this.handleDialogEvent.bind( this ) );
this.handleEvent( 'mmv-options-closed', this.handleDialogEvent.bind( this ) );
this.$image.on( 'click.mmv-canvas', ( e ) => {
// ignore clicks if the metadata panel or one of the dialogs is open - assume the intent is to

View file

@ -40,12 +40,6 @@ class CanvasButtons extends UiElement {
.prop( 'title', mw.msg( 'multimediaviewer-reuse-link' ) )
.append( $( '<span>' ).addClass( 'mw-mmv-icon' ) );
this.$options = $( '<button>' )
.text( ' ' )
.prop( 'title', mw.msg( 'multimediaviewer-options-tooltip' ) )
.addClass( 'cdx-button cdx-button--icon-only mw-mmv-button mw-mmv-options-button' )
.append( $( '<span>' ).addClass( 'mw-mmv-icon' ) );
this.$download = $( '<a>' )
.attr( 'role', 'button' )
.addClass( 'cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--icon-only mw-mmv-button mw-mmv-download-button' )
@ -69,7 +63,6 @@ class CanvasButtons extends UiElement {
.add( this.$download )
.add( this.$reuse )
.add( this.$fullscreen )
.add( this.$options )
.add( this.$next )
.add( this.$prev );
@ -121,8 +114,6 @@ class CanvasButtons extends UiElement {
* @fires ReuseDialog#mmv-reuse-closed
* @fires DownloadDialog#mmv-download-opened
* @fires DownloadDialog#mmv-download-closed
* @fires OptionsDialog#mmv-options-opened
* @fires OptionsDialog#mmv-options-closed
*/
attach() {
this.$reuse.on( 'click.mmv-canvasButtons', ( e ) => {
@ -139,16 +130,8 @@ class CanvasButtons extends UiElement {
this.handleEvent( 'mmv-download-opened', () => this.$download.addClass( 'open' ) );
this.handleEvent( 'mmv-download-closed', () => this.$download.removeClass( 'open' ) );
this.$options.on( 'click.mmv-canvasButtons', ( e ) => {
$( document ).trigger( 'mmv-options-open', e );
e.stopPropagation();
} );
this.handleEvent( 'mmv-options-opened', () => this.$options.addClass( 'open' ) );
this.handleEvent( 'mmv-options-closed', () => this.$options.removeClass( 'open' ) );
this.$download
.add( this.$reuse )
.add( this.$options )
.add( this.$close )
.add( this.$fullscreen );
}

View file

@ -51,7 +51,6 @@
// Positioning of buttons
.mw-mmv-download-button,
.mw-mmv-reuse-button,
.mw-mmv-options-button,
.mw-mmv-close,
.mw-mmv-fullscreen {
right: @buttons-offset-edge;
@ -94,14 +93,6 @@
}
}
.mw-mmv-options-button {
top: ( @buttons-offset-edge + ( 2 * @buttons-offset-each ) );
.mw-mmv-icon {
.cdx-mixin-css-icon( @cdx-icon-settings, @param-fill-color: @color-inverted-fixed );
}
}
.mw-mmv-next-image {
right: @size-icon-medium;

View file

@ -1,368 +0,0 @@
/*
* This file is part of the MediaWiki extension MultimediaViewer.
*
* MultimediaViewer is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MultimediaViewer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
*/
const { Config } = require( 'mmv.bootstrap' );
const { isMediaViewerEnabledOnClick } = require( 'mmv.head' );
const Dialog = require( './mmv.ui.dialog.js' );
const { helpLink } = require( '../config.json' );
/**
* Represents the viewing options dialog and the link to open it.
*/
class OptionsDialog extends Dialog {
/**
* @param {jQuery} $container the element to which the dialog will be appended
* @param {jQuery} $openButton the button which opens the dialog. Only used for positioning.
*/
constructor( $container, $openButton ) {
super( $container, $openButton );
this.$dialog.addClass( 'mw-mmv-options-dialog' );
this.eventPrefix = 'options';
this.initPanel();
}
attach() {
this.handleEvent( 'mmv-options-open', this.handleOpenCloseClick.bind( this ) );
this.handleEvent( 'mmv-reuse-open', this.closeDialog.bind( this ) );
this.handleEvent( 'mmv-download-open', this.closeDialog.bind( this ) );
}
/**
* Initialises UI elements.
*/
initPanel() {
this.initEnableConfirmation();
this.initDisableConfirmation();
this.initEnableDiv();
this.initDisableDiv();
}
/**
* Initialises the enable confirmation pane.
*/
initEnableConfirmation() {
this.createConfirmationPane(
'mw-mmv-enable-confirmation',
'$enableConfirmation',
[
mw.msg( 'multimediaviewer-enable-confirmation-header' ),
mw.msg( 'multimediaviewer-enable-confirmation-text', mw.config.get( 'wgSiteName' ) )
] );
}
/**
* Initialises the disable confirmation pane.
*/
initDisableConfirmation() {
this.createConfirmationPane(
'mw-mmv-disable-confirmation',
'$disableConfirmation',
[
mw.msg( 'multimediaviewer-disable-confirmation-header' ),
mw.msg( 'multimediaviewer-disable-confirmation-text', mw.config.get( 'wgSiteName' ) )
] );
}
/**
* Initialises the enable action pane.
*/
initEnableDiv() {
this.createActionPane(
'mw-mmv-options-enable',
'$enableDiv',
mw.msg( 'multimediaviewer-enable-submit-button' ),
[
mw.msg( 'multimediaviewer-enable-dialog-header' ),
mw.msg( 'multimediaviewer-enable-text-header' )
], true );
}
/**
* Initialises the disable action pane.
*/
initDisableDiv() {
this.createActionPane(
'mw-mmv-options-disable',
'$disableDiv',
mw.msg( 'multimediaviewer-option-submit-button' ),
[
mw.msg( 'multimediaviewer-options-dialog-header' ),
mw.msg( 'multimediaviewer-options-text-header' ),
mw.msg( 'multimediaviewer-options-text-body' )
], false );
}
/**
* Hides all of the divs.
*/
hideDivs() {
this.$dialog.removeClass( 'mw-mmv-disable-confirmation-shown mw-mmv-enable-confirmation-shown mw-mmv-enable-div-shown' );
this.$disableDiv
.add( this.$disableConfirmation )
.add( this.$enableDiv )
.add( this.$enableConfirmation )
.removeClass( 'mw-mmv-shown' );
}
/**
* Shows the confirmation div for the disable action.
*/
showDisableConfirmation() {
this.hideDivs();
this.$disableConfirmation.addClass( 'mw-mmv-shown' );
this.$dialog.addClass( 'mw-mmv-disable-confirmation-shown' );
}
/**
* Shows the confirmation div for the enable action.
*/
showEnableConfirmation() {
this.hideDivs();
this.$enableConfirmation.addClass( 'mw-mmv-shown' );
this.$dialog.addClass( 'mw-mmv-enable-confirmation-shown' );
}
/**
* Fired when the dialog is opened.
*
* @event OptionsDialog#mmv-options-opened
*/
/**
* Opens a dialog with information about file reuse.
*/
openDialog() {
if ( isMediaViewerEnabledOnClick() ) {
this.$disableDiv.addClass( 'mw-mmv-shown' );
} else {
this.$enableDiv.addClass( 'mw-mmv-shown' );
this.$dialog.addClass( 'mw-mmv-enable-div-shown' );
}
super.openDialog();
$( document ).trigger( 'mmv-options-opened' );
}
/**
* Fired when the dialog is closed.
*
* @event OptionsDialog#mmv-options-closed
*/
/**
* Closes the options dialog.
*
* @param {Event} [e] Event object when the close action is caused by a user
* action, as opposed to closing the window or something.
*/
closeDialog( e ) {
const wasConfirmation = this.$dialog.is( '.mw-mmv-disable-confirmation-shown' ) || this.$dialog.is( '.mw-mmv-enable-confirmation-shown' );
super.closeDialog();
$( document ).trigger( 'mmv-options-closed' );
this.hideDivs();
if ( e && $( e.target ).is( '.mw-mmv-options-button' ) && wasConfirmation ) {
this.openDialog();
}
}
/**
* Creates a confirmation pane.
*
* @param {string} divClass Class applied to main div.
* @param {string} propName Name of the property on this object to which we'll assign the div.
* @param {string} msgs See #addText
*/
createConfirmationPane( divClass, propName, msgs ) {
const $div = $( '<div>' )
// The following classes are used here:
// * mw-mmv-enable-confirmation
// * mw-mmv-disable-confirmation
.addClass( divClass )
.appendTo( this.$dialog );
$( '<div>' )
.text( '\u00A0' )
.addClass( 'mw-mmv-confirmation-close' )
.on( 'click', () => this.closeDialog() )
.appendTo( $div );
this.addText( $div, msgs );
this[ propName ] = $div;
}
/**
* Creates an action pane.
*
* @param {string} divClass Class applied to main div.
* @param {string} propName Name of the property on this object to which we'll assign the div.
* @param {string} smsg Message for the submit button.
* @param {string} msgs See #addText
* @param {boolean} enabled Whether this dialog is an enable one.
*/
createActionPane( divClass, propName, smsg, msgs, enabled ) {
const $div = $( '<div>' )
// The following classes are used here:
// * mw-mmv-options-enable
// * mw-mmv-options-disable
.addClass( divClass )
.appendTo( this.$dialog );
if ( enabled ) {
$( '<div>' )
.addClass( 'mw-mmv-options-enable-alert' )
.text( mw.msg( 'multimediaviewer-enable-alert' ) )
.appendTo( $div );
}
this.addText( $div, msgs );
this.addInfoLink( $div );
this.makeButtons( $div, smsg, enabled );
this[ propName ] = $div;
}
/**
* Creates buttons for the dialog.
*
* @param {jQuery} $container
* @param {string} smsg Message for the submit button.
* @param {boolean} enabled Whether the viewer is enabled after this dialog is submitted.
*/
makeButtons( $container, smsg, enabled ) {
const $submitDiv = $( '<div>' )
.addClass( 'mw-mmv-options-submit' )
.appendTo( $container );
this.makeSubmitButton(
$submitDiv,
smsg,
enabled
);
this.makeCancelButton( $submitDiv );
}
/**
* Makes a submit button for one of the panels.
*
* @param {jQuery} $submitDiv The div for the buttons in the dialog.
* @param {string} msg The string to put in the button.
* @param {boolean} enabled Whether to turn the viewer on or off when this button is pressed.
* @return {jQuery} Submit button
*/
makeSubmitButton( $submitDiv, msg, enabled ) {
return $( '<button>' )
.addClass( 'mw-mmv-options-submit-button cdx-button cdx-button--action-progressive cdx-button--weight-primary' )
.text( msg )
.appendTo( $submitDiv )
.on( 'click', () => {
const $buttons = $( this ).closest( '.mw-mmv-options-submit' ).find( '.mw-mmv-options-submit-button, .mw-mmv-options-cancel-button' );
$buttons.prop( 'disabled', true );
Config.setMediaViewerEnabledOnClick( enabled ).done( () => {
if ( enabled ) {
this.showEnableConfirmation();
} else {
this.showDisableConfirmation();
}
} ).always( () => {
$buttons.prop( 'disabled', false );
} );
return false;
} );
}
/**
* Makes a cancel button for one of the panels.
*
* @param {jQuery} $submitDiv The div for the buttons in the dialog.
* @return {jQuery} Cancel button
*/
makeCancelButton( $submitDiv ) {
return $( '<button>' )
.addClass( 'mw-mmv-options-cancel-button cdx-button cdx-button--weight-quiet' )
.text( mw.msg( 'multimediaviewer-option-cancel-button' ) )
.appendTo( $submitDiv )
.on( 'click', () => {
this.closeDialog();
return false;
} );
}
/**
* Adds text to a dialog.
*
* @param {jQuery} $container
* @param {string[]} msgs The messages to be added.
*/
addText( $container, msgs ) {
const $text = $( '<div>' )
.addClass( 'mw-mmv-options-text' );
const adders = [
( msg ) => {
$( '<h3>' )
.text( msg )
.addClass( 'mw-mmv-options-dialog-header' )
.appendTo( $container );
},
( msg ) => {
$( '<p>' )
.text( msg )
.addClass( 'mw-mmv-options-text-header' )
.appendTo( $text );
},
( msg ) => {
$( '<p>' )
.text( msg )
.addClass( 'mw-mmv-options-text-body' )
.appendTo( $text );
}
];
for ( let i = 0; i < msgs.length && i < adders.length; i++ ) {
adders[ i ]( msgs[ i ] );
}
$text.appendTo( $container );
}
/**
* Adds the info link to the panel.
*
* @param {jQuery} $div The panel to which we're adding the link.
*/
addInfoLink( $div ) {
$( '<a>' )
.addClass( 'mw-mmv-project-info-link' )
.prop( 'href', helpLink )
.text( mw.message( 'multimediaviewer-options-learn-more' ) )
.appendTo( $div.find( '.mw-mmv-options-text' ) );
}
}
module.exports = OptionsDialog;

View file

@ -1,137 +0,0 @@
@import 'mediawiki.skin.variables.less';
@import '../mmv.variables.less';
@import '../mmv.mixins.less';
.mw-mmv-options-dialog {
@offset-top: @buttons-offset-edge + ( 2 * @buttons-offset-each );
top: @offset-top;
height: auto;
z-index: 1004;
padding: 15px;
&.mw-mmv-enable-confirmation-shown {
background-color: #00af89;
box-shadow: 0 2px 0 #00634e;
.mw-mmv-dialog-down-arrow {
background-color: #00af89;
}
}
&.mw-mmv-disable-confirmation-shown,
&.mw-mmv-disable-confirmation-shown .mw-mmv-dialog-down-arrow,
&.mw-mmv-enable-div-shown .mw-mmv-dialog-down-arrow {
background-color: @background-color-base;
}
.mw-mmv-dialog-down-arrow {
@arrow-size: 20px;
top: ( @offset-top + ( @arrow-size / 2 ) );
}
.mw-mmv-enable-confirmation,
.mw-mmv-disable-confirmation,
.mw-mmv-options-enable,
.mw-mmv-options-disable {
position: relative;
display: none;
&.mw-mmv-shown {
display: block;
}
}
.mw-mmv-confirmation-close {
display: inline-block;
position: absolute;
right: 0;
top: 0;
.cdx-mixin-css-icon( @cdx-icon-close, @param-fill-color: @color-base );
cursor: pointer;
}
.mw-mmv-disable-confirmation {
.mw-mmv-options-dialog-header {
color: @color-base;
padding: 0;
}
.mw-mmv-options-text-header {
color: @color-base;
}
}
.mw-mmv-enable-confirmation {
.mw-mmv-options-dialog-header {
color: #fff;
padding: 0;
}
.mw-mmv-options-text-header {
color: #fff;
}
}
.mw-mmv-disable-confirmation,
.mw-mmv-enable-confirmation {
padding: 0;
.mw-mmv-options-text {
left: 0;
}
}
}
.mw-mmv-options-submit {
margin-top: 10px;
}
.mw-mmv-options-text {
left: 68px;
right: 0;
line-height: 1.4;
.mw-mmv-options-enable & {
top: 70px;
}
}
.mw-mmv-options-subcontainer .mw-mmv-options-text {
margin-left: 68px;
}
.mw-mmv-options-cancel-button,
.mw-mmv-options-submit-button {
float: right;
}
.mw-mmv-options-dialog-header {
padding-top: 0;
font-weight: normal;
font-size: 1.25em;
color: @color-base;
.mw-mmv-options-enable & {
top: 35px;
}
}
.mw-mmv-options-text-header,
.mw-mmv-options-text-body {
margin: 0;
font-size: 1em;
color: @color-subtle;
}
.mw-mmv-options-enable-alert {
background-color: @background-color-base;
color: @color-base;
position: absolute;
left: -15px;
right: -15px;
top: -15px;
border-top-right-radius: @border-radius-base;
border-top-left-radius: @border-radius-base;
padding: 10px 15px;
font-weight: 500;
}

View file

@ -50,4 +50,3 @@ require( './ui/mmv.ui.reuse.embed.test.js' );
require( './ui/mmv.ui.reuse.share.test.js' );
require( './ui/mmv.ui.reuse.utils.test.js' );
require( './ui/mmv.ui.truncatableTextField.test.js' );
require( './ui/mmv.ui.viewingOptions.test.js' );

View file

@ -1,126 +0,0 @@
const { Config } = require( 'mmv.bootstrap' );
const { OptionsDialog } = require( 'mmv' );
( function () {
function makeDialog( initialise ) {
const $qf = $( '#qunit-fixture' );
const $button = $( '<div>' ).appendTo( $qf );
const dialog = new OptionsDialog( $qf, $button );
if ( initialise ) {
dialog.initPanel();
}
return dialog;
}
QUnit.module( 'mmv.ui.viewingOptions', QUnit.newMwEnvironment() );
QUnit.test( 'Constructor sense test', ( assert ) => {
const dialog = makeDialog();
assert.true( dialog instanceof OptionsDialog, 'Dialog is created successfully' );
} );
QUnit.test( 'Initialisation functions', ( assert ) => {
const dialog = makeDialog( true );
assert.strictEqual( dialog.$disableDiv.length, 1, 'Disable div is created.' );
assert.strictEqual( dialog.$enableDiv.length, 1, 'Enable div is created.' );
assert.strictEqual( dialog.$disableConfirmation.length, 1, 'Disable confirmation is created.' );
assert.strictEqual( dialog.$enableConfirmation.length, 1, 'Enable confirmation is created.' );
} );
QUnit.test( 'Disable', function ( assert ) {
const dialog = makeDialog();
const deferred = $.Deferred();
this.sandbox.stub( Config, 'setMediaViewerEnabledOnClick', () => deferred );
dialog.initDisableDiv();
const $header = dialog.$disableDiv.find( 'h3.mw-mmv-options-dialog-header' );
const $text = dialog.$disableDiv.find( 'div.mw-mmv-options-text' );
const $textHeader = $text.find( 'p.mw-mmv-options-text-header' );
const $textBody = $text.find( 'p.mw-mmv-options-text-body' );
const $aboutLink = $text.find( 'a.mw-mmv-project-info-link' );
const $submitButton = dialog.$disableDiv.find( 'button.mw-mmv-options-submit-button' );
const $cancelButton = dialog.$disableDiv.find( 'button.mw-mmv-options-cancel-button' );
assert.strictEqual( $header.length, 1, 'Disable header created successfully.' );
assert.strictEqual( $header.text(), '(multimediaviewer-options-dialog-header)', 'Disable header has correct text (if this fails, it may be due to i18n differences)' );
assert.strictEqual( $text.length, 1, 'Text div created successfully.' );
assert.strictEqual( $textHeader.length, 1, 'Text header created successfully.' );
assert.strictEqual( $textHeader.text(), '(multimediaviewer-options-text-header)', 'Text header has correct text (if this fails, it may be due to i18n differences)' );
assert.strictEqual( $textBody.length, 1, 'Text body created successfully.' );
assert.strictEqual( $textBody.text(), '(multimediaviewer-options-text-body)', 'Text body has correct text (if this fails, it may be due to i18n differences)' );
assert.strictEqual( $aboutLink.length, 1, 'About link created successfully.' );
assert.strictEqual( $aboutLink.text(), '(multimediaviewer-options-learn-more)', 'About link has correct text (if this fails, it may be due to i18n differences)' );
assert.strictEqual( $submitButton.length, 1, 'Disable button created successfully.' );
assert.strictEqual( $submitButton.text(), '(multimediaviewer-option-submit-button)', 'Disable button has correct text (if this fails, it may be due to i18n differences)' );
assert.strictEqual( $cancelButton.length, 1, 'Cancel button created successfully.' );
assert.strictEqual( $cancelButton.text(), '(multimediaviewer-option-cancel-button)', 'Cancel button has correct text (if this fails, it may be due to i18n differences)' );
$submitButton.trigger( 'click' );
assert.strictEqual( dialog.$disableConfirmation.hasClass( 'mw-mmv-shown' ), false, 'Disable confirmation not shown yet' );
assert.strictEqual( dialog.$dialog.hasClass( 'mw-mmv-disable-confirmation-shown' ), false, 'Disable confirmation not shown yet' );
// Pretend that the async call in mmv.js succeeded
deferred.resolve();
// The confirmation should appear
assert.strictEqual( dialog.$disableConfirmation.hasClass( 'mw-mmv-shown' ), true, 'Disable confirmation shown' );
assert.strictEqual( dialog.$dialog.hasClass( 'mw-mmv-disable-confirmation-shown' ), true, 'Disable confirmation shown' );
} );
QUnit.test( 'Enable', function ( assert ) {
const dialog = makeDialog();
const deferred = $.Deferred();
this.sandbox.stub( Config, 'setMediaViewerEnabledOnClick', () => deferred );
dialog.initEnableDiv();
const $header = dialog.$enableDiv.find( 'h3.mw-mmv-options-dialog-header' );
const $text = dialog.$enableDiv.find( 'div.mw-mmv-options-text' );
const $textHeader = $text.find( 'p.mw-mmv-options-text-header' );
const $aboutLink = $text.find( 'a.mw-mmv-project-info-link' );
const $submitButton = dialog.$enableDiv.find( 'button.mw-mmv-options-submit-button' );
const $cancelButton = dialog.$enableDiv.find( 'button.mw-mmv-options-cancel-button' );
assert.strictEqual( $header.length, 1, 'Enable header created successfully.' );
assert.strictEqual( $header.text(), '(multimediaviewer-enable-dialog-header)', 'Enable header has correct text (if this fails, it may be due to i18n differences)' );
assert.strictEqual( $text.length, 1, 'Text div created successfully.' );
assert.strictEqual( $textHeader.length, 1, 'Text header created successfully.' );
assert.strictEqual( $textHeader.text(), '(multimediaviewer-enable-text-header)', 'Text header has correct text (if this fails, it may be due to i18n differences)' );
assert.strictEqual( $aboutLink.length, 1, 'About link created successfully.' );
assert.strictEqual( $aboutLink.text(), '(multimediaviewer-options-learn-more)', 'About link has correct text (if this fails, it may be due to i18n differences)' );
assert.strictEqual( $submitButton.length, 1, 'Enable button created successfully.' );
assert.strictEqual( $submitButton.text(), '(multimediaviewer-enable-submit-button)', 'Enable button has correct text (if this fails, it may be due to i18n differences)' );
assert.strictEqual( $cancelButton.length, 1, 'Cancel button created successfully.' );
assert.strictEqual( $cancelButton.text(), '(multimediaviewer-option-cancel-button)', 'Cancel button has correct text (if this fails, it may be due to i18n differences)' );
$submitButton.trigger( 'click' );
assert.strictEqual( dialog.$enableConfirmation.hasClass( 'mw-mmv-shown' ), false, 'Enable confirmation not shown yet' );
assert.strictEqual( dialog.$dialog.hasClass( 'mw-mmv-enable-confirmation-shown' ), false, 'Enable confirmation not shown yet' );
// Pretend that the async call in mmv.js succeeded
deferred.resolve();
// The confirmation should appear
assert.strictEqual( dialog.$enableConfirmation.hasClass( 'mw-mmv-shown' ), true, 'Enable confirmation shown' );
assert.strictEqual( dialog.$dialog.hasClass( 'mw-mmv-enable-confirmation-shown' ), true, 'Enable confirmation shown' );
} );
}() );