2013-07-03 21:44:15 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWMathInspector class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki math inspector.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.Inspector
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.ui.Surface} surface
|
|
|
|
* @param {Object} [config] Config options
|
|
|
|
*/
|
|
|
|
ve.ui.MWMathInspector = function VeUiMWMathInspector( surface, config ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.Inspector.call( this, surface, config );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.ui.MWMathInspector, ve.ui.Inspector );
|
|
|
|
|
|
|
|
/* Static properties */
|
|
|
|
|
2013-07-18 22:48:21 +00:00
|
|
|
ve.ui.MWMathInspector.static.icon = 'math';
|
2013-07-03 21:44:15 +00:00
|
|
|
|
|
|
|
ve.ui.MWMathInspector.static.titleMessage = 'visualeditor-mwmathinspector-title';
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle frame ready events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.MWMathInspector.prototype.initialize = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.Inspector.prototype.initialize.call( this );
|
|
|
|
|
2013-07-19 22:30:29 +00:00
|
|
|
this.input = new ve.ui.TextInputWidget( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'overlay': this.surface.$localOverlay,
|
|
|
|
'multiline': true
|
2013-07-03 21:44:15 +00:00
|
|
|
} );
|
2013-07-19 22:30:29 +00:00
|
|
|
this.input.$.addClass( 've-ui-mwMathInspector-input' );
|
2013-07-03 21:44:15 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$form.append( this.input.$ );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the inspector being opened.
|
|
|
|
*/
|
|
|
|
ve.ui.MWMathInspector.prototype.onOpen = function () {
|
2013-07-19 22:30:29 +00:00
|
|
|
var extsrc = '';
|
2013-07-03 21:44:15 +00:00
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ve.ui.Inspector.prototype.onOpen.call( this );
|
|
|
|
|
2013-07-19 22:30:29 +00:00
|
|
|
this.node = this.surface.getView().getFocusedNode();
|
2013-07-14 15:35:19 +00:00
|
|
|
|
2013-07-19 22:30:29 +00:00
|
|
|
if ( this.node ) {
|
|
|
|
extsrc = this.node.getModel().getAttribute( 'mw' ).body.extsrc;
|
|
|
|
}
|
2013-07-14 15:35:19 +00:00
|
|
|
|
2013-07-03 21:44:15 +00:00
|
|
|
// Wait for animation to complete
|
|
|
|
setTimeout( ve.bind( function () {
|
|
|
|
// Setup input text
|
2013-07-19 22:30:29 +00:00
|
|
|
this.input.setValue( extsrc );
|
2013-07-03 21:44:15 +00:00
|
|
|
this.input.$input.focus().select();
|
|
|
|
}, this ), 200 );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the inspector being closed.
|
|
|
|
*
|
|
|
|
* @param {string} action Action that caused the window to be closed
|
|
|
|
*/
|
|
|
|
ve.ui.MWMathInspector.prototype.onClose = function ( action ) {
|
2013-07-19 22:30:29 +00:00
|
|
|
var mw,
|
2013-07-14 15:35:19 +00:00
|
|
|
surfaceModel = this.surface.getModel();
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ve.ui.Inspector.prototype.onClose.call( this, action );
|
2013-07-03 21:44:15 +00:00
|
|
|
|
2013-07-19 22:30:29 +00:00
|
|
|
if ( this.node instanceof ve.ce.MWMathNode ) {
|
|
|
|
mw = this.node.getModel().getAttribute( 'mw' );
|
|
|
|
mw.body.extsrc = this.input.getValue();
|
|
|
|
surfaceModel.change(
|
|
|
|
ve.dm.Transaction.newFromAttributeChanges(
|
|
|
|
surfaceModel.getDocument(), this.node.getOuterRange().start, { 'mw': mw }
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
mw = {
|
|
|
|
'name': 'math',
|
|
|
|
'attrs': {},
|
|
|
|
'body': {
|
|
|
|
'extsrc': this.input.getValue()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
surfaceModel.getFragment().collapseRangeToEnd().insertContent( [
|
|
|
|
{
|
|
|
|
'type': 'mwMath',
|
|
|
|
'attributes': {
|
|
|
|
'mw': mw
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ 'type': '/mwMath' }
|
|
|
|
] );
|
|
|
|
}
|
2013-07-03 21:44:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.inspectorFactory.register( 'mwMathInspector', ve.ui.MWMathInspector );
|