From c12523f908f16f393eaf7cada0818e37003b881f Mon Sep 17 00:00:00 2001 From: "James D. Forrester" Date: Wed, 16 Apr 2014 19:39:10 -0700 Subject: [PATCH] Simplify VE inspector code by extending new MWLiveExtensionInspector All live preview logic has been moved to ve.ui.MWLiveExtensionInspector so so this can be simplified down to just static configuration. Depends on I708c4cb012be in VE-MW. Change-Id: I24b4788e97411eec18161709ca5d47c87d3f64da --- modules/VisualEditor/ve.ui.MWMathInspector.js | 89 ++----------------- 1 file changed, 5 insertions(+), 84 deletions(-) diff --git a/modules/VisualEditor/ve.ui.MWMathInspector.js b/modules/VisualEditor/ve.ui.MWMathInspector.js index ac62041..0d4c441 100644 --- a/modules/VisualEditor/ve.ui.MWMathInspector.js +++ b/modules/VisualEditor/ve.ui.MWMathInspector.js @@ -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 */