Merge "Simplify VE inspector code by extending new MWLiveExtensionInspector"
This commit is contained in:
commit
1bd6c8bbb8
|
@ -1,7 +1,7 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface MWMathInspector class.
|
||||
*
|
||||
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
|
@ -11,21 +11,19 @@
|
|||
* MediaWiki math inspector.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ui.MWExtensionInspector
|
||||
* @extends ve.ui.MWLiveExtensionInspector
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
ve.ui.MWMathInspector = function VeUiMWMathInspector( config ) {
|
||||
// Parent constructor
|
||||
ve.ui.MWExtensionInspector.call( this, config );
|
||||
|
||||
this.onChangeHandler = ve.debounce( ve.bind( this.updatePreview, this ), 250 );
|
||||
ve.ui.MWLiveExtensionInspector.call( this, config );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWMathInspector, ve.ui.MWExtensionInspector );
|
||||
OO.inheritClass( ve.ui.MWMathInspector, ve.ui.MWLiveExtensionInspector );
|
||||
|
||||
/* Static properties */
|
||||
|
||||
|
@ -35,86 +33,9 @@ ve.ui.MWMathInspector.static.icon = 'math';
|
|||
|
||||
ve.ui.MWMathInspector.static.title = OO.ui.deferMsg( 'math-visualeditor-mwmathinspector-title' );
|
||||
|
||||
ve.ui.MWMathInspector.static.nodeView = ve.ce.MWMathNode;
|
||||
|
||||
ve.ui.MWMathInspector.static.nodeModel = ve.dm.MWMathNode;
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* Update the math node rendering to reflect the content entered into the inspector.
|
||||
*/
|
||||
ve.ui.MWMathInspector.prototype.updatePreview = function () {
|
||||
var mwData = ve.copy( this.node.getAttribute( 'mw' ) ),
|
||||
newsrc = this.input.getValue();
|
||||
|
||||
mwData.body.extsrc = newsrc;
|
||||
|
||||
if ( this.visible ) {
|
||||
this.getFragment().changeAttributes( { 'mw': mwData } );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathInspector.prototype.setup = function ( data ) {
|
||||
// Parent method
|
||||
ve.ui.MWExtensionInspector.prototype.setup.call( this, data );
|
||||
|
||||
this.getFragment().getSurface().pushStaging();
|
||||
|
||||
var mwData;
|
||||
|
||||
this.node = this.getFragment().getSelectedNode();
|
||||
if ( !this.node || !( this.node instanceof ve.dm.MWMathNode ) ) {
|
||||
// Create a dummy node, needed for live preview
|
||||
mwData = {
|
||||
'name': 'math',
|
||||
'attrs': {},
|
||||
'body': {
|
||||
'extsrc': ''
|
||||
}
|
||||
};
|
||||
this.getFragment().collapseRangeToEnd().insertContent( [
|
||||
{
|
||||
'type': 'mwMath',
|
||||
'attributes': {
|
||||
'mw': mwData
|
||||
}
|
||||
},
|
||||
{ 'type': '/mwMath' }
|
||||
] );
|
||||
this.node = this.getFragment().getSelectedNode();
|
||||
}
|
||||
|
||||
this.input.on( 'change', this.onChangeHandler );
|
||||
|
||||
// Override directionality settings, inspector's input
|
||||
// should always be LTR:
|
||||
this.input.setRTL( false );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathInspector.prototype.teardown = function ( data ) {
|
||||
var newsrc = this.input.getValue(),
|
||||
surfaceModel = this.getFragment().getSurface();
|
||||
|
||||
this.input.off( 'change', this.onChangeHandler );
|
||||
|
||||
this.getFragment().getSurface().applyStaging();
|
||||
|
||||
if ( newsrc === '' ) {
|
||||
// The user tried to empty the node, remove it
|
||||
surfaceModel.change( ve.dm.Transaction.newFromRemoval(
|
||||
surfaceModel.getDocument(), this.node.getOuterRange()
|
||||
) );
|
||||
}
|
||||
// Grandparent method; we're overriding the parent behavior with applyStaging
|
||||
ve.ui.Inspector.prototype.teardown.call( this, data );
|
||||
};
|
||||
ve.ui.MWMathInspector.static.dir = 'ltr';
|
||||
|
||||
/* Registration */
|
||||
|
||||
|
|
Loading…
Reference in New Issue