2014-02-04 23:44:36 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension MultimediaViewer.
|
|
|
|
*
|
|
|
|
* MultimediaViewer 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.
|
|
|
|
*
|
|
|
|
* MultimediaViewer 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 MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
( function ( mw, $, oo ) {
|
2014-03-28 00:10:04 +00:00
|
|
|
var CBP;
|
|
|
|
|
2014-02-04 23:44:36 +00:00
|
|
|
/**
|
2014-03-28 00:10:04 +00:00
|
|
|
* Represents the buttons which are displayed over the image - next, previous, close
|
|
|
|
* and fullscreen.
|
|
|
|
* @class mw.mmv.ui.CanvasButtons
|
2014-02-04 23:44:36 +00:00
|
|
|
* @extends mw.mmv.ui.Element
|
|
|
|
* @constructor
|
2014-02-19 17:38:55 +00:00
|
|
|
* @param {jQuery} $container The parent element we should put the buttons into.
|
|
|
|
* @param {jQuery} $closeButton The close button element from the parent class.
|
|
|
|
* @param {jQuery} $fullscreenButton The fullscreen button from the parent class.
|
2014-02-04 23:44:36 +00:00
|
|
|
*/
|
2014-03-28 00:10:04 +00:00
|
|
|
function CanvasButtons( $container, $closeButton, $fullscreenButton ) {
|
2014-05-31 00:18:12 +00:00
|
|
|
var buttons = this,
|
|
|
|
tooltipDelay = mw.config.get( 'wgMultimediaViewer').tooltipDelay;
|
2014-02-04 23:44:36 +00:00
|
|
|
|
|
|
|
mw.mmv.ui.Element.call( this, $container );
|
|
|
|
|
|
|
|
this.$close = $closeButton;
|
|
|
|
this.$fullscreen = $fullscreenButton;
|
|
|
|
|
2014-06-10 20:39:10 +00:00
|
|
|
this.$viewFile = $( '<div>' )
|
|
|
|
.text( ' ' )
|
|
|
|
.prop( 'title', mw.message( 'multimediaviewer-viewfile-link' ).text() )
|
2014-05-31 00:18:12 +00:00
|
|
|
.tipsy( {
|
|
|
|
delayIn: tooltipDelay,
|
|
|
|
gravity: this.isRTL() ? 'sw' : 'se'
|
|
|
|
} )
|
2014-06-10 20:39:10 +00:00
|
|
|
.addClass( 'mw-mmv-viewfile' )
|
|
|
|
.click( function () {
|
2014-06-19 01:21:51 +00:00
|
|
|
mw.mmv.actionLogger.log( 'view-original-file' );
|
2014-06-10 20:39:10 +00:00
|
|
|
$( document ).trigger( 'mmv-viewfile' );
|
|
|
|
} );
|
|
|
|
|
2014-02-04 23:44:36 +00:00
|
|
|
this.$next = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-next-image disabled' )
|
2014-02-04 23:44:36 +00:00
|
|
|
.html( ' ' );
|
|
|
|
|
|
|
|
this.$prev = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-prev-image disabled' )
|
2014-02-04 23:44:36 +00:00
|
|
|
.html( ' ' );
|
|
|
|
|
|
|
|
this.$nav = this.$next
|
|
|
|
.add( this.$prev );
|
|
|
|
|
|
|
|
this.$buttons = this.$close
|
|
|
|
.add( this.$fullscreen )
|
|
|
|
.add( this.$next )
|
2014-06-10 20:39:10 +00:00
|
|
|
.add( this.$prev )
|
|
|
|
.add( this.$viewFile );
|
2014-02-04 23:44:36 +00:00
|
|
|
|
|
|
|
this.$buttons.appendTo( this.$container );
|
|
|
|
|
2014-02-11 13:25:39 +00:00
|
|
|
$( document ).on( 'mmv-close', function () {
|
2014-02-04 23:44:36 +00:00
|
|
|
buttons.$nav.addClass( 'disabled' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.$close.click( function () {
|
|
|
|
$container.trigger( $.Event( 'mmv-close' ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.$next.click( function () {
|
|
|
|
$container.trigger( $.Event( 'mmv-next' ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.$prev.click( function () {
|
|
|
|
$container.trigger( $.Event( 'mmv-prev' ) );
|
|
|
|
} );
|
|
|
|
}
|
2014-03-28 00:10:04 +00:00
|
|
|
oo.inheritClass( CanvasButtons, mw.mmv.ui.Element );
|
|
|
|
CBP = CanvasButtons.prototype;
|
2014-02-04 23:44:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the top offset for the navigation buttons.
|
|
|
|
* @param {number} offset
|
|
|
|
*/
|
2014-03-28 00:10:04 +00:00
|
|
|
CBP.setOffset = function ( offset ) {
|
2014-02-04 23:44:36 +00:00
|
|
|
this.$nav.css( {
|
|
|
|
top: offset
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops the fading animation of the buttons and cancel any opacity value
|
|
|
|
*/
|
2014-03-28 00:10:04 +00:00
|
|
|
CBP.stopFade = function () {
|
2014-02-04 23:44:36 +00:00
|
|
|
this.$buttons
|
|
|
|
.stop( true )
|
2014-02-18 08:25:48 +00:00
|
|
|
.removeClass( 'hidden' )
|
2014-02-04 23:44:36 +00:00
|
|
|
.css( 'opacity', '' );
|
2014-02-18 08:25:48 +00:00
|
|
|
|
|
|
|
this.$container.trigger( $.Event( 'mmv-fade-stopped' ) );
|
2014-02-04 23:44:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggles buttons being disabled or not
|
|
|
|
* @param {boolean} showPrevButton
|
|
|
|
* @param {boolean} showNextButton
|
|
|
|
*/
|
2014-05-15 20:24:40 +00:00
|
|
|
CBP.toggle = function ( showPrevButton, showNextButton ) {
|
2014-02-04 23:44:36 +00:00
|
|
|
this.$next.toggleClass( 'disabled', !showPrevButton );
|
|
|
|
this.$prev.toggleClass( 'disabled', !showNextButton );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fades out the active buttons
|
|
|
|
*/
|
2014-03-28 00:10:04 +00:00
|
|
|
CBP.fadeOut = function () {
|
2014-02-04 23:44:36 +00:00
|
|
|
var buttons = this;
|
|
|
|
|
|
|
|
// We don't use animation chaining because delay() can't be stop()ed
|
|
|
|
this.buttonsFadeTimeout = setTimeout( function() {
|
2014-02-18 08:25:48 +00:00
|
|
|
buttons.$buttons.not( '.disabled' ).animate( { opacity: 0 }, 1000, 'swing',
|
|
|
|
function () {
|
|
|
|
buttons.$buttons.addClass( 'hidden' );
|
|
|
|
buttons.$container.trigger( $.Event( 'mmv-faded-out' ) );
|
|
|
|
} );
|
2014-02-04 23:44:36 +00:00
|
|
|
}, 1500 );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if any active buttons are currently hovered, given a position
|
|
|
|
* @param {number} x The horizontal coordinate of the position
|
|
|
|
* @param {number} y The vertical coordinate of the position
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-03-28 00:10:04 +00:00
|
|
|
CBP.isAnyActiveButtonHovered = function ( x, y ) {
|
2014-02-04 23:44:36 +00:00
|
|
|
// We don't use mouseenter/mouseleave events because content is subject
|
|
|
|
// to change underneath the cursor, eg. when entering fullscreen or
|
|
|
|
// when going prev/next (the button can disappear when reaching ends)
|
|
|
|
var hovered = false;
|
|
|
|
|
|
|
|
this.$buttons.not( '.disabled' ).each( function( idx, e ) {
|
|
|
|
var $e = $( e ),
|
|
|
|
offset = $e.offset();
|
|
|
|
|
|
|
|
if ( y >= offset.top
|
|
|
|
&& y <= offset.top + $e.height()
|
|
|
|
&& x >= offset.left
|
|
|
|
&& x <= offset.left + $e.width() ) {
|
|
|
|
hovered = true;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
return hovered;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reveals all active buttons and schedule a fade out if needed
|
|
|
|
*/
|
2014-03-28 00:10:04 +00:00
|
|
|
CBP.revealAndFade = function ( mousePosition ) {
|
2014-02-04 23:44:36 +00:00
|
|
|
if ( this.buttonsFadeTimeout ) {
|
|
|
|
clearTimeout( this.buttonsFadeTimeout );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop ongoing animations and make sure the buttons that need to be displayed are displayed
|
|
|
|
this.stopFade();
|
|
|
|
|
|
|
|
// mousePosition can be empty, for instance when we enter fullscreen and haven't
|
|
|
|
// recorded a real mousemove event yet
|
|
|
|
if ( !mousePosition
|
|
|
|
|| !this.isAnyActiveButtonHovered( mousePosition.x, mousePosition.y ) ) {
|
|
|
|
this.fadeOut();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-27 19:45:45 +00:00
|
|
|
/**
|
|
|
|
* Removes all UI things from the DOM, or hides them
|
|
|
|
*/
|
|
|
|
CBP.unattach = function () {
|
|
|
|
this.$viewFile.tipsy( 'hide' );
|
|
|
|
this.$close.tipsy( 'hide' );
|
|
|
|
this.$fullscreen.tipsy( 'hide' );
|
|
|
|
};
|
|
|
|
|
2014-03-28 00:10:04 +00:00
|
|
|
mw.mmv.ui.CanvasButtons = CanvasButtons;
|
2014-02-04 23:44:36 +00:00
|
|
|
}( mediaWiki, jQuery, OO ) );
|