mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 22:35:41 +00:00
Use ve.ui.SurfaceWidget for image captions
Objectives: * Make use of the new ve.ui.SurfaceWidget.js for image caption editing Changes: ve.ui.MWDialog.css * Remove styles that are no longer needed ** -body class isn't needed if you contain the content in a layout and configure it to be padded ** Toolbar styles are now part of surface widget ve.ui.MWMediaEditDialog.js * Wrap caption fieldset in an editPanel (also nice because we may merge this dialog with MediaInsert and use a stack panel layout in the future * Replace surface and toolbar with surface widget which manages both Change-Id: I1b7e0e2ec1cfa30879360a7ebde2b0f35d26aca5
This commit is contained in:
parent
61ba07d409
commit
dc606823e2
|
@ -49,21 +49,28 @@ ve.ui.MWMediaEditDialog.prototype.initialize = function () {
|
||||||
ve.ui.MWDialog.prototype.initialize.call( this );
|
ve.ui.MWDialog.prototype.initialize.call( this );
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
this.contentFieldset = new ve.ui.FieldsetLayout( {
|
this.editPanel = new ve.ui.PanelLayout( {
|
||||||
|
'$$': this.frame.$$,
|
||||||
|
'padded': true,
|
||||||
|
'scrollable': true
|
||||||
|
} );
|
||||||
|
this.captionFieldset = new ve.ui.FieldsetLayout( {
|
||||||
'$$': this.frame.$$,
|
'$$': this.frame.$$,
|
||||||
'label': ve.msg( 'visualeditor-dialog-media-content-section' ),
|
'label': ve.msg( 'visualeditor-dialog-media-content-section' ),
|
||||||
'icon': 'parameter'
|
'icon': 'parameter'
|
||||||
} );
|
} );
|
||||||
this.applyButton = new ve.ui.ButtonWidget( {
|
this.applyButton = new ve.ui.ButtonWidget( {
|
||||||
'$$': this.$$, 'label': ve.msg( 'visualeditor-dialog-action-apply' ), 'flags': ['primary']
|
'$$': this.$$,
|
||||||
|
'label': ve.msg( 'visualeditor-dialog-action-apply' ),
|
||||||
|
'flags': ['primary']
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
this.applyButton.connect( this, { 'click': [ 'close', 'apply' ] } );
|
this.applyButton.connect( this, { 'click': [ 'close', 'apply' ] } );
|
||||||
|
|
||||||
// Initialization
|
// Initialization
|
||||||
this.$body.addClass( 've-ui-mwMediaEditDialog-body' );
|
this.editPanel.$.append( this.captionFieldset.$ );
|
||||||
this.$body.append( this.contentFieldset.$ );
|
this.$body.append( this.editPanel.$ );
|
||||||
this.$foot.append( this.applyButton.$ );
|
this.$foot.append( this.applyButton.$ );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,7 +80,7 @@ ve.ui.MWMediaEditDialog.prototype.onOpen = function () {
|
||||||
// Parent method
|
// Parent method
|
||||||
ve.ui.MWDialog.prototype.onOpen.call( this );
|
ve.ui.MWDialog.prototype.onOpen.call( this );
|
||||||
|
|
||||||
// Get caption content
|
// Properties
|
||||||
this.captionNode = this.surface.getView().getFocusedNode().getModel().getCaptionNode();
|
this.captionNode = this.surface.getView().getFocusedNode().getModel().getCaptionNode();
|
||||||
if ( this.captionNode && this.captionNode.getLength() > 0 ) {
|
if ( this.captionNode && this.captionNode.getLength() > 0 ) {
|
||||||
data = doc.getData( this.captionNode.getRange(), true );
|
data = doc.getData( this.captionNode.getRange(), true );
|
||||||
|
@ -84,17 +91,18 @@ ve.ui.MWMediaEditDialog.prototype.onOpen = function () {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.captionSurface = new ve.ui.Surface(
|
this.captionSurface = new ve.ui.SurfaceWidget(
|
||||||
new ve.dm.ElementLinearData( doc.getStore(), data ), { '$$': this.frame.$$ }
|
new ve.dm.ElementLinearData( doc.getStore(), data ),
|
||||||
|
{
|
||||||
|
'$$': this.frame.$$,
|
||||||
|
'tools': this.constructor.static.toolbarTools,
|
||||||
|
'commands': this.constructor.static.surfaceCommands
|
||||||
|
}
|
||||||
);
|
);
|
||||||
this.captionToolbar = new ve.ui.Toolbar( this.captionSurface, { '$$': this.frame.$$ } );
|
|
||||||
|
|
||||||
this.captionToolbar.$.addClass( 've-ui-mwMediaEditDialog-toolbar' );
|
// Initialization
|
||||||
this.contentFieldset.$.append( this.captionToolbar.$, this.captionSurface.$ );
|
this.captionFieldset.$.append( this.captionSurface.$ );
|
||||||
this.captionToolbar.addTools( this.constructor.static.toolbarTools );
|
|
||||||
this.captionSurface.addCommands( this.constructor.static.surfaceCommands );
|
|
||||||
this.captionSurface.initialize();
|
this.captionSurface.initialize();
|
||||||
this.captionSurface.view.documentView.documentNode.$.focus();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ve.ui.MWMediaEditDialog.prototype.onClose = function ( action ) {
|
ve.ui.MWMediaEditDialog.prototype.onClose = function ( action ) {
|
||||||
|
@ -104,7 +112,7 @@ ve.ui.MWMediaEditDialog.prototype.onClose = function ( action ) {
|
||||||
ve.ui.MWDialog.prototype.onClose.call( this );
|
ve.ui.MWDialog.prototype.onClose.call( this );
|
||||||
|
|
||||||
if ( action === 'apply' ) {
|
if ( action === 'apply' ) {
|
||||||
data = this.captionSurface.getModel().getDocument().getData();
|
data = this.captionSurface.getContent();
|
||||||
doc = surfaceModel.getDocument();
|
doc = surfaceModel.getDocument();
|
||||||
if ( this.captionNode ) {
|
if ( this.captionNode ) {
|
||||||
// Replace the contents of the caption
|
// Replace the contents of the caption
|
||||||
|
@ -123,9 +131,9 @@ ve.ui.MWMediaEditDialog.prototype.onClose = function ( action ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
this.captionNode = null;
|
|
||||||
this.captionSurface.destroy();
|
this.captionSurface.destroy();
|
||||||
this.captionToolbar.destroy();
|
this.captionSurface = null;
|
||||||
|
this.captionNode = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Registration */
|
/* Registration */
|
||||||
|
|
|
@ -81,22 +81,3 @@
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ve.ui.MWMediaEditDialog */
|
|
||||||
|
|
||||||
.ve-ui-mwMediaEditDialog-body {
|
|
||||||
padding: 2em;
|
|
||||||
overflow-y: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ve-ui-mwMediaEditDialog-toolbar {
|
|
||||||
font-size: 1.25em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ve-ui-mwMediaEditDialog-toolbar .ve-ui-toolbar-bar {
|
|
||||||
border: solid 1px #ddd;
|
|
||||||
border-radius: 0.25em;
|
|
||||||
border-bottom-right-radius: 0;
|
|
||||||
border-bottom-left-radius: 0;
|
|
||||||
border-bottom-width: 0;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue