jenkins-bot has submitted this change and it was merged.
Change subject: MWMath cleanup
......................................................................
MWMath cleanup
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
---
M VisualEditor.php
M modules/ve-mw/ce/nodes/ve.ce.MWMathNode.js
M modules/ve-mw/ce/styles/ve.ce.Node.css
M modules/ve-mw/dm/nodes/ve.dm.MWMathNode.js
M modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
M modules/ve-mw/ui/inspectors/ve.ui.MWMathInspector.js
A modules/ve-mw/ui/styles/ve.ui.MWInspector.css
M modules/ve-mw/ui/tools/buttons/ve.ui.MWMathButtonTool.js
8 files changed, 122 insertions(+), 41 deletions(-)
Approvals:
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/VisualEditor.php b/VisualEditor.php
index b190b6e..10086b0 100644
--- a/VisualEditor.php
+++ b/VisualEditor.php
@@ -580,6 +580,7 @@
've/ui/styles/ve.ui.Widget.css',
've-mw/ui/styles/ve.ui.Widget.css',
've/ui/styles/ve.ui.Inspector.css',
+ 've-mw/ui/styles/ve.ui.MWInspector.css',
've/ui/styles/ve.ui.Dialog.css',
've-mw/ui/styles/ve.ui.MWDialog.css',
),
diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWMathNode.js
b/modules/ve-mw/ce/nodes/ve.ce.MWMathNode.js
index 2a56e70..3d17ddf 100644
--- a/modules/ve-mw/ce/nodes/ve.ce.MWMathNode.js
+++ b/modules/ve-mw/ce/nodes/ve.ce.MWMathNode.js
@@ -5,7 +5,7 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
-/*global mw*/
+/*global mw, MathJax */
/**
* ContentEditable MediaWiki math node.
@@ -14,14 +14,23 @@
* @extends ve.ce.LeafNode
* @mixins ve.ce.FocusableNode
* @mixins ve.ce.ProtectedNode
+ * @mixins ve.ce.GeneratedContentNode
*
* @constructor
* @param {ve.dm.MWMathNode} model Model to observe
* @param {Object} [config] Config options
*/
ve.ce.MWMathNode = function VeCeMWMathNode( model, config ) {
+ var $wrapper;
+
// Parent constructor
ve.ce.LeafNode.call( this, model, config );
+
+ // Wrap image
+ this.$image = this.$;
+ $wrapper = $( '<span> ');
+ this.$.wrap( $wrapper );
+ this.$ = $wrapper;
// Mixin constructors
ve.ce.FocusableNode.call( this );
@@ -34,8 +43,6 @@
// DOM Changes
this.$.addClass( 've-ce-mwMathNode' );
- this.$.attr( 'src', model.getAttribute( 'src' ) );
- this.$.attr( 'alt', model.getAttribute( 'alt' ) );
};
/* Inheritance */
@@ -62,7 +69,7 @@
'action': 'visualeditor',
'paction': 'parsefragment',
'page': mw.config.get( 'wgRelevantPageName' ),
- 'wikitext': '<math>' + this.model.getAttribute(
'extsrc' ) + '</math>',
+ 'wikitext': '<math>' + this.getModel().getAttribute(
'mw' ).body.extsrc + '</math>',
'token': mw.user.tokens.get( 'editToken' ),
'format': 'json'
},
@@ -85,9 +92,18 @@
*/
ve.ce.MWMathNode.prototype.onParseSuccess = function ( deferred, response ) {
var data = response.visualeditor, contentNodes = $( data.content
).get();
- this.$.attr( 'alt', contentNodes[0].childNodes[0].getAttribute( 'alt' )
);
- this.$.attr( 'src', contentNodes[0].childNodes[0].getAttribute( 'src' )
);
+ // HACK: unwrap paragraph from PHP parser
+ contentNodes = Array.prototype.slice.apply( contentNodes[0].childNodes
);
deferred.resolve( contentNodes );
+ if ( $( contentNodes ).is( 'span.tex' ) ) {
+ // MathJax
+ MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub ] );
+ } else {
+ // Rerender after image load
+ this.$.find( 'img' ).on( 'load', ve.bind( function () {
+ this.emit( 'rerender' );
+ }, this ) );
+ }
};
/**
diff --git a/modules/ve-mw/ce/styles/ve.ce.Node.css
b/modules/ve-mw/ce/styles/ve.ce.Node.css
index df7d934..deee191 100644
--- a/modules/ve-mw/ce/styles/ve.ce.Node.css
+++ b/modules/ve-mw/ce/styles/ve.ce.Node.css
@@ -47,3 +47,9 @@
.ve-ce-mwInlineImageNode {
display: inline-block;
}
+
+/* ve.ce.MWMathNode */
+
+.ve-ce-mwMathNode {
+ display: inline-block;
+}
diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWMathNode.js
b/modules/ve-mw/dm/nodes/ve.dm.MWMathNode.js
index cbd823b..87a76e9 100644
--- a/modules/ve-mw/dm/nodes/ve.dm.MWMathNode.js
+++ b/modules/ve-mw/dm/nodes/ve.dm.MWMathNode.js
@@ -10,16 +10,23 @@
*
* @class
* @extends ve.dm.LeafNode
+ * @mixins ve.dm.GeneratedContentNode
+ *
* @constructor
*/
ve.dm.MWMathNode = function VeDmMWMathNode( length, element ) {
// Parent constructor
ve.dm.LeafNode.call( this, 0, element );
+
+ // Mixin constructors
+ ve.dm.GeneratedContentNode.call( this );
};
/* Inheritance */
ve.inheritClass( ve.dm.MWMathNode, ve.dm.LeafNode );
+
+ve.mixinClass( ve.dm.MWMathNode, ve.dm.GeneratedContentNode );
/* Static members */
@@ -33,41 +40,52 @@
ve.dm.MWMathNode.static.isContent = true;
-ve.dm.MWMathNode.static.toDataElement = function ( domElements ) {
- var dataElement,
+ve.dm.MWMathNode.static.toDataElement = function ( domElements, converter ) {
+ var dataElement, index,
mwDataJSON = domElements[0].getAttribute( 'data-mw' ),
- mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {},
- extsrc = mwData.body.extsrc,
- alt = domElements[0].getAttribute( 'alt' ),
- src = domElements[0].getAttribute( 'src' );
+ mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
dataElement = {
'type': 'mwMath',
'attributes': {
'mw': mwData,
- 'originalMw': mwDataJSON,
- 'extsrc': extsrc,
- 'alt': alt,
- 'src': src
+ 'originalDomElements': ve.copyArray( domElements ),
+ 'originalMw': mwDataJSON
}
};
+
+ index = this.storeDomElements( dataElement, domElements,
converter.getStore() );
+ dataElement.attributes.originalIndex = index;
+
return dataElement;
};
-ve.dm.MWMathNode.static.toDomElements = function ( dataElement, doc ) {
- var el = doc.createElement( 'img' ),
- mwData = ve.copy( dataElement.attributes.mw ),
+ve.dm.MWMathNode.static.toDomElements = function ( dataElement, doc, converter
) {
+ var el,
+ index = converter.getStore().indexOfHash( ve.getHash(
this.getHashObject( dataElement ) ) ),
originalMw = dataElement.attributes.originalMw;
- mwData.body.extsrc = dataElement.attributes.extsrc;
- if ( originalMw && ve.compare( mwData, JSON.parse( originalMw ) ) ) {
- el.setAttribute( 'data-mw', originalMw );
+ // If the transclusion is unchanged just send back the
+ // original DOM elements so selser can skip over it
+ if (
+ index === dataElement.attributes.originalIndex ||
+ ( originalMw && ve.compare( dataElement.attributes.mw,
JSON.parse( originalMw ) ) )
+ ) {
+ // The object in the store is also used for CE rendering so
return a copy
+ return ve.copyDomElements(
dataElement.attributes.originalDomElements, doc );
} else {
- el.setAttribute( 'data-mw', JSON.stringify( mwData ) );
+ el = doc.createElement( 'img' );
+ el.setAttribute( 'typeof', 'mw:Extension/Math' );
+ el.setAttribute( 'data-mw', JSON.stringify(
dataElement.attributes.mw ) );
+ return [ el ];
}
- el.setAttribute( 'alt', dataElement.attributes.alt );
- el.setAttribute( 'src', dataElement.attributes.src );
- return [ el ];
+};
+
+ve.dm.MWMathNode.static.getHashObject = function ( dataElement ) {
+ return {
+ type: dataElement.type,
+ mw: dataElement.attributes.mw
+ };
};
/* Registration */
diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
index 35e57bb..d193090 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
@@ -172,7 +172,7 @@
{ 'items': [ 'mwFormat' ] },
{ 'items': [ 'bold', 'italic', 'mwLink', 'code', 'clear' ] },
{ 'items': [ 'number', 'bullet', 'outdent', 'indent' ] },
- { 'items': [ 'mwMediaInsert', 'mwReference', 'mwReferenceList',
'mwTransclusion' ] }
+ { 'items': [ 'mwMediaInsert', 'mwReference', 'mwReferenceList',
'mwTransclusion', 'mwMath' ] }
];
ve.init.mw.ViewPageTarget.static.surfaceCommands = [
diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWMathInspector.js
b/modules/ve-mw/ui/inspectors/ve.ui.MWMathInspector.js
index 1bd1068..5f9dfc6 100644
--- a/modules/ve-mw/ui/inspectors/ve.ui.MWMathInspector.js
+++ b/modules/ve-mw/ui/inspectors/ve.ui.MWMathInspector.js
@@ -30,8 +30,6 @@
ve.ui.MWMathInspector.static.titleMessage =
'visualeditor-mwmathinspector-title';
-ve.ui.MWMathInspector.static.InputWidget = ve.ui.InputWidget;
-
/* Methods */
/**
@@ -43,9 +41,12 @@
// Parent method
ve.ui.Inspector.prototype.initialize.call( this );
- this.input = new this.constructor.static.InputWidget( {
- '$$': this.frame.$$, 'overlay': this.surface.$localOverlay
+ 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.$ );
@@ -56,18 +57,21 @@
* Handle the inspector being opened.
*/
ve.ui.MWMathInspector.prototype.onOpen = function () {
+ var extsrc = '';
// Parent method
ve.ui.Inspector.prototype.onOpen.call( this );
- this.mathNode = this.surface.getView().getFocusedNode();
+ this.node = this.surface.getView().getFocusedNode();
- var src = this.mathNode.getModel().getAttribute( 'extsrc' );
+ 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( src );
+ this.input.setValue( extsrc );
this.input.$input.focus().select();
}, this ), 200 );
};
@@ -78,18 +82,38 @@
* @param {string} action Action that caused the window to be closed
*/
ve.ui.MWMathInspector.prototype.onClose = function ( action ) {
-
- var newsrc = this.input.getValue(),
+ var mw,
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 }
- )
- );
+ 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 */
diff --git a/modules/ve-mw/ui/styles/ve.ui.MWInspector.css
b/modules/ve-mw/ui/styles/ve.ui.MWInspector.css
new file mode 100644
index 0000000..82e3386
--- /dev/null
+++ b/modules/ve-mw/ui/styles/ve.ui.MWInspector.css
@@ -0,0 +1,12 @@
+/*!
+ * VisualEditor MediaWiki UserInterface Inspector styles.
+ *
+ * @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+
+/* ve.ui.MWMathInspector */
+
+.ve-ui-mwMathInspector-input textarea {
+ height: 8em;
+}
\ No newline at end of file
diff --git a/modules/ve-mw/ui/tools/buttons/ve.ui.MWMathButtonTool.js
b/modules/ve-mw/ui/tools/buttons/ve.ui.MWMathButtonTool.js
index 5ebe3f6..c97e212 100644
--- a/modules/ve-mw/ui/tools/buttons/ve.ui.MWMathButtonTool.js
+++ b/modules/ve-mw/ui/tools/buttons/ve.ui.MWMathButtonTool.js
@@ -26,9 +26,13 @@
/* Static Properties */
ve.ui.MWMathButtonTool.static.name = 'mwMath';
+
ve.ui.MWMathButtonTool.static.icon = 'math';
+
ve.ui.MWMathButtonTool.static.titleMessage =
'visualeditor-mwmathinspector-title';
+
ve.ui.MWMathButtonTool.static.inspector = 'mwMathInspector';
+
ve.ui.MWMathButtonTool.static.modelClasses = [ ve.dm.MWMathNode ];
/* Registration */
--
To view, visit https://gerrit.wikimedia.org/r/74807
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I520f8ccc9f89a2ce70aa1d9e02ed0c6cacbecc2f
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jiabao <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits