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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
( function( mw, $, oo ) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @protected
|
|
|
|
* Creates a new button on the metadata stripe.
|
|
|
|
* @param {string} cssClass CSS class name for the button
|
|
|
|
* @param {string} text HTML code for the button text
|
2014-04-01 19:02:33 +00:00
|
|
|
* @param {string} popupText HTML code for the popup text
|
2014-04-01 01:41:57 +00:00
|
|
|
*/
|
2014-04-01 19:02:33 +00:00
|
|
|
SBP.createButton = function ( cssClass, text, popupText ) {
|
2014-07-03 19:12:59 +00:00
|
|
|
var $button,
|
|
|
|
$label,
|
2014-06-27 20:56:14 +00:00
|
|
|
tooltipDelay = mw.config.get( 'wgMultimediaViewer' ).tooltipDelay;
|
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 );
|
|
|
|
|
|
|
|
if ( text ) {
|
2014-07-03 19:12:59 +00:00
|
|
|
$label = $( '<span>' ).addClass( 'mw-mmv-stripe-button-text' ).text( text );
|
|
|
|
$button.append( $label ).addClass( 'has-label' );
|
2014-06-27 20:56:14 +00:00
|
|
|
}
|
|
|
|
if ( popupText ) {
|
2014-07-03 19:12:59 +00:00
|
|
|
$button.prop( 'title', popupText ).tipsy( {
|
2014-10-03 09:15:28 +00:00
|
|
|
gravity: this.correctEW( 'se' ),
|
2014-05-31 00:18:12 +00:00
|
|
|
delayIn: tooltipDelay
|
|
|
|
} );
|
2014-06-27 20:56:14 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @protected
|
|
|
|
* Creates a button linking to the file description page.
|
|
|
|
*/
|
2014-04-02 00:07:51 +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
|
|
|
/**
|
|
|
|
* @protected
|
|
|
|
* Runs code for each button, similarly to $.each.
|
|
|
|
* @param {function(jQuery, string)} callback a function that will be called with each button
|
|
|
|
*/
|
|
|
|
SBP.eachButton = function ( callback ) {
|
|
|
|
var buttonName;
|
|
|
|
for ( buttonName in this.buttons ) {
|
|
|
|
callback( this.buttons[buttonName], buttonName );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @protected
|
|
|
|
* Updates the button linking to the file page.
|
|
|
|
* @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
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears listeners.
|
|
|
|
*/
|
|
|
|
SBP.unattach = function () {
|
2014-09-16 20:33:05 +00:00
|
|
|
mw.mmv.ui.Element.prototype.unattach.call( this );
|
2014-04-08 09:54:30 +00:00
|
|
|
|
|
|
|
this.clearTimer( 'feedbackTooltip.show' );
|
2014-06-27 19:45:45 +00:00
|
|
|
|
|
|
|
$.each( this.buttons, function ( name, $button ) {
|
2014-07-14 21:51:06 +00:00
|
|
|
// Tipsy's not enabled on every button
|
|
|
|
if ( $button.data( 'tipsy' ) ) {
|
|
|
|
$button.tipsy( 'hide' );
|
|
|
|
}
|
2014-06-27 19:45:45 +00:00
|
|
|
} );
|
2014-04-01 01:41:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mw.mmv.ui.StripeButtons = StripeButtons;
|
|
|
|
}( mediaWiki, jQuery, OO ) );
|