mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2025-01-08 11:54:14 +00:00
8e7fe2434d
First I jumped on replacing both jscs and jshint with eslint but it might be premature decision. Although linting with eslint is possible (like in there is wikimedia config for eslint) it is still not clear should it But in case the change happens we will be ready. Apart from config stuff this changes few bits spotted by eslint: improves some indentation, removes weird spaces, completes some doc blocks, changes IIFE forms in tests. These changes do not seem controversial. Change-Id: I9f8bf0f5745da8e662685f4cd879ea4baa609c01
179 lines
5.1 KiB
JavaScript
179 lines
5.1 KiB
JavaScript
( function ( mw, $ ) {
|
|
/* eslint-disable dot-notation */
|
|
// JSHint does not like OOJS' usage of "static" and "super"
|
|
/* jshint -W024 */
|
|
|
|
/**
|
|
* Module containing the RevisionSlider tutorial
|
|
*
|
|
* @param {Object} config
|
|
* @constructor
|
|
*/
|
|
var HelpDialog = function ( config ) {
|
|
HelpDialog.super.call( this, config );
|
|
};
|
|
|
|
OO.inheritClass( HelpDialog, OO.ui.ProcessDialog );
|
|
|
|
HelpDialog.static.title = mw.msg( 'revisionslider-tutorial' );
|
|
HelpDialog.static.actions = [
|
|
{
|
|
action: 'next',
|
|
label: mw.msg( 'revisionslider-next-dialog' ),
|
|
flags: [ 'primary', 'progressive' ],
|
|
modes: [ 'initial', 'middle' ],
|
|
classes: [ 'revisionslider-help-next' ]
|
|
},
|
|
{ action: 'previous', flags: 'safe', label: mw.msg( 'revisionslider-previous-dialog' ), modes: [ 'middle', 'last' ], classes: [ 'revisionslider-help-previous' ] },
|
|
{ label: mw.msg( 'revisionslider-close-dialog' ), flags: 'safe', modes: 'initial', classes: [ 'revisionslider-help-close-start' ] },
|
|
{ label: mw.msg( 'revisionslider-close-dialog' ), flags: 'primary', modes: 'last', classes: [ 'revisionslider-help-close-end' ] }
|
|
];
|
|
|
|
$.extend( HelpDialog.prototype, {
|
|
/**
|
|
* @type {OO.ui.PanelLayout[]}
|
|
*/
|
|
slides: [],
|
|
|
|
/**
|
|
* @type {number}
|
|
*/
|
|
slidePointer: 0,
|
|
|
|
initialize: function () {
|
|
HelpDialog.super.prototype.initialize.call( this );
|
|
|
|
this.slides = [ this.getSlide1(), this.getSlide2(), this.getSlide3(), this.getSlide4() ];
|
|
|
|
this.stackLayout = new OO.ui.StackLayout( {
|
|
items: this.slides
|
|
} );
|
|
|
|
this.$body.append( this.stackLayout.$element );
|
|
},
|
|
|
|
/**
|
|
* @return {OO.ui.PanelLayout}
|
|
*/
|
|
getSlide1: function () {
|
|
var slide = new OO.ui.PanelLayout( { $: this.$, padded: true, expanded: false } );
|
|
|
|
slide.$element
|
|
.append(
|
|
$( '<div>' ).addClass( 'mw-revslider-help-dialog-image-landscape mw-revslider-help-dialog-slide-1' )
|
|
)
|
|
.append(
|
|
$( '<p>' ).addClass( 'mw-revslider-help-dialog-text' )
|
|
.html( mw.message( 'revisionslider-help-dialog-slide1' ).parse() )
|
|
);
|
|
|
|
slide.$element.find( 'a' ).attr( 'target', '_blank' );
|
|
|
|
return slide;
|
|
},
|
|
|
|
/**
|
|
* @return {OO.ui.PanelLayout}
|
|
*/
|
|
getSlide2: function () {
|
|
var slide = new OO.ui.PanelLayout( { $: this.$, padded: true, expanded: false } );
|
|
|
|
slide.$element
|
|
.append( $( '<div>' ).addClass( 'mw-revslider-help-dialog-image-landscape mw-revslider-help-dialog-slide-2' ) )
|
|
.append(
|
|
$( '<p>' ).addClass( 'mw-revslider-help-dialog-text' )
|
|
.text( mw.msg( 'revisionslider-help-dialog-slide2' ) )
|
|
);
|
|
|
|
return slide;
|
|
},
|
|
|
|
/**
|
|
* @return {OO.ui.PanelLayout}
|
|
*/
|
|
getSlide3: function () {
|
|
var slide = new OO.ui.PanelLayout( { $: this.$, padded: true, expanded: false } );
|
|
|
|
slide.$element
|
|
.append( $( '<div>' ).addClass( 'mw-revslider-help-dialog-image-portrait mw-revslider-help-dialog-slide-3 mw-revslider-column-image' ) )
|
|
.append(
|
|
$( '<div>' ).addClass( 'mw-revslider-column-text mw-revslider-help-dialog-text' )
|
|
.html( mw.message( 'revisionslider-help-dialog-slide3' ).parse() )
|
|
)
|
|
.append( $( '<div>' ).css( 'clear', 'both' ) );
|
|
|
|
return slide;
|
|
},
|
|
|
|
/**
|
|
* @return {OO.ui.PanelLayout}
|
|
*/
|
|
getSlide4: function () {
|
|
var slide = new OO.ui.PanelLayout( { $: this.$, padded: true, expanded: false } );
|
|
|
|
slide.$element
|
|
.append( $( '<div>' ).addClass( 'mw-revslider-help-dialog-image-landscape mw-revslider-help-dialog-slide-4' ) )
|
|
.append(
|
|
$( '<p>' ).addClass( 'mw-revslider-help-dialog-text' )
|
|
.text( mw.msg( 'revisionslider-help-dialog-slide4' ) )
|
|
);
|
|
|
|
return slide;
|
|
},
|
|
|
|
/**
|
|
* @param {string} action
|
|
* @return {OO.ui.Process}
|
|
*/
|
|
getActionProcess: function ( action ) {
|
|
if ( action === 'next' ) {
|
|
this.stackLayout.setItem( this.slides[ ++this.slidePointer ] );
|
|
} else if ( action === 'previous' ) {
|
|
this.stackLayout.setItem( this.slides[ --this.slidePointer ] );
|
|
}
|
|
|
|
if ( this.slidePointer === 0 ) {
|
|
this.actions.setMode( 'initial' );
|
|
} else if ( this.slidePointer === this.slides.length - 1 ) {
|
|
this.actions.setMode( 'last' );
|
|
} else {
|
|
this.actions.setMode( 'middle' );
|
|
}
|
|
|
|
this.stackLayout.$element.closest( '.oo-ui-window-frame' ).css( 'height', this.getContentHeight() + 'px' );
|
|
return HelpDialog.super.prototype.getActionProcess.call( this, action );
|
|
},
|
|
|
|
getSetupProcess: function ( data ) {
|
|
return HelpDialog.super.prototype.getSetupProcess.call( this, data )
|
|
.next( function () {
|
|
this.actions.setMode( 'initial' );
|
|
}, this );
|
|
},
|
|
|
|
/**
|
|
* Needed to set the initial height of the dialog
|
|
*
|
|
* @return {number}
|
|
*/
|
|
getBodyHeight: function () {
|
|
return this.slides[ this.slidePointer ].$element.outerHeight( true );
|
|
}
|
|
} );
|
|
|
|
/**
|
|
* Shows the help dialog
|
|
*/
|
|
HelpDialog.show = function () {
|
|
var windowManager = new OO.ui.WindowManager(),
|
|
dialogue = new HelpDialog( { size: 'medium', classes: [ 'revisionslider-help-dialog' ] } );
|
|
|
|
$( 'body' ).append( windowManager.$element );
|
|
windowManager.addWindows( [ dialogue ] );
|
|
windowManager.openWindow( dialogue );
|
|
};
|
|
|
|
mw.libs.revisionSlider = mw.libs.revisionSlider || {};
|
|
mw.libs.revisionSlider.HelpDialog = HelpDialog;
|
|
}( mediaWiki, jQuery ) );
|