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 = {};
|
|
|
|
|
|
|
|
this.initReuseButton();
|
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-05-31 00:18:12 +00:00
|
|
|
gravity: $( document.body ).hasClass( 'rtl' ) ? 'sw' : 'se',
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @protected
|
|
|
|
* Creates the reuse button.
|
|
|
|
*/
|
|
|
|
SBP.initReuseButton = function() {
|
|
|
|
this.buttons.$reuse = this.createButton(
|
|
|
|
'mw-mmv-stripe-button-reuse',
|
|
|
|
mw.message( 'multimediaviewer-reuse-link' ).text()
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
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(
|
|
|
|
'empty',
|
|
|
|
null,
|
|
|
|
mw.message( 'multimediaviewer-description-page-button-text' ).plain()
|
|
|
|
).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 ) {
|
|
|
|
var descPagePopupMessage;
|
|
|
|
|
2014-04-02 00:07:51 +00:00
|
|
|
descPagePopupMessage = repoInfo.isLocal
|
2014-04-04 19:02:36 +00:00
|
|
|
? mw.message( 'multimediaviewer-description-page-button-text' ).plain()
|
2014-05-01 00:04:09 +00:00
|
|
|
: mw.message( 'multimediaviewer-description-page-popup-text', repoInfo.displayName ).text();
|
2014-04-02 00:07:51 +00:00
|
|
|
|
2014-04-02 00:39:54 +00:00
|
|
|
this.buttons.$descriptionPage.attr( {
|
2014-04-02 00:07:51 +00:00
|
|
|
href: imageInfo.descriptionUrl,
|
2014-04-02 00:39:54 +00:00
|
|
|
title: descPagePopupMessage,
|
|
|
|
'original-title': descPagePopupMessage // needed by jquery.tipsy
|
2014-04-02 00:07:51 +00:00
|
|
|
} );
|
|
|
|
|
2014-06-02 21:24:32 +00:00
|
|
|
if ( repoInfo.isCommons() ) {
|
2014-06-27 20:56:14 +00:00
|
|
|
this.buttons.$descriptionPage.addClass( 'mw-mmv-repo-button-commons' );
|
2014-04-02 00:07:51 +00:00
|
|
|
} else {
|
2014-06-27 20:56:14 +00:00
|
|
|
this.buttons.$descriptionPage.addClass( 'mw-mmv-repo-button-dynamic' );
|
2014-04-10 19:09:28 +00:00
|
|
|
if ( repoInfo.favIcon ) {
|
2014-06-27 20:56:14 +00:00
|
|
|
this.setInlineStyle( 'repo-button-description-page',
|
2014-04-10 19:09:28 +00:00
|
|
|
// needs to be more specific then the fallback rule in stripeButtons.less
|
2014-07-16 14:42:17 +00:00
|
|
|
'html .mw-mmv-repo-button-dynamic:before {' +
|
2014-04-10 19:09:28 +00:00
|
|
|
'background-image: url("' + repoInfo.favIcon + '");' +
|
|
|
|
'}'
|
|
|
|
);
|
|
|
|
}
|
2014-04-02 00:07:51 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
this.buttons.$reuse.removeClass( 'open' );
|
2014-06-09 06:56:52 +00:00
|
|
|
|
|
|
|
this.buttons.$descriptionPage.attr( { href: null, title: null, 'original-title': null } )
|
2014-06-27 20:56:14 +00:00
|
|
|
.removeClass( 'mw-mmv-repo-button-dynamic mw-mmv-repo-button-commons' );
|
|
|
|
this.setInlineStyle( 'repo-button-description-page', null );
|
2014-04-01 01:41:57 +00:00
|
|
|
};
|
|
|
|
|
2014-04-02 01:58:41 +00:00
|
|
|
/**
|
|
|
|
* @event mmv-reuse-open
|
|
|
|
* Fired when the buttonto open the reuse dialog is clicked.
|
|
|
|
*/
|
2014-04-01 01:41:57 +00:00
|
|
|
/**
|
|
|
|
* Registers listeners.
|
|
|
|
*/
|
|
|
|
SBP.attach = function () {
|
|
|
|
var buttons = this.buttons;
|
|
|
|
|
|
|
|
buttons.$reuse.on( 'click.mmv-stripeButtons', function ( e ) {
|
|
|
|
$( document ).trigger( 'mmv-reuse-open' );
|
|
|
|
e.stopPropagation(); // the dialog would take it as an outside click and close
|
|
|
|
} );
|
|
|
|
this.handleEvent( 'mmv-reuse-opened', function () {
|
|
|
|
buttons.$reuse.addClass( 'open' );
|
|
|
|
} );
|
|
|
|
this.handleEvent( 'mmv-reuse-closed', function () {
|
|
|
|
buttons.$reuse.removeClass( 'open' );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears listeners.
|
|
|
|
*/
|
|
|
|
SBP.unattach = function () {
|
2014-04-07 17:37:42 +00:00
|
|
|
this.constructor['super'].prototype.unattach.call( this );
|
2014-04-01 01:41:57 +00:00
|
|
|
this.buttons.$reuse.off( 'click.mmv-stripeButtons' );
|
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 ) );
|