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' );
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
( function () {
|
2014-04-01 01:41:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for buttons which are placed on the metadata stripe (the always visible part of the
|
|
|
|
* metadata panel).
|
|
|
|
*/
|
2023-05-20 12:38:59 +00:00
|
|
|
class StripeButtons extends UiElement {
|
|
|
|
/**
|
|
|
|
* @param {jQuery} $container the title block (.mw-mmv-title-contain) which wraps the buttons and all
|
|
|
|
* other title elements
|
|
|
|
*/
|
|
|
|
constructor( $container ) {
|
|
|
|
super( $container );
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* This holds the actual buttons.
|
|
|
|
*
|
|
|
|
* @property {Object.<string, jQuery>}
|
|
|
|
*/
|
|
|
|
this.buttons = {};
|
|
|
|
|
|
|
|
this.initDescriptionPageButton();
|
|
|
|
}
|
2014-04-01 01:41:57 +00:00
|
|
|
|
|
|
|
/**
|
2023-05-20 12:38:59 +00:00
|
|
|
* Creates a new button on the metadata stripe.
|
2020-06-26 10:21:04 +00:00
|
|
|
*
|
2023-05-20 12:38:59 +00:00
|
|
|
* @protected
|
|
|
|
* @param {string} cssClass CSS class name for the button
|
|
|
|
* @return {jQuery} Button
|
2014-04-01 01:41:57 +00:00
|
|
|
*/
|
2023-05-20 12:38:59 +00:00
|
|
|
createButton( cssClass ) {
|
|
|
|
// eslint-disable-next-line mediawiki/class-doc
|
|
|
|
return $( '<a>' )
|
|
|
|
.addClass( `mw-mmv-stripe-button empty ${cssClass}` )
|
|
|
|
// elements are right-floated so we use prepend instead of append to keep the order
|
|
|
|
.prependTo( this.$buttonContainer )
|
|
|
|
.attr( 'tabindex', '0' );
|
|
|
|
}
|
2014-05-31 00:18:12 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/**
|
|
|
|
* Creates a button linking to the file description page.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
initDescriptionPageButton() {
|
|
|
|
this.buttons.$descriptionPage = this.createButton(
|
|
|
|
'empty mw-mmv-description-page-button mw-ui-big mw-ui-button mw-ui-progressive'
|
|
|
|
);
|
|
|
|
}
|
2014-06-27 20:56:14 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/**
|
|
|
|
* Runs code for each button, similarly to $.each.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @param {function(jQuery, string)} callback a function that will be called with each button
|
|
|
|
*/
|
|
|
|
eachButton( callback ) {
|
|
|
|
let buttonName;
|
|
|
|
for ( buttonName in this.buttons ) {
|
|
|
|
callback( this.buttons[ buttonName ], buttonName );
|
|
|
|
}
|
|
|
|
}
|
2014-04-01 01:41:57 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
* @param {Image} imageInfo
|
|
|
|
* @param {Repo} repoInfo
|
|
|
|
*/
|
|
|
|
set( imageInfo, repoInfo ) {
|
|
|
|
this.eachButton( ( $button ) => {
|
|
|
|
$button.removeClass( 'empty' );
|
|
|
|
} );
|
2014-04-02 00:07:51 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
this.setDescriptionPageButton( imageInfo, repoInfo );
|
2014-04-01 01:41:57 +00:00
|
|
|
}
|
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/**
|
|
|
|
* Updates the button linking to the file page.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @param {Image} imageInfo
|
|
|
|
* @param {Repo} repoInfo
|
|
|
|
*/
|
|
|
|
setDescriptionPageButton( imageInfo, repoInfo ) {
|
|
|
|
const $button = this.buttons.$descriptionPage;
|
|
|
|
let isCommons = repoInfo.isCommons();
|
|
|
|
let descriptionUrl = imageInfo.descriptionUrl;
|
2014-04-02 00:07:51 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
if ( repoInfo.isLocal === false && imageInfo.pageID ) {
|
|
|
|
// The file has a local description page, override the description URL
|
|
|
|
descriptionUrl = imageInfo.title.getUrl();
|
|
|
|
isCommons = false;
|
|
|
|
}
|
2014-04-02 00:49:21 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
$button.text( mw.message( 'multimediaviewer-repository-local' ).text() )
|
|
|
|
.attr( 'href', descriptionUrl );
|
2014-04-02 00:49:21 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
$button.toggleClass( 'mw-mmv-repo-button-commons', isCommons );
|
|
|
|
}
|
2014-04-02 00:07:51 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
empty() {
|
|
|
|
this.eachButton( ( $button ) => {
|
|
|
|
$button.addClass( 'empty' );
|
|
|
|
} );
|
2014-04-01 01:41:57 +00:00
|
|
|
|
2023-05-20 12:38:59 +00:00
|
|
|
this.buttons.$descriptionPage.attr( { href: null, title: null, 'original-title': null } )
|
|
|
|
.removeClass( 'mw-mmv-repo-button-commons' );
|
|
|
|
}
|
|
|
|
}
|
2014-04-01 01:41:57 +00:00
|
|
|
|
2023-05-19 20:26:45 +00:00
|
|
|
module.exports = StripeButtons;
|
2018-11-12 16:33:24 +00:00
|
|
|
}() );
|