2014-04-01 01:41:57 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension MediaViewer.
|
|
|
|
*
|
|
|
|
* MediaViewer is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MediaViewer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-05-19 20:26:45 +00:00
|
|
|
const UiElement = require( './mmv.ui.js' );
|
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* Class for buttons which are placed on the metadata stripe (the always visible part of the
|
|
|
|
* metadata panel).
|
|
|
|
*/
|
|
|
|
class StripeButtons extends UiElement {
|
2014-04-01 01:41:57 +00:00
|
|
|
/**
|
2024-05-21 20:12:08 +00:00
|
|
|
* @param {jQuery} $container the title block (.mw-mmv-title-contain) which wraps the buttons and all
|
|
|
|
* other title elements
|
2014-04-01 01:41:57 +00:00
|
|
|
*/
|
2024-05-21 20:12:08 +00:00
|
|
|
constructor( $container ) {
|
|
|
|
super( $container );
|
2014-04-01 01:41:57 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
this.$buttonContainer = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-stripe-button-container' )
|
|
|
|
.appendTo( $container );
|
2014-04-01 01:41:57 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/**
|
2024-05-29 08:54:16 +00:00
|
|
|
* A button linking to the file description page.
|
2023-05-20 12:38:59 +00:00
|
|
|
*/
|
2024-05-29 08:54:16 +00:00
|
|
|
this.$descriptionPage = $( '<a>' )
|
2024-05-21 20:12:08 +00:00
|
|
|
.addClass( 'mw-mmv-stripe-button empty mw-mmv-description-page-button cdx-button cdx-button--weight-primary cdx-button--action-progressive cdx-button--size-large cdx-button--fake-button cdx-button--fake-button--enabled' )
|
|
|
|
// elements are right-floated so we use prepend instead of append to keep the order
|
|
|
|
.prependTo( this.$buttonContainer );
|
|
|
|
}
|
2014-04-02 00:07:51 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
2024-05-29 08:54:16 +00:00
|
|
|
* @param {ImageModel} imageInfo
|
2024-05-21 20:12:08 +00:00
|
|
|
*/
|
2024-05-29 08:54:16 +00:00
|
|
|
set( imageInfo ) {
|
2024-05-21 20:12:08 +00:00
|
|
|
let descriptionUrl = imageInfo.descriptionUrl;
|
2024-05-29 08:54:16 +00:00
|
|
|
let isCommons = String( descriptionUrl ).includes( '//commons.wikimedia.org/' );
|
2024-05-21 20:12:08 +00:00
|
|
|
|
2024-05-29 08:54:16 +00:00
|
|
|
if ( imageInfo.pageID ) {
|
2024-05-21 20:12:08 +00:00
|
|
|
// The file has a local description page, override the description URL
|
|
|
|
descriptionUrl = imageInfo.title.getUrl();
|
|
|
|
isCommons = false;
|
2023-05-20 12:38:59 +00:00
|
|
|
}
|
2024-05-21 20:12:08 +00:00
|
|
|
|
2024-05-29 08:54:16 +00:00
|
|
|
this.$descriptionPage.empty()
|
2024-05-21 20:12:08 +00:00
|
|
|
.append( $( '<span>' ).addClass( 'cdx-button__icon' ) )
|
2024-05-28 18:04:50 +00:00
|
|
|
.append( mw.msg( 'multimediaviewer-repository-local' ) )
|
2024-05-29 08:54:16 +00:00
|
|
|
.attr( 'href', descriptionUrl )
|
|
|
|
.removeClass( 'empty' )
|
|
|
|
.toggleClass( 'mw-mmv-repo-button-commons', isCommons );
|
2024-05-21 20:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
empty() {
|
2024-05-29 08:54:16 +00:00
|
|
|
this.$descriptionPage.attr( { href: null, title: null, 'original-title': null } )
|
|
|
|
.addClass( 'empty' )
|
2024-05-21 20:12:08 +00:00
|
|
|
.removeClass( 'mw-mmv-repo-button-commons' );
|
2023-05-20 12:38:59 +00:00
|
|
|
}
|
2024-05-21 20:12:08 +00:00
|
|
|
}
|
2014-04-01 01:41:57 +00:00
|
|
|
|
2024-05-21 20:12:08 +00:00
|
|
|
module.exports = StripeButtons;
|