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';
|
|
|
|
|
|
|
|
ve.ui.MWMathInspector.static.InputWidget = ve.ui.InputWidget;
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle frame ready events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.MWMathInspector.prototype.initialize = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.Inspector.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
this.input = new this.constructor.static.InputWidget( {
|
|
|
|
'$$': this.frame.$$, 'overlay': this.surface.$localOverlay
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$form.append( this.input.$ );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the inspector being opened.
|
|
|
|
*/
|
|
|
|
ve.ui.MWMathInspector.prototype.onOpen = function () {
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ve.ui.Inspector.prototype.onOpen.call( this );
|
|
|
|
|
2013-07-14 15:35:19 +00:00
|
|
|
this.mathNode = this.surface.getView().getFocusedNode();
|
|
|
|
|
|
|
|
var src = this.mathNode.getModel().getAttribute( 'extsrc' );
|
|
|
|
|
2013-07-03 21:44:15 +00:00
|
|
|
// Wait for animation to complete
|
|
|
|
setTimeout( ve.bind( function () {
|
|
|
|
// Setup input text
|
|
|
|
this.input.setValue( src );
|
|
|
|
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 ) {
|
|
|
|
|
|
|
|
var newsrc = this.input.getValue(),
|
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
|
|
|
|
|
|
|
surfaceModel.change(
|
|
|
|
ve.dm.Transaction.newFromAttributeChanges(
|
2013-07-14 15:35:19 +00:00
|
|
|
surfaceModel.getDocument(), this.mathNode.getOuterRange().start, { 'extsrc': newsrc }
|
2013-07-03 21:44:15 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.inspectorFactory.register( 'mwMathInspector', ve.ui.MWMathInspector );
|