2020-11-18 09:11:12 +00:00
|
|
|
/**
|
|
|
|
* Module containing presentation logic for the arrow buttons
|
|
|
|
*
|
|
|
|
* @class SliderArroView
|
|
|
|
* @param {SliderView} sliderView
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function SliderArrowView( sliderView ) {
|
|
|
|
this.sliderView = sliderView;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.extend( SliderArrowView.prototype, {
|
2017-03-24 13:48:57 +00:00
|
|
|
/**
|
2020-11-18 09:11:12 +00:00
|
|
|
* @type {SliderView}
|
|
|
|
*/
|
|
|
|
sliderView: null,
|
|
|
|
|
|
|
|
/**
|
2024-01-27 12:16:52 +00:00
|
|
|
* @param {number} direction -1 or 1
|
2020-11-18 09:11:12 +00:00
|
|
|
* @return {OO.ui.ButtonWidget}
|
2017-03-24 13:48:57 +00:00
|
|
|
*/
|
2024-01-27 12:16:52 +00:00
|
|
|
renderArrowButton: function ( direction ) {
|
|
|
|
const prev = direction < 0;
|
|
|
|
const button = new OO.ui.ButtonWidget( {
|
|
|
|
icon: prev ? 'previous' : 'next',
|
2020-11-18 09:11:12 +00:00
|
|
|
width: 20,
|
|
|
|
height: 140,
|
|
|
|
framed: true,
|
2024-01-27 12:16:52 +00:00
|
|
|
classes: [
|
|
|
|
'mw-revslider-arrow',
|
|
|
|
prev ? 'mw-revslider-arrow-backwards' : 'mw-revslider-arrow-forwards'
|
|
|
|
]
|
2020-11-18 09:11:12 +00:00
|
|
|
} );
|
|
|
|
|
2024-01-27 12:16:52 +00:00
|
|
|
const tooltip = mw.msg( prev ? 'revisionslider-arrow-tooltip-older' : 'revisionslider-arrow-tooltip-newer' );
|
|
|
|
const popup = new OO.ui.PopupWidget( {
|
|
|
|
$content: $( '<p>' ).text( tooltip ),
|
|
|
|
$floatableContainer: button.$element,
|
2020-11-18 09:11:12 +00:00
|
|
|
width: 200,
|
|
|
|
classes: [ 'mw-revslider-tooltip', 'mw-revslider-arrow-tooltip' ]
|
|
|
|
} );
|
|
|
|
|
2024-01-27 12:16:52 +00:00
|
|
|
button.connect( this, { click: [ 'arrowClickHandler', button ] } );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
2024-01-27 12:16:52 +00:00
|
|
|
button.$element
|
|
|
|
.attr( 'data-dir', direction )
|
|
|
|
.children().attr( 'aria-label', tooltip )
|
|
|
|
.on( 'mouseover', { button: button, popup: popup }, this.showPopup )
|
|
|
|
.on( 'mouseout', { popup: popup }, this.hidePopup )
|
|
|
|
.on( 'focusin', { button: button }, this.arrowFocusHandler );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
2024-01-27 12:16:52 +00:00
|
|
|
$( document.body ).append( popup.$element );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
2024-01-27 12:16:52 +00:00
|
|
|
return button;
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
showPopup: function ( e ) {
|
2024-01-27 12:16:52 +00:00
|
|
|
if ( e.data.button.isDisabled() ) {
|
2020-11-18 09:11:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-01-27 12:16:52 +00:00
|
|
|
|
|
|
|
const $button = $( this );
|
|
|
|
const popup = e.data.popup;
|
2020-11-18 09:11:12 +00:00
|
|
|
popup.$element.css( {
|
2024-01-27 12:16:52 +00:00
|
|
|
left: $button.offset().left + $button.outerWidth() / 2 + 'px',
|
|
|
|
top: $button.offset().top + $button.outerHeight() + 'px'
|
2020-11-18 09:11:12 +00:00
|
|
|
} );
|
|
|
|
popup.toggle( true );
|
|
|
|
},
|
|
|
|
|
|
|
|
hidePopup: function ( e ) {
|
2024-01-27 12:16:52 +00:00
|
|
|
e.data.popup.toggle( false );
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {OO.ui.ButtonWidget} button
|
|
|
|
*/
|
|
|
|
arrowClickHandler: function ( button ) {
|
|
|
|
if ( button.isDisabled() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mw.track( 'counter.MediaWiki.RevisionSlider.event.arrowClick' );
|
2024-02-21 12:56:44 +00:00
|
|
|
this.sliderView.slideView( button.$element.attr( 'data-dir' ) );
|
2020-11-18 09:11:12 +00:00
|
|
|
},
|
2017-03-24 13:48:57 +00:00
|
|
|
|
2020-01-24 16:21:23 +00:00
|
|
|
/**
|
2020-11-18 09:11:12 +00:00
|
|
|
* Disabled oo.ui.ButtonWidgets get focused when clicked. In particular cases
|
|
|
|
* (arrow gets clicked when disabled, none other elements gets focus meanwhile, the other arrow is clicked)
|
|
|
|
* previously disabled arrow button still has focus and has OOUI focused button styles
|
|
|
|
* applied (blue border) which is not what is wanted. And generally setting a focus on disabled
|
|
|
|
* buttons does not seem right in case of RevisionSlider's arrow buttons.
|
|
|
|
* This method removes focus from the disabled button if such case happens.
|
|
|
|
*
|
2023-10-24 13:45:31 +00:00
|
|
|
* @private
|
2020-11-18 09:11:12 +00:00
|
|
|
* @param {jQuery.Event} e
|
2020-01-24 16:21:23 +00:00
|
|
|
*/
|
2020-11-18 09:11:12 +00:00
|
|
|
arrowFocusHandler: function ( e ) {
|
2023-06-22 09:41:37 +00:00
|
|
|
const button = e.data.button;
|
2020-11-18 09:11:12 +00:00
|
|
|
if ( button.isDisabled() ) {
|
|
|
|
button.$element.find( 'a.oo-ui-buttonElement-button' ).trigger( 'blur' );
|
2017-03-24 13:48:57 +00:00
|
|
|
}
|
2020-11-18 09:11:12 +00:00
|
|
|
}
|
|
|
|
} );
|
2017-03-24 13:48:57 +00:00
|
|
|
|
2020-03-29 20:36:10 +00:00
|
|
|
module.exports = SliderArrowView;
|