Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/dialogs/ve.ui.DiffDialog.js

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