Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/177129
Change subject: Use target.getSurface now that targets can have multiple
surfaces
......................................................................
Use target.getSurface now that targets can have multiple surfaces
Also
* Remove debug bar code now surfaces manage their own
* Remove import rules code now implemented in base target
Depends on I5c2afe4 in core.
Change-Id: I18d6f9f2f36431959d31347b4c1952a1aca1350e
---
M modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
M modules/ve-mw/init/ve.init.mw.Target.js
2 files changed, 57 insertions(+), 63 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/29/177129/1
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 c345961..73bdb34 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
@@ -210,10 +210,10 @@
this.toolbar.$bar.slideDown( 'fast', function () {
// Check the surface wasn't torn down while the toolbar was
animating
- if ( this.surface ) {
+ if ( this.getSurface() ) {
this.toolbar.initialize();
- this.surface.getView().emit( 'position' );
- this.surface.getContext().updateDimensions();
+ this.getSurface().getView().emit( 'position' );
+ this.getSurface().getContext().updateDimensions();
}
}.bind( this ) );
};
@@ -281,7 +281,7 @@
if ( override || !this.edited ) {
this.cancel( trackMechanism );
} else {
- this.surface.dialogs.openWindow( 'cancelconfirm'
).then( function ( opened ) {
+ this.getSurface().dialogs.openWindow( 'cancelconfirm'
).then( function ( opened ) {
opened.then( function ( closing ) {
closing.then( function ( data ) {
if ( data.action === 'discard'
) {
@@ -418,14 +418,13 @@
return;
}
this.activating = false;
- this.surface.getModel().connect( this, {
+ this.getSurface().getModel().connect( this, {
history: 'updateToolbarSaveButtonState'
} );
- this.surface.setImportRules( this.constructor.static.importRules );
// TODO: mwTocWidget should probably live in a ve.ui.MWSurface subclass
if ( mw.config.get( 'wgVisualEditorConfig' ).enableTocWidget ) {
- this.surface.mwTocWidget = new ve.ui.MWTocWidget( this.surface
);
+ this.getSurface().mwTocWidget = new ve.ui.MWTocWidget(
this.getSurface() );
}
// Update UI
@@ -433,7 +432,7 @@
this.changeDocumentTitle();
this.hidePageContent();
- this.surface.getView().focus();
+ this.getSurface().getView().focus();
this.setupToolbarSaveButton();
this.attachToolbarSaveButton();
@@ -701,7 +700,7 @@
*/
ve.init.mw.ViewPageTarget.prototype.onShowChanges = function ( diffHtml ) {
// Invalidate the viewer diff on next change
- this.surface.getModel().getDocument().once( 'transact',
+ this.getSurface().getModel().getDocument().once( 'transact',
this.saveDialog.clearDiff.bind( this.saveDialog )
);
this.saveDialog.setDiffAndReview( diffHtml );
@@ -797,7 +796,7 @@
* @param {jQuery.Event} e Mouse click event
*/
ve.init.mw.ViewPageTarget.prototype.onToolbarMetaButtonClick = function () {
- this.surface.getDialogs().openWindow( 'meta' );
+ this.getSurface().getDialogs().openWindow( 'meta' );
};
/**
@@ -806,7 +805,7 @@
ve.init.mw.ViewPageTarget.prototype.updateToolbarSaveButtonState = function ()
{
var isDisabled;
- this.edited = this.surface.getModel().hasBeenModified();
+ this.edited = this.getSurface().getModel().hasBeenModified();
// Disable the save button if we have no history or if the sanity check
is not finished
isDisabled = ( !this.edited && !this.restoring ) ||
!this.sanityCheckFinished;
this.toolbarSaveButton.setDisabled( isDisabled );
@@ -847,7 +846,7 @@
*/
ve.init.mw.ViewPageTarget.prototype.onSaveDialogReviewComplete = function (
wikitext ) {
// Invalidate the viewer wikitext on next change
- this.surface.getModel().getDocument().once( 'transact',
+ this.getSurface().getModel().getDocument().once( 'transact',
this.saveDialog.clearDiff.bind( this.saveDialog )
);
this.saveDialog.setDiffAndReview( $( '<pre>' ).text( wikitext ) );
@@ -899,14 +898,14 @@
* @method
*/
ve.init.mw.ViewPageTarget.prototype.editSource = function () {
- if ( !this.surface.getModel().hasBeenModified() ) {
+ if ( !this.getSurface().getModel().hasBeenModified() ) {
this.switchToWikitextEditor( true );
return;
}
- this.surface.getView().getDocument().getDocumentNode().$element.css(
'opacity', 0.5 );
+
this.getSurface().getView().getDocument().getDocumentNode().$element.css(
'opacity', 0.5 );
- this.surface.getDialogs().openWindow( 'wikitextswitchconfirm', {
target: this } );
+ this.getSurface().getDialogs().openWindow( 'wikitextswitchconfirm', {
target: this } );
};
/**
@@ -999,8 +998,8 @@
this.tearDownToolbar();
this.tearDownDebugBar();
this.restoreDocumentTitle();
- if ( this.surface.mwTocWidget ) {
- this.surface.mwTocWidget.teardown();
+ if ( this.getSurface().mwTocWidget ) {
+ this.getSurface().mwTocWidget.teardown();
}
if ( this.saveDialog && this.saveDialog.isOpened() ) {
@@ -1012,9 +1011,8 @@
return $.when.apply( $, promises ).then( function () {
// Destroy surface
- if ( this.surface ) {
- this.surface.destroy();
- this.surface = null;
+ while ( this.surfaces.length ) {
+ this.surfaces.pop().destroy();
}
this.active = false;
}.bind( this ) );
@@ -1027,17 +1025,17 @@
* @method
*/
ve.init.mw.ViewPageTarget.prototype.setupSkinTabs = function () {
- var viewPageTarget = this;
+ var target = this;
if ( this.isViewPage ) {
// Allow instant switching back to view mode, without refresh
$( '#ca-view a, #ca-nstab-visualeditor a' )
.click( this.onViewTabClick.bind( this ) );
$( '#ca-viewsource, #ca-edit' ).click( function ( e ) {
- if ( viewPageTarget.surface &&
!viewPageTarget.deactivating ) {
- viewPageTarget.editSource();
+ if ( target.getSurface() && !target.deactivating ) {
+ target.editSource();
- if (
viewPageTarget.surface.getModel().hasBeenModified() ) {
+ if (
target.getSurface().getModel().hasBeenModified() ) {
e.preventDefault();
}
}
@@ -1089,7 +1087,7 @@
ve.init.mw.ViewPageTarget.prototype.attachToolbarSaveButton = function () {
var $actionTools = $( '<div>' ),
$pushButtons = $( '<div>' ),
- actions = new ve.ui.TargetToolbar( this, this.surface );
+ actions = new ve.ui.TargetToolbar( this, this.getSurface() );
actions.setup( [
{ include: [ 'help', 'notices' ] },
@@ -1120,10 +1118,10 @@
*/
ve.init.mw.ViewPageTarget.prototype.showSaveDialog = function () {
this.emit( 'saveWorkflowBegin' );
- this.surface.getDialogs().getWindow( 'mwSave' ).then( function ( win ) {
- var currentWindow =
this.surface.getContext().getInspectors().getCurrentWindow(),
+ this.getSurface().getDialogs().getWindow( 'mwSave' ).then( function (
win ) {
+ var currentWindow =
this.getSurface().getContext().getInspectors().getCurrentWindow(),
target = this;
- this.origSelection = this.surface.getModel().getSelection();
+ this.origSelection =
this.getSurface().getModel().getSelection();
// Make sure any open inspectors are closed
if ( currentWindow ) {
@@ -1132,7 +1130,7 @@
// Preload the serialization
if ( !this.docToSave ) {
- this.docToSave = ve.dm.converter.getDomFromModel(
this.surface.getModel().getDocument() );
+ this.docToSave = ve.dm.converter.getDomFromModel(
this.getSurface().getModel().getDocument() );
}
this.prepareCacheKey( this.docToSave );
@@ -1152,9 +1150,9 @@
}
this.saveDialog.setSanityCheck( this.sanityCheckVerified );
- this.surface.getDialogs().openWindow(
+ this.getSurface().getDialogs().openWindow(
this.saveDialog,
- { dir: this.surface.getModel().getDocument().getLang() }
+ { dir:
this.getSurface().getModel().getDocument().getLang() }
)
// Call onSaveDialogClose() when the save dialog starts
closing
.always( function ( opened ) {
@@ -1174,12 +1172,12 @@
this.docToSave = null;
this.clearPreparedCacheKey();
}.bind( this );
- if ( this.surface ) {
- this.surface.getModel().getDocument().once( 'transact', clear );
+ if ( this.getSurface() ) {
+ this.getSurface().getModel().getDocument().once( 'transact',
clear );
} else {
clear();
}
- this.surface.getModel().setSelection( this.origSelection );
+ this.getSurface().getModel().setSelection( this.origSelection );
this.emit( 'saveWorkflowEnd' );
};
@@ -1597,7 +1595,7 @@
( !usePrefs && $.cookie(
've-beta-welcome-dialog' ) === null )
)
) {
- this.surface.getDialogs().openWindow( 'betaWelcome' );
+ this.getSurface().getDialogs().openWindow(
'betaWelcome' );
}
if ( prefSaysShow ) {
@@ -1615,10 +1613,10 @@
}
}
- if ( this.surface.getModel().metaList.getItemsInGroup( 'mwRedirect'
).length ) {
- this.surface.getDialogs().openWindow( 'meta', {
+ if ( this.getSurface().getModel().metaList.getItemsInGroup(
'mwRedirect' ).length ) {
+ this.getSurface().getDialogs().openWindow( 'meta', {
page: 'settings',
- fragment: this.surface.getModel().getFragment()
+ fragment: this.getSurface().getModel().getFragment()
} );
}
};
@@ -1657,7 +1655,7 @@
return undefined;
}
// Check if there's been an edit
- if ( this.surface && this.edited && mw.user.options.get(
'useeditwarning' ) ) {
+ if ( this.getSurface() && this.edited && mw.user.options.get(
'useeditwarning' ) ) {
// Return our message
message = ve.msg( 'visualeditor-viewpage-savewarning' );
}
@@ -1688,7 +1686,7 @@
} ).toString();
} else {
this.serialize(
- this.docToSave || ve.dm.converter.getDomFromModel(
this.surface.getModel().getDocument() ),
+ this.docToSave || ve.dm.converter.getDomFromModel(
this.getSurface().getModel().getDocument() ),
function ( wikitext ) {
ve.track( 'mwedit.abort', { type: 'switchwith',
mechanism: 'navigate' } );
this.submitWithSaveFields( { wpDiff: 1,
veswitched: 1 }, wikitext );
@@ -1701,5 +1699,5 @@
* Resets the document opacity when we've decided to cancel switching to the
wikitext editor.
*/
ve.init.mw.ViewPageTarget.prototype.resetDocumentOpacity = function () {
- this.surface.getView().getDocument().getDocumentNode().$element.css(
'opacity', 1 );
+
this.getSurface().getView().getDocument().getDocumentNode().$element.css(
'opacity', 1 );
};
diff --git a/modules/ve-mw/init/ve.init.mw.Target.js
b/modules/ve-mw/init/ve.init.mw.Target.js
index 775ff68..06e1644 100644
--- a/modules/ve-mw/init/ve.init.mw.Target.js
+++ b/modules/ve-mw/init/ve.init.mw.Target.js
@@ -606,7 +606,7 @@
*/
ve.init.mw.Target.prototype.onSaveError = function ( doc, saveData, jqXHR,
status, data ) {
var api, editApi,
- viewPage = this;
+ target = this;
this.saving = false;
// Handle empty response
@@ -641,12 +641,12 @@
prop: 'info',
// Try to send the normalised form so that it is less
likely we get extra data like
// data.normalised back that we don't need.
- titles: new mw.Title( viewPage.pageName ).toText(),
+ titles: new mw.Title( target.pageName ).toText(),
indexpageids: '',
intoken: 'edit'
} )
.always( function () {
- viewPage.emit( 'saveErrorBadToken' );
+ target.emit( 'saveErrorBadToken' );
} )
.done( function ( data ) {
var userMsg,
@@ -657,7 +657,7 @@
isAnon = mw.user.isAnon();
if ( userInfo && editToken ) {
- viewPage.editToken = editToken;
+ target.editToken = editToken;
if (
( isAnon && userInfo.anon !==
undefined ) ||
@@ -666,7 +666,7 @@
mw.config.get(
'wgUserId' ) === userInfo.id
) {
// New session is the same user
still
- viewPage.save( doc, saveData );
+ target.save( doc, saveData );
} else {
// The now current session is a
different user
if ( userInfo.anon !==
undefined ) {
@@ -678,7 +678,7 @@
// functions
like mw.user.isAnon rely on this.
wgUserName: null
} );
- viewPage.emit(
'saveErrorNewUser', null );
+ target.emit(
'saveErrorNewUser', null );
} else {
// New session is a
different user
mw.config.set( {
wgUserId: userInfo.id, wgUserName: userInfo.name } );
@@ -688,7 +688,7 @@
mw.messages.get( 'visualeditor-savedialog-identify-user' )
.replace( /\$1/g, userInfo.name )
);
- viewPage.emit(
'saveErrorNewUser', userInfo.name );
+ target.emit(
'saveErrorNewUser', userInfo.name );
}
}
}
@@ -1371,8 +1371,7 @@
);
setTimeout( function () {
// Create ui.Surface (also creates ce.Surface and
dm.Surface and builds CE tree)
- var surface = target.createSurface( dmDoc, {
excludeCommands: target.constructor.static.excludeCommands } );
- target.surface = surface;
+ var surface = target.addSurface( dmDoc );
surface.$element.addClass(
've-init-mw-viewPageTarget-surface' )
.addClass( target.protectedClasses );
setTimeout( function () {
@@ -1383,9 +1382,6 @@
surface.getContext().toggle( false );
target.$element.append( surface.$element );
target.setupToolbar();
- if ( ve.debug ) {
- target.setupDebugBar();
- }
// Apply mw-body-content to the view
(ve-ce-surface).
// Not to surface (ve-ui-surface), since that
contains both the view
@@ -1426,15 +1422,15 @@
ve.init.mw.Target.prototype.startSanityCheck = function () {
// We have to get a copy of the data now, before we unlock the surface
and let the user edit,
// but we can defer the actual conversion and comparison
- var viewPage = this,
- doc = viewPage.surface.getModel().getDocument(),
+ var target = this,
+ doc = target.surface.getModel().getDocument(),
data = new ve.dm.FlatLinearData( doc.getStore().clone(),
ve.copy( doc.getFullData() ) ),
- oldDom = viewPage.doc,
+ oldDom = target.doc,
d = $.Deferred();
// Reset
- viewPage.sanityCheckFinished = false;
- viewPage.sanityCheckVerified = false;
+ target.sanityCheckFinished = false;
+ target.sanityCheckVerified = false;
setTimeout( function () {
// We can't compare oldDom.body and newDom.body directly,
because the attributes on the
@@ -1461,15 +1457,15 @@
d.resolve();
} );
- viewPage.sanityCheckPromise = d.promise()
+ target.sanityCheckPromise = d.promise()
.done( function () {
// If we detect no roundtrip errors,
// don't emphasize "review changes" to the user.
- viewPage.sanityCheckVerified = true;
+ target.sanityCheckVerified = true;
})
.always( function () {
- viewPage.sanityCheckFinished = true;
- viewPage.emit( 'sanityCheckComplete' );
+ target.sanityCheckFinished = true;
+ target.emit( 'sanityCheckComplete' );
} );
};
@@ -1481,7 +1477,7 @@
*/
ve.init.mw.Target.prototype.restoreEditSection = function () {
if ( this.section !== undefined && this.section > 0 ) {
- var surfaceView = this.surface.getView(),
+ var surfaceView = this.getSurface().getView(),
$documentNode =
surfaceView.getDocument().getDocumentNode().$element,
$section = $documentNode.find( 'h1, h2, h3, h4, h5, h6'
).eq( this.section - 1 ),
headingNode = $section.data( 'view' );
--
To view, visit https://gerrit.wikimedia.org/r/177129
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I18d6f9f2f36431959d31347b4c1952a1aca1350e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits