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

36.11% Statements 13/36
0% Branches 0/6
0% Functions 0/12
36.11% Lines 13/36

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                              1x             1x       1x   1x   1x   1x                       1x                                 1x                             1x                   1x                           1x                               1x                 1x  
/*!
 * VisualEditor user interface DiffDialog class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * 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', 'close' ]
	}
];
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.ui.DiffDialog.prototype.initialize = function () {
	// Parent method
	ve.ui.DiffDialog.super.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( () => {
			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
			);
		} );
};
 
/**
 * @inheritdoc
 */
ve.ui.DiffDialog.prototype.getReadyProcess = function ( data ) {
	return ve.ui.DiffDialog.super.prototype.getReadyProcess.call( this, data )
		.next( () => {
			this.positionDiffElement();
		} );
};
 
/**
 * @inheritdoc
 */
ve.ui.DiffDialog.prototype.setDimensions = function () {
	// Parent method
	ve.ui.DiffDialog.super.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 () {
	setTimeout( () => {
		this.withoutSizeTransitions( () => {
			this.positioning = true;
			if ( this.diffElement && this.isVisible() ) {
				this.diffElement.positionDescriptions();
				this.updateSize();
			}
			this.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( () => {
			this.diffElement.$element.remove();
		} );
};
 
/* Registration */
 
ve.ui.windowFactory.register( ve.ui.DiffDialog );