Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/inspectors/ve.ui.FragmentInspector.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface FragmentInspector class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Inspector for working with fragments of content.
9 *
10 * @class
11 * @extends OO.ui.ProcessDialog
12 * @mixes ve.ui.FragmentWindow
13 *
14 * @constructor
15 * @param {Object} [config] Configuration options
16 * @param {boolean} [config.padded=true] Inspector form area has padding,
17 * set to false for edge-to-edge layouts, e.g. IndexLayout
18 */
19 ve.ui.FragmentInspector = function VeUiFragmentInspector( config ) {
20 config = config || {};
21
22 // Parent constructor
23 ve.ui.FragmentInspector.super.call( this, config );
24
25 // Mixin constructor
26 ve.ui.FragmentWindow.call( this, config );
27
28 // Properties
29 this.initialFragment = null;
30 this.previousSelection = null;
31 this.padded = config.padded !== false;
32 };
33
34 /* Inheritance */
35
36 OO.inheritClass( ve.ui.FragmentInspector, OO.ui.ProcessDialog );
37
38 OO.mixinClass( ve.ui.FragmentInspector, ve.ui.FragmentWindow );
39
40 /* Static Properties */
41
42 ve.ui.FragmentInspector.static.actions = [
43 {
44 label: OO.ui.deferMsg( 'visualeditor-dialog-action-cancel' ),
45 flags: [ 'safe', 'close' ],
46 modes: [ 'readonly', 'edit', 'insert' ]
47 },
48 {
49 action: 'done',
50 label: OO.ui.deferMsg( 'visualeditor-dialog-action-done' ),
51 flags: [ 'progressive', 'primary' ],
52 modes: 'edit'
53 },
54 {
55 action: 'done',
56 label: OO.ui.deferMsg( 'visualeditor-dialog-action-insert' ),
57 flags: [ 'progressive', 'primary' ],
58 modes: 'insert'
59 }
60 ];
61
62 ve.ui.FragmentInspector.static.size = 'large';
63
64 /* Methods */
65
66 /**
67 * Handle form submit events.
68 *
69 * Executes the 'done' action when the user presses enter in the form.
70 */
71 ve.ui.FragmentInspector.prototype.onFormSubmit = function () {
72 this.executeAction( 'done' );
73 };
74
75 /**
76 * @inheritdoc
77 */
78 ve.ui.FragmentInspector.prototype.initialize = function () {
79 // Parent method
80 ve.ui.FragmentInspector.super.prototype.initialize.call( this );
81
82 // Properties
83 this.container = new OO.ui.PanelLayout( {
84 classes: [ 've-ui-fragmentInspector-container' ],
85 scrollable: true,
86 expanded: false,
87 padded: this.padded
88 } );
89 this.form = new OO.ui.FormLayout( {
90 classes: [ 've-ui-fragmentInspector-form' ]
91 } );
92
93 // Events
94 this.form.connect( this, { submit: 'onFormSubmit' } );
95
96 // Initialization
97 this.$element.addClass( 've-ui-fragmentInspector' );
98 this.$content.addClass( 've-ui-fragmentInspector-content' );
99 this.container.$element.append( this.form.$element );
100 this.$body.append( this.container.$element );
101
102 this.tabIndexScope = new ve.ui.TabIndexScope( {
103 root: this.$content
104 } );
105 };
106
107 /**
108 * @inheritdoc
109 */
110 ve.ui.FragmentInspector.prototype.getActionProcess = function ( action ) {
111 if ( action === 'done' ) {
112 return new OO.ui.Process( () => {
113 this.close( { action: 'done' } );
114 } );
115 }
116 return ve.ui.FragmentInspector.super.prototype.getActionProcess.call( this, action );
117 };
118
119 /**
120 * @inheritdoc
121 */
122 ve.ui.FragmentInspector.prototype.getActionWidgetConfig = function ( config ) {
123 // Mixin method
124 config = ve.ui.FragmentWindow.prototype.getActionWidgetConfig.call( this, config );
125 // Parent method
126 return ve.ui.FragmentInspector.super.prototype.getActionWidgetConfig.call( this, config );
127 };
128
129 /**
130 * @inheritdoc
131 */
132 ve.ui.FragmentInspector.prototype.getSetupProcess = function ( data ) {
133 // Parent method
134 const process = ve.ui.FragmentInspector.super.prototype.getSetupProcess.call( this, data );
135 // Mixin method
136 return ve.ui.FragmentWindow.prototype.getSetupProcess.call( this, data, process );
137 };
138
139 /**
140 * @inheritdoc
141 */
142 ve.ui.FragmentInspector.prototype.getTeardownProcess = function ( data ) {
143 // Parent method
144 const process = ve.ui.FragmentInspector.super.prototype.getTeardownProcess.call( this, data );
145 // Mixin method
146 return ve.ui.FragmentWindow.prototype.getTeardownProcess.call( this, data, process );
147 };
148
149 /**
150 * @inheritdoc
151 */
152 ve.ui.FragmentInspector.prototype.getReadyProcess = function ( data ) {
153 return ve.ui.FragmentInspector.super.prototype.getReadyProcess.call( this, data )
154 // Add a 0ms timeout before doing anything. Because… Internet Explorer :(
155 .first( 0 );
156 };
157
158 /**
159 * @inheritdoc
160 */
161 ve.ui.FragmentInspector.prototype.getBodyHeight = function () {
162 return Math.ceil( this.container.$element[ 0 ].scrollHeight );
163 };