Tchanders has uploaded a new change for review. https://gerrit.wikimedia.org/r/242533
Change subject: Refactor PreviewElement to allow preview to be updated ...................................................................... Refactor PreviewElement to allow preview to be updated Allow updatePreview to be called separately, so that PreviewElement can be updated live. Bug: T114230 Change-Id: I161fe7b88e2fb0df85b8d41e8ddef0049c6cb435 --- M src/ui/elements/ve.ui.PreviewElement.js 1 file changed, 39 insertions(+), 32 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/33/242533/1 diff --git a/src/ui/elements/ve.ui.PreviewElement.js b/src/ui/elements/ve.ui.PreviewElement.js index 230f159..6640323 100644 --- a/src/ui/elements/ve.ui.PreviewElement.js +++ b/src/ui/elements/ve.ui.PreviewElement.js @@ -17,9 +17,6 @@ * @param {Object} [config] Configuration options */ ve.ui.PreviewElement = function VeUiPreviewElement( model, config ) { - var promises = [], - element = this; - // Parent constructor OO.ui.Element.call( this, config ); @@ -28,35 +25,7 @@ this.model = model; - // Initial CE node - this.view = ve.ce.nodeFactory.create( this.model.getType(), this.model ); - - function queueNode( node ) { - var promise; - if ( typeof node.generateContents === 'function' ) { - if ( node.isGenerating() ) { - promise = $.Deferred(); - node.once( 'rerender', promise.resolve ); - promises.push( promise ); - } - } - } - - // Traverse children to see when they are all rerendered - if ( this.view instanceof ve.ce.BranchNode ) { - ve.BranchNode.static.traverse( this.view, queueNode ); - } else { - queueNode( this.view ); - } - - // When all children are rerendered, replace with dm DOM - $.when.apply( $, promises ) - .then( function () { - // Verify that the element and/or the ce node weren't destroyed - if ( element.view ) { - element.replaceWithModelDom(); - } - } ); + this.updatePreview(); // Initialize this.$element.addClass( 've-ui-previewElement' ); @@ -110,6 +79,44 @@ }; /** + * Update the preview + */ +ve.ui.PreviewElement.prototype.updatePreview = function () { + var promises = [], + element = this; + + // Initial CE node + this.view = ve.ce.nodeFactory.create( this.model.getType(), this.model ); + + function queueNode( node ) { + var promise; + if ( typeof node.generateContents === 'function' ) { + if ( node.isGenerating() ) { + promise = $.Deferred(); + node.once( 'rerender', promise.resolve ); + promises.push( promise ); + } + } + } + + // Traverse children to see when they are all rerendered + if ( this.view instanceof ve.ce.BranchNode ) { + ve.BranchNode.static.traverse( this.view, queueNode ); + } else { + queueNode( this.view ); + } + + // When all children are rerendered, replace with dm DOM + $.when.apply( $, promises ) + .then( function () { + // Verify that the element and/or the ce node weren't destroyed + if ( element.view ) { + element.replaceWithModelDom(); + } + } ); +}; + +/** * Check if the preview is still generating * * @return {boolean} Still generating -- To view, visit https://gerrit.wikimedia.org/r/242533 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I161fe7b88e2fb0df85b8d41e8ddef0049c6cb435 Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Tchanders <thalia.e.c...@googlemail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits