all files / src/ui/dialogs/ ve.ui.DiffDialog.js

35.14% Statements 13/37
0% Branches 0/6
0% Functions 0/12
35.14% Lines 13/37
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128                                                                                                                                                                                                                                     
/*!
 * VisualEditor user interface DiffDialog class.
 *
 * @copyright 2011-2019 VisualEditor Team and others; see http://ve.mit-license.org
 */
 
/**
 * Dialog for displaying a diff.
 *
 * @class
 * @extends OO.ui.ProcessDialog
 *
 * @constructor
 * @param {Object} [config] Configuration options
 */
ve.ui.DiffDialog = function VeUiDiffDialog( config ) {
	// Parent constructor
	ve.ui.DiffDialog.super.call( this, config );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ui.DiffDialog, OO.ui.ProcessDialog );
 
/* Static properties */
 
ve.ui.DiffDialog.static.name = 'diff';
 
ve.ui.DiffDialog.static.size = 'larger';
 
ve.ui.DiffDialog.static.title = 'Changes';
 
ve.ui.DiffDialog.static.actions = [
	{
		label: OO.ui.deferMsg( 'visualeditor-dialog-action-done' ),
		flags: 'safe'
	}
];
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.ui.DiffDialog.prototype.initialize = function () {
	// Parent method
	ve.ui.DiffDialog.parent.prototype.initialize.apply( this, arguments );
 
	this.diffElement = null;
 
	this.content = new OO.ui.PanelLayout( {
		padded: true,
		expanded: false
	} );
 
	this.$body.append( this.content.$element );
};
 
/**
 * @inheritdoc
 */
ve.ui.DiffDialog.prototype.getSetupProcess = function ( data ) {
	return ve.ui.DiffDialog.super.prototype.getSetupProcess.call( this, data )
		.next( function () {
			this.diffElement = new ve.ui.DiffElement( new ve.dm.VisualDiff( data.oldDoc, data.newDoc ) );
			ve.targetLinksToNewWindow( this.diffElement.$document[ 0 ] );
 
			this.content.$element.append(
				this.diffElement.$element
			);
		}, this );
};
 
/**
 * @inheritdoc
 */
ve.ui.DiffDialog.prototype.getReadyProcess = function ( data ) {
	return ve.ui.DiffDialog.super.prototype.getReadyProcess.call( this, data )
		.next( function () {
			this.positionDiffElement();
		}, this );
};
 
/**
 * @inheritdoc
 */
ve.ui.DiffDialog.prototype.setDimensions = function () {
	// Parent method
	ve.ui.DiffDialog.parent.prototype.setDimensions.apply( this, arguments );
 
	if ( !this.positioning ) {
		this.positionDiffElement();
	}
};
 
/**
 * Re-position elements within the diff element
 *
 * Should be called whenever the diff element's container has changed width.
 */
ve.ui.DiffDialog.prototype.positionDiffElement = function () {
	var dialog = this;
	setTimeout( function () {
		dialog.withoutSizeTransitions( function () {
			dialog.positioning = true;
			if ( dialog.diffElement && dialog.isVisible() ) {
				dialog.diffElement.positionDescriptions();
				dialog.updateSize();
			}
			dialog.positioning = false;
		} );
	}, OO.ui.theme.getDialogTransitionDuration() );
};
 
/**
 * @inheritdoc
 */
ve.ui.DiffDialog.prototype.getTeardownProcess = function ( data ) {
	return ve.ui.DiffDialog.super.prototype.getTeardownProcess.call( this, data )
		.next( function () {
			this.diffElement.$element.remove();
		}, this );
};
 
/* Registration */
 
ve.ui.windowFactory.register( ve.ui.DiffDialog );