mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 08:10:35 +00:00
VisualDiff: Fetch original doc from Parsoid if fromEditedState
Bug: T160741 Change-Id: Ied0641cc868a8dd4cf540eba75e1b248277a96b0
This commit is contained in:
parent
ddf6a89c72
commit
939a1f4005
|
@ -1176,17 +1176,36 @@ ve.init.mw.ArticleTarget.prototype.onSaveDialogReviewComplete = function ( wikit
|
|||
* @return {jQuery.Promise|null} Promise resolving with a ve.dm.VisualDiff visual diff, or null if not known
|
||||
*/
|
||||
ve.init.mw.ArticleTarget.prototype.getVisualDiffPromise = function () {
|
||||
var deferred;
|
||||
var deferred, dmDoc,
|
||||
target = this;
|
||||
|
||||
if ( this.getSurface().getMode() === 'source' ) {
|
||||
return null;
|
||||
}
|
||||
deferred = $.Deferred();
|
||||
dmDoc = this.getSurface().getModel().getDocument();
|
||||
|
||||
if ( !this.originalDmDoc ) {
|
||||
// TODO: If switching from source - we need to fetch the original doc
|
||||
// from the server.
|
||||
this.originalDmDoc = this.createModelFromDom( this.doc, 'visual' );
|
||||
if ( !this.fromEditedState ) {
|
||||
this.originalDmDoc = this.createModelFromDom( this.doc, 'visual' );
|
||||
} else {
|
||||
mw.libs.ve.targetLoader.requestParsoidData(
|
||||
this.pageName,
|
||||
this.revid,
|
||||
this.constructor.name
|
||||
).then( function ( response ) {
|
||||
var doc, data = response ? ( response.visualeditor || response.visualeditoredit ) : null;
|
||||
if ( data && typeof data.content === 'string' ) {
|
||||
doc = target.parseDocument( data.content, 'visual' );
|
||||
target.originalDmDoc = target.createModelFromDom( doc, 'visual' );
|
||||
deferred.resolve( new ve.dm.VisualDiff( target.originalDmDoc, dmDoc ) );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
if ( this.originalDmDoc ) {
|
||||
deferred.resolve( new ve.dm.VisualDiff( this.originalDmDoc, dmDoc ) );
|
||||
}
|
||||
deferred.resolve( new ve.dm.VisualDiff( this.originalDmDoc, this.getSurface().getModel().getDocument() ) );
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue