2014-03-17 08:07:53 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2024-05-23 20:13:50 +00:00
|
|
|
const { Dialog } = require( 'mmv' );
|
|
|
|
const Embed = require( './mmv.ui.reuse.embed.js' );
|
|
|
|
const Share = require( './mmv.ui.reuse.share.js' );
|
2023-05-19 20:26:45 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Represents the file reuse dialog and the link to open it.
|
|
|
|
*/
|
|
|
|
class ReuseDialog extends Dialog {
|
2014-03-17 08:07:53 +00:00
|
|
|
/**
|
2024-05-21 20:12:08 +00:00
|
|
|
* @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.
|
2014-03-17 08:07:53 +00:00
|
|
|
*/
|
2024-08-11 09:58:39 +00:00
|
|
|
constructor( $container, $openButton ) {
|
|
|
|
super( $container, $openButton );
|
2014-09-16 20:33:05 +00:00
|
|
|
|
2024-05-23 20:13:50 +00:00
|
|
|
this.share = new Share( this.$dialog );
|
|
|
|
this.embed = new Embed( this.$dialog );
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$dialog.addClass( 'mw-mmv-reuse-dialog' );
|
|
|
|
|
|
|
|
this.eventPrefix = 'use-this-file';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers listeners.
|
|
|
|
*/
|
|
|
|
attach() {
|
2024-05-23 20:13:50 +00:00
|
|
|
this.share.attach();
|
|
|
|
this.embed.attach();
|
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.handleEvent( 'mmv-reuse-open', this.handleOpenCloseClick.bind( this ) );
|
2014-03-17 08:07:53 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.handleEvent( 'mmv-download-open', this.closeDialog.bind( this ) );
|
|
|
|
this.handleEvent( 'mmv-options-open', this.closeDialog.bind( this ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets data needed by contained panes and makes dialog launch link visible.
|
|
|
|
*
|
2024-05-29 08:54:16 +00:00
|
|
|
* @param {ImageModel} image
|
2024-05-21 20:12:08 +00:00
|
|
|
* @param {string} caption
|
|
|
|
* @param {string} alt
|
|
|
|
*/
|
2024-05-29 08:54:16 +00:00
|
|
|
set( image, caption, alt ) {
|
2024-05-23 20:13:50 +00:00
|
|
|
this.share.set( image );
|
2024-05-29 08:54:16 +00:00
|
|
|
this.embed.set( image, caption, alt );
|
2024-05-23 20:13:50 +00:00
|
|
|
this.showImageWarnings( image );
|
2024-05-21 20:12:08 +00:00
|
|
|
}
|
2024-02-13 00:44:51 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Fired when the dialog is opened.
|
|
|
|
*
|
|
|
|
* @event ReuseDialog#mmv-reuse-opened
|
|
|
|
*/
|
2014-04-11 14:05:58 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Opens a dialog with information about file reuse.
|
|
|
|
*/
|
|
|
|
openDialog() {
|
|
|
|
super.openDialog();
|
2023-05-20 13:02:55 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$warning.insertAfter( this.$container );
|
2014-09-05 12:52:53 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
$( document ).trigger( 'mmv-reuse-opened' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fired when the dialog is closed.
|
|
|
|
*
|
|
|
|
* @event ReuseDialog#mmv-reuse-closed
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the reuse dialog.
|
|
|
|
*/
|
|
|
|
closeDialog() {
|
|
|
|
super.closeDialog();
|
|
|
|
|
|
|
|
$( document ).trigger( 'mmv-reuse-closed' );
|
2023-05-20 12:38:59 +00:00
|
|
|
}
|
2024-05-21 20:12:08 +00:00
|
|
|
}
|
2014-04-02 01:58:41 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
module.exports = ReuseDialog;
|