| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
const HtmlUtils = require( '../mmv.HtmlUtils.js' ); |
| 19 |
const UiElement = require( './mmv.ui.js' ); |
| 20 |
const MetadataPanelScroller = require( './mmv.ui.metadataPanelScroller.js' ); |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
class Permission extends UiElement { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
constructor( $container, scroller ) { |
| 34 |
super( $container ); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
this.$box = $( '<div>' ) |
| 42 |
.addClass( 'mw-mmv-permission-box mw-mmv-info-box empty' ) |
| 43 |
.appendTo( this.$container ); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
this.$title = $( '<h3>' ) |
| 51 |
.text( mw.msg( 'multimediaviewer-permission-title' ) ) |
| 52 |
.appendTo( this.$box ); |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
this.$text = $( '<div>' ) |
| 62 |
.addClass( 'mw-mmv-permission-text' ) |
| 63 |
.appendTo( this.$box ) |
| 64 |
.on( 'click', '.mw-mmv-permission-text-viewmore', ( e ) => { |
| 65 |
e.preventDefault(); |
| 66 |
this.grow(); |
| 67 |
this.scroller.toggle( 'up' ); |
| 68 |
} ); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
this.$fader = $( '<div>' ) |
| 76 |
.addClass( 'mw-mmv-permission-text-fader' ) |
| 77 |
.append( |
| 78 |
$( '<a>' ) |
| 79 |
.addClass( 'mw-mmv-permission-text-viewmore' ) |
| 80 |
.prop( 'href', '#' ) |
| 81 |
.text( mw.msg( 'multimediaviewer-permission-viewmore' ) ) |
| 82 |
); |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
this.$html = $( '<div>' ) |
| 91 |
.addClass( 'mw-mmv-permission-html' ) |
| 92 |
.appendTo( this.$box ); |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
this.$close = $( '<button>' ) |
| 100 |
.addClass( 'mw-mmv-permission-close' ) |
| 101 |
.on( 'click', () => { |
| 102 |
this.shrink(); |
| 103 |
} ) |
| 104 |
.appendTo( this.$box ); |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
this.scroller = scroller; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
empty() { |
| 118 |
this.$box.addClass( 'empty' ); |
| 119 |
this.$text.empty(); |
| 120 |
this.$html.empty(); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
set( permission ) { |
| 129 |
this.$box.removeClass( 'empty' ); |
| 130 |
|
| 131 |
this.$text.html( HtmlUtils.htmlToTextWithLinks( permission ) ); |
| 132 |
this.$text.append( this.$fader ); |
| 133 |
|
| 134 |
this.$html.html( permission ); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
grow() { |
| 147 |
this.$box.addClass( 'full-size' ); |
| 148 |
this.$container.trigger( 'mmv-permission-grow' ); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
shrink() { |
| 161 |
this.$box.removeClass( 'full-size' ); |
| 162 |
this.$container.trigger( 'mmv-permission-shrink' ); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
isFullSize() { |
| 171 |
return this.$box.hasClass( 'full-size' ); |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
module.exports = Permission; |