mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
mw.ViewPageTarget: Clean up nested binds and triple model/connect
Change-Id: I67cabfdf0247dd0951b7d4f26c99d621aa2f7b0d
This commit is contained in:
parent
fe40b86e74
commit
b0e8900a02
|
@ -1057,51 +1057,57 @@ ve.init.mw.ViewPageTarget.prototype.setupToolbarBetaNotice = function () {
|
||||||
* @param {Function} [callback] Callback to call when done
|
* @param {Function} [callback] Callback to call when done
|
||||||
*/
|
*/
|
||||||
ve.init.mw.ViewPageTarget.prototype.setUpSurface = function ( doc, callback ) {
|
ve.init.mw.ViewPageTarget.prototype.setUpSurface = function ( doc, callback ) {
|
||||||
setTimeout( ve.bind( function () {
|
var target = this;
|
||||||
|
setTimeout( function () {
|
||||||
// Build linmod
|
// Build linmod
|
||||||
var store = new ve.dm.IndexValueStore(),
|
var store = new ve.dm.IndexValueStore(),
|
||||||
internalList = new ve.dm.InternalList(),
|
internalList = new ve.dm.InternalList(),
|
||||||
data = ve.dm.converter.getDataFromDom( doc, store, internalList );
|
data = ve.dm.converter.getDataFromDom( doc, store, internalList );
|
||||||
setTimeout( ve.bind( function () {
|
setTimeout( function () {
|
||||||
// Build DM tree
|
// Build DM tree
|
||||||
var dmDoc = new ve.dm.Document( data, undefined, internalList );
|
var dmDoc = new ve.dm.Document( data, undefined, internalList );
|
||||||
setTimeout( ve.bind( function () {
|
setTimeout( function () {
|
||||||
// Create ui.Surface (also creates ce.Surface and dm.Surface and builds CE tree)
|
// Create ui.Surface (also creates ce.Surface and dm.Surface and builds CE tree)
|
||||||
this.surface = new ve.ui.Surface( dmDoc, this.surfaceOptions );
|
target.surface = new ve.ui.Surface( dmDoc, target.surfaceOptions );
|
||||||
this.surface.$.addClass( 've-init-mw-viewPageTarget-surface' );
|
target.surface.$.addClass( 've-init-mw-viewPageTarget-surface' );
|
||||||
setTimeout( ve.bind( function () {
|
setTimeout( function () {
|
||||||
// Initialize surface
|
// Initialize surface
|
||||||
this.surface.connect( this, { 'toolbarPosition': 'onSurfaceToolbarPosition' } );
|
target.surface.connect( target, { 'toolbarPosition': 'onSurfaceToolbarPosition' } );
|
||||||
this.surface.getContext().hide();
|
target.surface.getContext().hide();
|
||||||
this.$document = this.surface.$.find( '.ve-ce-documentNode' );
|
target.$document = target.surface.$.find( '.ve-ce-documentNode' );
|
||||||
this.surface.getModel().connect( this, { 'transact': 'onSurfaceModelTransact' } );
|
target.surface.getModel().connect( target, {
|
||||||
this.surface.getModel().connect( this, { 'change': 'onSurfaceModelChange' } );
|
'transact': 'onSurfaceModelTransact',
|
||||||
this.surface.getModel().connect( this, { 'history': 'updateToolbarSaveButtonState' } );
|
'change': 'onSurfaceModelChange',
|
||||||
this.$.append( this.surface.$ );
|
'history': 'updateToolbarSaveButtonState'
|
||||||
this.setUpToolbar();
|
} );
|
||||||
this.transformPageTitle();
|
target.$.append( target.surface.$ );
|
||||||
this.changeDocumentTitle();
|
target.setUpToolbar();
|
||||||
|
target.transformPageTitle();
|
||||||
|
target.changeDocumentTitle();
|
||||||
|
|
||||||
// Update UI
|
// Update UI
|
||||||
this.hidePageContent();
|
target.hidePageContent();
|
||||||
this.hideSpinner();
|
target.hideSpinner();
|
||||||
this.active = true;
|
target.active = true;
|
||||||
this.$document.attr( {
|
target.$document.attr( {
|
||||||
'lang': mw.config.get( 'wgVisualEditor' ).pageLanguageCode,
|
'lang': mw.config.get( 'wgVisualEditor' ).pageLanguageCode,
|
||||||
'dir': mw.config.get( 'wgVisualEditor' ).pageLanguageDir
|
'dir': mw.config.get( 'wgVisualEditor' ).pageLanguageDir
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Add appropriately mw-content-ltr or mw-content-rtl class
|
// Add appropriately mw-content-ltr or mw-content-rtl class
|
||||||
this.surface.view.$.addClass(
|
target.surface.view.$.addClass(
|
||||||
'mw-content-' + mw.config.get( 'wgVisualEditor' ).pageLanguageDir
|
'mw-content-' + mw.config.get( 'wgVisualEditor' ).pageLanguageDir
|
||||||
);
|
);
|
||||||
this.surface.initialize();
|
|
||||||
|
// Now that the surface is attached to the document and ready,
|
||||||
|
// let it initialize itself
|
||||||
|
target.surface.initialize();
|
||||||
|
|
||||||
setTimeout( callback );
|
setTimeout( callback );
|
||||||
}, this ) );
|
} );
|
||||||
}, this ) );
|
} );
|
||||||
}, this ) );
|
} );
|
||||||
}, this ) );
|
} );
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue