| 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 HtmlUtils = require( '../mmv.HtmlUtils.js' ); |
| 19 | const UiElement = require( './mmv.ui.js' ); |
| 20 | |
| 21 | /** |
| 22 | * Description element in the UI. |
| 23 | */ |
| 24 | class Description extends UiElement { |
| 25 | constructor( $container ) { |
| 26 | super( $container ); |
| 27 | |
| 28 | this.$imageDescDiv = $( '<div>' ) |
| 29 | .addClass( 'mw-mmv-image-desc-div empty' ) |
| 30 | .appendTo( this.$container ); |
| 31 | |
| 32 | this.$imageDesc = $( '<p>' ) |
| 33 | .addClass( 'mw-mmv-image-desc' ) |
| 34 | .appendTo( this.$imageDescDiv ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Sets data on the element. |
| 39 | * This complements MetadataPanel.setTitle() - information shown there will not be shown here. |
| 40 | * |
| 41 | * @param {string|null} description The text of the description |
| 42 | * @param {string|null} caption The text of the caption |
| 43 | */ |
| 44 | set( description, caption ) { |
| 45 | if ( caption && description ) { // panel header shows the caption - show description here |
| 46 | this.$imageDesc.html( HtmlUtils.htmlToTextWithTags( description ) ); |
| 47 | this.$imageDescDiv.removeClass( 'empty' ); |
| 48 | } else { // either there is no description or the paner header already shows it - nothing to do here |
| 49 | this.empty(); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @inheritdoc |
| 55 | */ |
| 56 | empty() { |
| 57 | this.$imageDesc.empty(); |
| 58 | this.$imageDescDiv.addClass( 'empty' ); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | module.exports = Description; |