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/>.
|
|
|
|
*/
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
( function ( mw, $, oo ) {
|
2014-04-01 01:41:57 +00:00
|
|
|
var SBP;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class mw.mmv.ui.StripeButtons
|
|
|
|
* @extends mw.mmv.ui.Element
|
|
|
|
* Class for buttons which are placed on the metadata stripe (the always visible part of the
|
|
|
|
* metadata panel).
|
|
|
|
* @constructor
|
2014-06-27 20:56:14 +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
|
|
|
*/
|
2014-07-16 15:24:07 +00:00
|
|
|
function StripeButtons( $container ) {
|
2014-04-01 01:41:57 +00:00
|
|
|
mw.mmv.ui.Element.call( this, $container );
|
|
|
|
|
|
|
|
this.$buttonContainer = $( '<div>' )
|
|
|
|
.addClass( 'mw-mmv-stripe-button-container' )
|
|
|
|
.appendTo( $container );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This holds the actual buttons.
|
|
|
|
* @property {Object.<string, jQuery>}
|
|
|
|
*/
|
|
|
|
this.buttons = {};
|
|
|
|
|
2014-06-09 06:56:52 +00:00
|
|
|
this.initDescriptionPageButton();
|
2014-04-01 01:41:57 +00:00
|
|
|
}
|
|
|
|
oo.inheritClass( StripeButtons, mw.mmv.ui.Element );
|
|
|
|
SBP = StripeButtons.prototype;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new button on the metadata stripe.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
|
|
|
* @protected
|
2014-04-01 01:41:57 +00:00
|
|
|
* @param {string} cssClass CSS class name for the button
|
|
|
|
*/
|
2014-11-19 10:46:39 +00:00
|
|
|
SBP.createButton = function ( cssClass ) {
|
|
|
|
var $button;
|
2014-05-31 00:18:12 +00:00
|
|
|
|
2014-07-03 19:12:59 +00:00
|
|
|
$button = $( '<a>' )
|
2014-04-01 01:41:57 +00:00
|
|
|
.addClass( 'mw-mmv-stripe-button empty ' + cssClass )
|
|
|
|
// elements are right-floated so we use prepend instead of append to keep the order
|
2014-06-27 20:56:14 +00:00
|
|
|
.prependTo( this.$buttonContainer );
|
|
|
|
|
2014-07-03 19:12:59 +00:00
|
|
|
return $button;
|
2014-04-01 01:41:57 +00:00
|
|
|
};
|
|
|
|
|
2014-04-02 01:58:41 +00:00
|
|
|
/**
|
|
|
|
* Creates a button linking to the file description page.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
|
|
|
* @protected
|
2014-04-02 01:58:41 +00:00
|
|
|
*/
|
2015-01-23 12:48:27 +00:00
|
|
|
SBP.initDescriptionPageButton = function () {
|
2014-07-16 14:42:17 +00:00
|
|
|
this.buttons.$descriptionPage = this.createButton(
|
2014-09-05 18:50:33 +00:00
|
|
|
'empty mw-mmv-description-page-button mw-ui-big mw-ui-button mw-ui-progressive'
|
2014-07-16 14:42:17 +00:00
|
|
|
).click( function () {
|
|
|
|
mw.mmv.actionLogger.log( 'file-description-page-abovefold' );
|
|
|
|
} );
|
2014-04-02 00:07:51 +00:00
|
|
|
};
|
|
|
|
|
2014-04-01 01:41:57 +00:00
|
|
|
/**
|
|
|
|
* Runs code for each button, similarly to $.each.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
|
|
|
* @protected
|
2014-04-01 01:41:57 +00:00
|
|
|
* @param {function(jQuery, string)} callback a function that will be called with each button
|
|
|
|
*/
|
2015-01-23 12:48:27 +00:00
|
|
|
SBP.eachButton = function ( callback ) {
|
2014-04-01 01:41:57 +00:00
|
|
|
var buttonName;
|
|
|
|
for ( buttonName in this.buttons ) {
|
2016-07-18 13:49:27 +00:00
|
|
|
callback( this.buttons[ buttonName ], buttonName );
|
2014-04-01 01:41:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
2014-04-02 00:07:51 +00:00
|
|
|
* @param {mw.mmv.model.Image} imageInfo
|
|
|
|
* @param {mw.mmv.model.Repo} repoInfo
|
2014-04-01 01:41:57 +00:00
|
|
|
*/
|
2014-04-02 00:07:51 +00:00
|
|
|
SBP.set = function ( imageInfo, repoInfo ) {
|
2014-04-01 01:41:57 +00:00
|
|
|
this.eachButton( function ( $button ) {
|
|
|
|
$button.removeClass( 'empty' );
|
|
|
|
} );
|
2014-04-02 00:07:51 +00:00
|
|
|
|
2014-06-09 06:56:52 +00:00
|
|
|
this.setDescriptionPageButton( imageInfo, repoInfo );
|
2014-04-02 00:49:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the button linking to the file page.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
|
|
|
* @protected
|
2014-04-02 00:49:21 +00:00
|
|
|
* @param {mw.mmv.model.Image} imageInfo
|
|
|
|
* @param {mw.mmv.model.Repo} repoInfo
|
|
|
|
*/
|
|
|
|
SBP.setDescriptionPageButton = function ( imageInfo, repoInfo ) {
|
2014-09-05 18:50:33 +00:00
|
|
|
var $button = this.buttons.$descriptionPage;
|
2014-04-02 00:49:21 +00:00
|
|
|
|
2014-09-05 18:50:33 +00:00
|
|
|
$button.text( mw.message( 'multimediaviewer-repository-local' ).text() )
|
|
|
|
.attr( 'href', imageInfo.descriptionUrl );
|
2014-04-02 00:07:51 +00:00
|
|
|
|
2014-09-05 18:50:33 +00:00
|
|
|
$button.toggleClass( 'mw-mmv-repo-button-commons', repoInfo.isCommons() );
|
2014-04-01 01:41:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
SBP.empty = function () {
|
|
|
|
this.eachButton( function ( $button ) {
|
2014-04-02 00:07:51 +00:00
|
|
|
$button.addClass( 'empty' );
|
2014-04-01 01:41:57 +00:00
|
|
|
} );
|
2014-04-02 00:07:51 +00:00
|
|
|
|
2014-06-09 06:56:52 +00:00
|
|
|
this.buttons.$descriptionPage.attr( { href: null, title: null, 'original-title': null } )
|
2014-09-05 18:50:33 +00:00
|
|
|
.removeClass( 'mw-mmv-repo-button-commons' );
|
2014-04-01 01:41:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mw.mmv.ui.StripeButtons = StripeButtons;
|
|
|
|
}( mediaWiki, jQuery, OO ) );
|