Jiabao has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/85639


Change subject: MathJax Live Preview III
......................................................................

MathJax Live Preview III

- rebased ex-changes
- implement add new math node function

Change-Id: Ibe7dd274a0a3635da100ca379c54973050ba31a2
---
M modules/ve-mw/ce/nodes/ve.ce.MWMathNode.js
M modules/ve-mw/ui/inspectors/ve.ui.MWMathInspector.js
2 files changed, 30 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/39/85639/1

diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWMathNode.js 
b/modules/ve-mw/ce/nodes/ve.ce.MWMathNode.js
index a54878d..acddbff 100644
--- a/modules/ve-mw/ce/nodes/ve.ce.MWMathNode.js
+++ b/modules/ve-mw/ce/nodes/ve.ce.MWMathNode.js
@@ -94,7 +94,9 @@
  */
 ve.ce.MWMathNode.prototype.onParseSuccess = function ( deferred, response ) {
        var data = response.visualeditor, contentNodes = $( data.content 
).get();//, self = this;
-       contentNodes = Array.prototype.slice.apply( contentNodes[0].childNodes 
);
+       if (contentNodes[0]) {  
+               contentNodes = Array.prototype.slice.apply( 
contentNodes[0].childNodes );
+       }       
        deferred.resolve( contentNodes );
 
        MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub, this.$[0] ] );
diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWMathInspector.js 
b/modules/ve-mw/ui/inspectors/ve.ui.MWMathInspector.js
index af73629..30915dd 100644
--- a/modules/ve-mw/ui/inspectors/ve.ui.MWMathInspector.js
+++ b/modules/ve-mw/ui/inspectors/ve.ui.MWMathInspector.js
@@ -66,7 +66,7 @@
        var newsrc = this.input.getValue(),
                mw = this.mathNode.getModel().getAttribute( 'mw' );
 
-       if ( mw.body.extsrc !== newsrc ) {
+       if ( mw.body.extsrc !== newsrc && newsrc !== '') {
                this.mathNode.forceUpdate({ 'wikitext': newsrc });
        }
 };
@@ -75,14 +75,37 @@
  * Handle the inspector being opened.
  */
 ve.ui.MWMathInspector.prototype.onOpen = function () {
+       var src = '',
+               mw;
+               surfaceModel = this.surface.getModel();
 
        // Parent method
        ve.ui.Inspector.prototype.onOpen.call( this );
 
        this.mathNode = this.surface.getView().getFocusedNode();
 
-       var src = this.mathNode.getModel().getAttribute( 'mw' ).body.extsrc;
 
+       if (this.mathNode) {
+               src = this.mathNode.getModel().getAttribute( 'mw' ).body.extsrc;
+       } else {
+                       mw = {
+                               'name': 'math',
+                               'attrs': {},
+                               'body': {
+                                       'extsrc': this.input.getValue()
+                               }
+                       };
+                       
surfaceModel.getFragment().collapseRangeToEnd().insertContent( [
+                       {
+                               'type': 'mwMath',
+                               'attributes': {
+                                       'mw': mw
+                               }
+                       },
+                       { 'type': '/mwMath' }
+                       ] );
+                       this.mathNode = this.surface.getView().getFocusedNode();
+       }
        // Wait for animation to complete
        setTimeout( ve.bind( function () {
                // Setup input text
@@ -116,6 +139,8 @@
                                )
                        );
                }
+       } else {
+               
surfaceModel.change(ve.dm.Transaction.newFromRemoval(surfaceModel.getDocument(),
 this.mathNode.getOuterRange()));
        }
 };
 

-- 
To view, visit https://gerrit.wikimedia.org/r/85639
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibe7dd274a0a3635da100ca379c54973050ba31a2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Jiabao <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to