Debian Codegraph @

extensions/MultimediaViewer/resources/mmv/ui/mmv.ui.canvasButtons.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 UiElement = require( './mmv.ui.js' );
19
20 /**
21 * Represents the buttons which are displayed over the image - next, previous, close
22 * and fullscreen.
23 */
24 class CanvasButtons extends UiElement {
25 /**
26 * @param {jQuery} $container The parent element we should put the buttons into.
27 * @param {jQuery} $closeButton The close button element from the parent class.
28 * @param {jQuery} $fullscreenButton The fullscreen button from the parent class.
29 * @fires MultimediaViewer#mmv-close
30 */
31 constructor( $container, $closeButton, $fullscreenButton ) {
32 super( $container );
33
34 this.$close = $closeButton;
35 this.$fullscreen = $fullscreenButton;
36
37 this.$reuse = $( '<a>' )
38 .attr( 'role', 'button' )
39 .addClass( 'cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--icon-only mw-mmv-button mw-mmv-reuse-button' )
40 .prop( 'title', mw.msg( 'multimediaviewer-reuse-link' ) )
41 .append( $( '<span>' ).addClass( 'mw-mmv-icon' ) );
42
43 this.$download = $( '<a>' )
44 .attr( 'role', 'button' )
45 .addClass( 'cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--icon-only mw-mmv-button mw-mmv-download-button' )
46 .prop( 'title', mw.msg( 'multimediaviewer-download-link' ) )
47 .append( $( '<span>' ).addClass( 'mw-mmv-icon' ) );
48
49 this.$next = $( '<button>' )
50 .prop( 'title', mw.msg( 'multimediaviewer-next-image-alt-text' ) )
51 .addClass( 'cdx-button cdx-button--icon-only cdx-button--size-large mw-mmv-button mw-mmv-next-image' )
52 .append( $( '<span>' ).addClass( 'mw-mmv-icon' ) );
53
54 this.$prev = $( '<button>' )
55 .prop( 'title', mw.msg( 'multimediaviewer-prev-image-alt-text' ) )
56 .addClass( 'cdx-button cdx-button--icon-only cdx-button--size-large mw-mmv-button mw-mmv-prev-image' )
57 .append( $( '<span>' ).addClass( 'mw-mmv-icon' ) );
58
59 this.$nav = this.$next
60 .add( this.$prev )
61 .hide();
62
63 this.$buttons = this.$close
64 .add( this.$download )
65 .add( this.$reuse )
66 .add( this.$fullscreen )
67 .add( this.$next )
68 .add( this.$prev );
69
70 this.$buttons.appendTo( this.$container );
71
72 $( document ).on( 'mmv-close', () => {
73 this.$nav.hide();
74 } );
75
76 this.$close.on( 'click', () => {
77 $container.trigger( $.Event( 'mmv-close' ) );
78 } );
79
80 this.$next.on( 'click', () => {
81 this.emit( 'next' );
82 } );
83
84 this.$prev.on( 'click', () => {
85 this.emit( 'prev' );
86 } );
87 }
88
89 /**
90 * Sets the top offset for the navigation buttons.
91 *
92 * @param {number} offset
93 */
94 setOffset( offset ) {
95 this.$nav.css( {
96 top: offset
97 } );
98 }
99
100 /**
101 * Registers listeners.
102 *
103 * @fires ReuseDialog#mmv-reuse-opened
104 * @fires ReuseDialog#mmv-reuse-closed
105 * @fires DownloadDialog#mmv-download-opened
106 * @fires DownloadDialog#mmv-download-closed
107 */
108 attach() {
109 this.$reuse.on( 'click.mmv-canvasButtons', ( e ) => {
110 $( document ).trigger( 'mmv-reuse-open', e );
111 return false;
112 } );
113 this.handleEvent( 'mmv-reuse-opened', () => this.$reuse.addClass( 'open' ) );
114 this.handleEvent( 'mmv-reuse-closed', () => this.$reuse.removeClass( 'open' ) );
115
116 this.$download.on( 'click.mmv-canvasButtons', ( e ) => {
117 $( document ).trigger( 'mmv-download-open', e );
118 return false;
119 } );
120 this.handleEvent( 'mmv-download-opened', () => this.$download.addClass( 'open' ) );
121 this.handleEvent( 'mmv-download-closed', () => this.$download.removeClass( 'open' ) );
122
123 this.$download
124 .add( this.$reuse )
125 .add( this.$close )
126 .add( this.$fullscreen );
127 }
128
129 /**
130 * Removes all UI things from the DOM, or hides them
131 */
132 unattach() {
133 super.unattach();
134
135 this.$download
136 .add( this.$reuse )
137 .add( this.$options )
138 .add( this.$close )
139 .add( this.$fullscreen )
140 .off( 'click.mmv-canvasButtons' );
141 }
142
143 /**
144 * @param {ImageModel} image
145 */
146 set( image ) {
147 this.$reuse.prop( 'href', image.descriptionUrl );
148 this.$download.prop( 'href', image.url );
149 }
150
151 empty() {
152 this.$reuse
153 .removeClass( 'open' )
154 .prop( 'href', null );
155 this.$download
156 .prop( 'href', null );
157 }
158 }
159
160 module.exports = CanvasButtons;