Debian Codegraph @

extensions/MultimediaViewer/resources/mmv.ui.reuse/mmv.ui.reuse.dialog.js

raw symbols SCIP
1 /*
2 * This file is part of the MediaWiki extension MultimediaViewer.
3 *
4 * MultimediaViewer is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * MultimediaViewer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 const { Dialog } = require( 'mmv' );
19 const Embed = require( './mmv.ui.reuse.embed.js' );
20 const Share = require( './mmv.ui.reuse.share.js' );
21
22 /**
23 * Represents the file reuse dialog and the link to open it.
24 */
25 class ReuseDialog extends Dialog {
26 /**
27 * @param {jQuery} $container the element to which the dialog will be appended
28 * @param {jQuery} $openButton the button which opens the dialog. Only used for positioning.
29 */
30 constructor( $container, $openButton ) {
31 super( $container, $openButton );
32
33 this.share = new Share( this.$dialog );
34 this.embed = new Embed( this.$dialog );
35 this.$dialog.addClass( 'mw-mmv-reuse-dialog' );
36
37 this.eventPrefix = 'use-this-file';
38 }
39
40 /**
41 * Registers listeners.
42 */
43 attach() {
44 this.share.attach();
45 this.embed.attach();
46
47 this.handleEvent( 'mmv-reuse-open', this.handleOpenCloseClick.bind( this ) );
48
49 this.handleEvent( 'mmv-download-open', this.closeDialog.bind( this ) );
50 }
51
52 /**
53 * Sets data needed by contained panes and makes dialog launch link visible.
54 *
55 * @param {ImageModel} image
56 * @param {string} caption
57 * @param {string} alt
58 */
59 set( image, caption, alt ) {
60 this.share.set( image );
61 this.embed.set( image, caption, alt );
62 this.showImageWarnings( image );
63 }
64
65 /**
66 * Fired when the dialog is opened.
67 *
68 * @event ReuseDialog#mmv-reuse-opened
69 */
70
71 /**
72 * Opens a dialog with information about file reuse.
73 */
74 openDialog() {
75 super.openDialog();
76
77 this.$warning.insertAfter( this.$container );
78
79 $( document ).trigger( 'mmv-reuse-opened' );
80 }
81
82 /**
83 * Fired when the dialog is closed.
84 *
85 * @event ReuseDialog#mmv-reuse-closed
86 */
87
88 /**
89 * Closes the reuse dialog.
90 */
91 closeDialog() {
92 super.closeDialog();
93
94 $( document ).trigger( 'mmv-reuse-closed' );
95 }
96 }
97
98 module.exports = ReuseDialog;