| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
const UiElement = require( './mmv.ui.js' ); |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
class CanvasButtons extends UiElement { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 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 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
setOffset( offset ) { |
| 95 |
this.$nav.css( { |
| 96 |
top: offset |
| 97 |
} ); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 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 |
|
| 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 |
|
| 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; |