mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 19:09:29 +00:00
0d30e1e77d
VisualEditor.php * Add CSS file ve.ce.MWMathNode.js * Wrap the image in a span, so GenerateContentNode doesn't try to nest an image inside an image * Remove unnecessary attribute setting * Only pass unwrapped image to deferred.resolve * Retrigger MathJax rendering ve.ce.Node.css * Use inline-block for image wrapper ve.dm.MWMathNode.js * Mixin GeneratedContentNode and implement getHash * Copy over functionality of MWTransclusionNode: + Just store data-mw for attributes + Store orignal(DomElement|MW|Index) for selser ve.init.mw.ViewPageTarget.js * Add mwMath to the toolbar ve.ui.MWMathInspector.js * Remove static.InputWidget, not required in this architecture * Use multiline TextInputWidget * Only update mw attribute * Allow creation of new math nodes ve.ui.MWInspector.css * Set height of TextInputWidget Change-Id: I520f8ccc9f89a2ce70aa1d9e02ed0c6cacbecc2f
122 lines
2.6 KiB
JavaScript
122 lines
2.6 KiB
JavaScript
/*!
|
|
* 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';
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle frame ready events.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.MWMathInspector.prototype.initialize = function () {
|
|
// Parent method
|
|
ve.ui.Inspector.prototype.initialize.call( this );
|
|
|
|
this.input = new ve.ui.TextInputWidget( {
|
|
'$$': this.frame.$$,
|
|
'overlay': this.surface.$localOverlay,
|
|
'multiline': true
|
|
} );
|
|
this.input.$.addClass( 've-ui-mwMathInspector-input' );
|
|
|
|
// Initialization
|
|
this.$form.append( this.input.$ );
|
|
};
|
|
|
|
|
|
/**
|
|
* Handle the inspector being opened.
|
|
*/
|
|
ve.ui.MWMathInspector.prototype.onOpen = function () {
|
|
var extsrc = '';
|
|
|
|
// Parent method
|
|
ve.ui.Inspector.prototype.onOpen.call( this );
|
|
|
|
this.node = this.surface.getView().getFocusedNode();
|
|
|
|
if ( this.node ) {
|
|
extsrc = this.node.getModel().getAttribute( 'mw' ).body.extsrc;
|
|
}
|
|
|
|
// Wait for animation to complete
|
|
setTimeout( ve.bind( function () {
|
|
// Setup input text
|
|
this.input.setValue( extsrc );
|
|
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 mw,
|
|
surfaceModel = this.surface.getModel();
|
|
|
|
// Parent method
|
|
ve.ui.Inspector.prototype.onClose.call( this, action );
|
|
|
|
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' }
|
|
] );
|
|
}
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ui.inspectorFactory.register( 'mwMathInspector', ve.ui.MWMathInspector );
|