2013-06-18 22:58:10 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWMediaEditDialog class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Document dialog.
|
|
|
|
*
|
|
|
|
* @class
|
2013-07-03 01:30:10 +00:00
|
|
|
* @extends ve.ui.MWDialog
|
2013-06-18 22:58:10 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.ui.Surface} surface
|
|
|
|
* @param {Object} [config] Config options
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaEditDialog = function VeUiMWMediaEditDialog( surface, config ) {
|
|
|
|
// Parent constructor
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.ui.MWDialog.call( this, surface, config );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.captionNode = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.inheritClass( ve.ui.MWMediaEditDialog, ve.ui.MWDialog );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWMediaEditDialog.static.titleMessage = 'visualeditor-dialog-media-title';
|
|
|
|
|
|
|
|
ve.ui.MWMediaEditDialog.static.icon = 'picture';
|
|
|
|
|
|
|
|
ve.ui.MWMediaEditDialog.static.toolbarTools = [
|
|
|
|
{ 'items': ['undo', 'redo'] },
|
|
|
|
{ 'items': ['bold', 'italic', 'mwLink', 'clear'] }
|
|
|
|
];
|
|
|
|
|
|
|
|
ve.ui.MWMediaEditDialog.static.surfaceCommands = [
|
|
|
|
'bold', 'italic', 'mwLink', 'undo', 'redo'
|
|
|
|
];
|
|
|
|
|
|
|
|
/* Static Initialization */
|
|
|
|
|
|
|
|
ve.ui.MWMediaEditDialog.static.addLocalStylesheets( [
|
2013-07-03 01:30:10 +00:00
|
|
|
've/ce/styles/ve.ce.Node.css',
|
|
|
|
've-mw/ce/styles/ve.ce.Node.css',
|
|
|
|
've/ce/styles/ve.ce.Surface.css',
|
|
|
|
've/ui/styles/ve.ui.Surface.css',
|
|
|
|
've/ui/styles/ve.ui.Context.css',
|
|
|
|
've/ui/styles/ve.ui.Tool.css',
|
|
|
|
've-mw/ui/styles/ve.ui.Tool.css',
|
|
|
|
've/ui/styles/ve.ui.Toolbar.css'
|
2013-06-18 22:58:10 +00:00
|
|
|
] );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
ve.ui.MWMediaEditDialog.prototype.initialize = function () {
|
2013-06-21 02:47:10 +00:00
|
|
|
// Parent method
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.ui.MWDialog.prototype.initialize.call( this );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.contentFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-media-content-section' ),
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$body.addClass( 've-ui-mwMediaEditDialog-body' );
|
|
|
|
this.$body.append( this.contentFieldset.$ );
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWMediaEditDialog.prototype.onOpen = function () {
|
|
|
|
var data, doc = this.surface.getModel().getDocument();
|
|
|
|
|
|
|
|
// Parent method
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.ui.MWDialog.prototype.onOpen.call( this );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
// Get caption content
|
|
|
|
this.captionNode = this.surface.getView().getFocusedNode().getModel().getCaptionNode();
|
|
|
|
if ( this.captionNode && this.captionNode.getLength() > 0 ) {
|
|
|
|
data = doc.getData( this.captionNode.getRange(), true );
|
|
|
|
} else {
|
|
|
|
data = [
|
|
|
|
{ 'type': 'paragraph', 'internal': { 'generated': 'wrapper' } },
|
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.captionSurface = new ve.ui.Surface(
|
|
|
|
new ve.dm.ElementLinearData( doc.getStore(), data ), { '$$': this.frame.$$ }
|
|
|
|
);
|
|
|
|
this.captionToolbar = new ve.ui.Toolbar( this.captionSurface, { '$$': this.frame.$$ } );
|
|
|
|
|
|
|
|
this.captionToolbar.$.addClass( 've-ui-mwMediaEditDialog-toolbar' );
|
|
|
|
this.contentFieldset.$.append( this.captionToolbar.$, this.captionSurface.$ );
|
|
|
|
this.captionToolbar.addTools( this.constructor.static.toolbarTools );
|
|
|
|
this.captionSurface.addCommands( this.constructor.static.surfaceCommands );
|
|
|
|
this.captionSurface.initialize();
|
|
|
|
this.captionSurface.view.documentView.documentNode.$.focus();
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWMediaEditDialog.prototype.onClose = function ( action ) {
|
|
|
|
var data, doc, surfaceModel = this.surface.getModel();
|
|
|
|
|
|
|
|
// Parent method
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.ui.MWDialog.prototype.onClose.call( this );
|
2013-06-18 22:58:10 +00:00
|
|
|
|
|
|
|
if ( action === 'apply' ) {
|
|
|
|
data = this.captionSurface.getModel().getDocument().getData();
|
|
|
|
doc = surfaceModel.getDocument();
|
|
|
|
if ( this.captionNode ) {
|
|
|
|
// Replace the contents of the caption
|
|
|
|
surfaceModel.getFragment( this.captionNode.getRange(), true ).insertContent( data );
|
|
|
|
} else {
|
|
|
|
// Insert a new caption at the beginning of the image node
|
|
|
|
surfaceModel.getFragment()
|
|
|
|
.adjustRange( 1 )
|
|
|
|
.collapseRangeToStart()
|
|
|
|
.insertContent(
|
|
|
|
[ { 'type': 'mwImageCaption' } ]
|
|
|
|
.concat( data )
|
|
|
|
.concat( [ { 'type': '/mwImageCaption' } ] )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
this.captionNode = null;
|
|
|
|
this.captionSurface.destroy();
|
|
|
|
this.captionToolbar.destroy();
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.dialogFactory.register( 'mwMediaEdit', ve.ui.MWMediaEditDialog );
|