/* * This file is part of the MediaWiki extension UploadWizard. * * UploadWizard 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. * * UploadWizard 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 UploadWizard. If not, see . */ ( function ( mw, $, uw, OO ) { /** * Represents a generic UI for a step. * * @class uw.ui.Step * @mixins OO.EventEmitter * @constructor * @param {string} name The name of this step */ uw.ui.Step = function UWUIStep( name ) { OO.EventEmitter.call( this ); this.name = name; this.$buttons = $( '
' ).addClass( 'mwe-upwiz-buttons' ); this.$div = $( '
' ) .attr( 'id', 'mwe-upwiz-stepdiv-' + this.name ) .addClass( 'mwe-upwiz-stepdiv' ) .hide(); $( '#mwe-upwiz-content' ).append( this.$div ); this.$arrow = $( '
  • ' ) .attr( 'id', 'mwe-upwiz-step-' + this.name ) .append( $( '
    ' ).text( mw.message( 'mwe-upwiz-step-' + this.name ).text() ) ); $( '#mwe-upwiz-steps' ).append( this.$arrow ); // this will make sure that buttons will only be added if they've been // set in the controller, otherwise there's nowhere to go... this.nextButtonPromise = $.Deferred(); this.previousButtonPromise = $.Deferred(); }; OO.mixinClass( uw.ui.Step, OO.EventEmitter ); /** * Initialize this step. * * @param {mw.UploadWizardUpload[]} uploads */ uw.ui.Step.prototype.load = function ( uploads ) { var offset = $( 'h1:first' ).offset(); this.movedFrom = false; this.uploads = uploads; this.$div.append( this.$buttons ).show(); $( '#mwe-upwiz-steps' ).arrowStepsHighlight( this.$arrow ); $( 'html, body' ).animate( { scrollTop: offset.top, scrollLeft: offset.left }, 'slow' ); }; /** * Cleanup this step. */ uw.ui.Step.prototype.unload = function () { this.movedFrom = true; this.$div.children().detach(); }; uw.ui.Step.prototype.enableNextButton = function () { this.nextButtonPromise.resolve(); }; uw.ui.Step.prototype.enablePreviousButton = function () { this.previousButtonPromise.resolve(); }; /** * Add a 'next' button to the step's button container */ uw.ui.Step.prototype.addNextButton = function () { var ui = this; this.nextButton = new OO.ui.ButtonWidget( { classes: [ 'mwe-upwiz-button-next' ], label: mw.message( 'mwe-upwiz-next' ).text(), flags: [ 'progressive', 'primary' ] } ).on( 'click', function () { ui.emit( 'next-step' ); } ); this.nextButtonPromise.done( function () { ui.$buttons.append( ui.nextButton.$element ); } ); }; /** * Add a 'previous' button to the step's button container */ uw.ui.Step.prototype.addPreviousButton = function () { var ui = this; this.previousButton = new OO.ui.ButtonWidget( { classes: [ 'mwe-upwiz-button-previous' ], label: mw.message( 'mwe-upwiz-previous' ).text() } ).on( 'click', function () { ui.emit( 'previous-step' ); } ); this.previousButtonPromise.done( function () { ui.$buttons.append( ui.previousButton.$element ); } ); }; }( mediaWiki, jQuery, mediaWiki.uploadWizard, OO ) );