mediawiki-extensions-Visual.../modules/ve-mw/ui/inspectors/ve.ui.MWMathInspector.js

98 lines
2.2 KiB
JavaScript
Raw Normal View History

/*!
* 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 */
ve.ui.MWMathInspector.static.icon = 'math';
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 );
this.mathNode = this.surface.getView().getFocusedNode();
var src = this.mathNode.getModel().getAttribute( 'extsrc' );
// 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(),
surfaceModel = this.surface.getModel();
// Parent method
ve.ui.Inspector.prototype.onClose.call( this, action );
surfaceModel.change(
ve.dm.Transaction.newFromAttributeChanges(
surfaceModel.getDocument(), this.mathNode.getOuterRange().start, { 'extsrc': newsrc }
)
);
};
/* Registration */
ve.ui.inspectorFactory.register( 'mwMathInspector', ve.ui.MWMathInspector );