Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/180301
Change subject: Remove use of bind() for inline functions
......................................................................
Remove use of bind() for inline functions
Follows-up b0e8900, 447e8de, d3f26e65.
Contrary to binding a reference, this-overiddes for inline
functions gets messy and fragile. There's also a minor
performance overhead that can be avoided. No separation of
concerns, eiter, as the object is held by the closure.
Also:
* Remove left-over instances of @method.
* Remove redundant '0' argument to setTimeout.
* Use null instead of $ for apply() on static methods like $.when.
* Use .empty().append() instead of .html(). Does the same but
without additional overhead and without confusion association
with "html" which isn't used (it doesn't serialise and re-parse
or clone, it just appends when given one or more nodes).
Change-Id: I797a3667c67d52568150be9be5d043d149f22077
---
M modules/ve-mw/ce/nodes/ve.ce.MWExtensionNode.js
M modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
M modules/ve-mw/init/ve.init.mw.Target.js
M modules/ve-mw/ui/dialogs/ve.ui.MWCitationDialog.js
M modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js
M modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js
M modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js
M modules/ve-mw/ui/pages/ve.ui.MWCategoriesPage.js
M modules/ve-mw/ui/tools/ve.ui.MWPopupTool.js
M modules/ve-mw/ui/widgets/ve.ui.MWCategoryInputWidget.js
M modules/ve-mw/ui/widgets/ve.ui.MWTocItemWidget.js
M modules/ve-mw/ui/widgets/ve.ui.MWTocWidget.js
12 files changed, 177 insertions(+), 182 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/01/180301/1
diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWExtensionNode.js
b/modules/ve-mw/ce/nodes/ve.ce.MWExtensionNode.js
index 371d42a..a241e49 100644
--- a/modules/ve-mw/ce/nodes/ve.ce.MWExtensionNode.js
+++ b/modules/ve-mw/ce/nodes/ve.ce.MWExtensionNode.js
@@ -85,11 +85,12 @@
/** */
ve.ce.MWExtensionNode.prototype.afterRender = function () {
+ var node = this;
// Rerender after images load
// TODO: ignore shields, and count multiple images
this.$element.find( 'img' ).on( 'load', function () {
- this.emit( 'rerender' );
- }.bind( this ) );
+ node.emit( 'rerender' );
+ } );
};
/**
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 5c1f820..38888b1 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
@@ -181,7 +181,9 @@
* @inheritdoc
*/
ve.init.mw.ViewPageTarget.prototype.setupToolbar = function ( surface ) {
- var $firstHeading;
+ var $firstHeading,
+ target = this;
+
// Parent method
ve.init.mw.Target.prototype.setupToolbar.call( this, surface );
@@ -205,19 +207,17 @@
this.getToolbar().$bar.slideDown( 'fast', function () {
// Check the surface wasn't torn down while the toolbar was
animating
- if ( this.getSurface() ) {
- this.getToolbar().initialize();
- this.getSurface().getView().emit( 'position' );
- this.getSurface().getContext().updateDimensions();
+ if ( target.getSurface() ) {
+ target.getToolbar().initialize();
+ target.getSurface().getView().emit( 'position' );
+ target.getSurface().getContext().updateDimensions();
}
- }.bind( this ) );
+ } );
};
/**
* Set up notices for things like unknown browsers.
- * Needs to be done on each activation because localNoticeMessages is cleared
in clearState
- *
- * @method
+ * Needs to be done on each activation because localNoticeMessages is cleared
in clearState.
*/
ve.init.mw.ViewPageTarget.prototype.setupLocalNoticeMessages = function () {
if ( mw.config.get( 'wgTranslatePageTranslation' ) === 'source' ) {
@@ -238,7 +238,6 @@
/**
* Switch to edit mode.
*
- * @method
* @return {jQuery.Promise}
*/
ve.init.mw.ViewPageTarget.prototype.activate = function () {
@@ -304,7 +303,9 @@
* @param {string} [trackMechanism] Abort mechanism; used for event tracking
if present
*/
ve.init.mw.ViewPageTarget.prototype.cancel = function ( trackMechanism ) {
- var abortType, promises = [];
+ var abortType,
+ target = this,
+ promises = [];
// Event tracking
if ( trackMechanism ) {
@@ -354,26 +355,26 @@
promises.push( this.tearDownSurface() );
}
- $.when.apply( $, promises ).then( function () {
+ $.when.apply( null, promises ).done( function () {
// Show/restore components that are otherwise handled by
tearDownSurface
- this.showPageContent();
- this.restorePageTitle();
+ target.showPageContent();
+ target.restorePageTitle();
// If there is a load in progress, abort it
- if ( this.loading ) {
- this.loading.abort();
+ if ( target.loading ) {
+ target.loading.abort();
}
- this.clearState();
- this.docToSave = null;
- this.initialEditSummary = new mw.Uri().query.summary;
+ target.clearState();
+ target.docToSave = null;
+ target.initialEditSummary = new mw.Uri().query.summary;
- this.deactivating = false;
- this.activating = false;
- this.activatingDeferred.reject();
+ target.deactivating = false;
+ target.activating = false;
+ target.activatingDeferred.reject();
- mw.hook( 've.deactivationComplete' ).fire( this.edited );
- }.bind( this ) );
+ mw.hook( 've.deactivationComplete' ).fire( target.edited );
+ } );
};
/**
@@ -1013,11 +1014,11 @@
/**
* Switch to viewing mode.
*
- * @method
* @return {jQuery.Promise} Promise resolved when surface is torn down
*/
ve.init.mw.ViewPageTarget.prototype.tearDownSurface = function () {
- var promises = [];
+ var target = this,
+ promises = [];
// Update UI
this.tearDownToolbar();
@@ -1036,13 +1037,13 @@
this.saveDialog = null;
}
- return $.when.apply( $, promises ).then( function () {
+ return $.when.apply( null, promises ).then( function () {
// Destroy surface
- while ( this.surfaces.length ) {
- this.surfaces.pop().destroy();
+ while ( target.surfaces.length ) {
+ target.surfaces.pop().destroy();
}
- this.active = false;
- }.bind( this ) );
+ target.active = false;
+ } );
};
/**
@@ -1085,8 +1086,6 @@
/**
* Add content and event bindings to toolbar save button.
- *
- * @method
*/
ve.init.mw.ViewPageTarget.prototype.setupToolbarSaveButton = function () {
this.toolbarSaveButton = new OO.ui.ButtonWidget( {
@@ -1112,8 +1111,6 @@
/**
* Add the save button to the user interface.
- *
- * @method
*/
ve.init.mw.ViewPageTarget.prototype.attachToolbarSaveButton = function () {
var $actionTools = $( '<div>' ),
@@ -1144,15 +1141,14 @@
/**
* Show the save dialog.
*
- * @method
* @fires saveWorkflowBegin
*/
ve.init.mw.ViewPageTarget.prototype.showSaveDialog = function () {
+ var target = this;
this.emit( 'saveWorkflowBegin' );
- this.getSurface().getDialogs().getWindow( 'mwSave' ).then( function (
win ) {
- var currentWindow =
this.getSurface().getContext().getInspectors().getCurrentWindow(),
- target = this;
- this.origSelection =
this.getSurface().getModel().getSelection();
+ this.getSurface().getDialogs().getWindow( 'mwSave' ).done( function (
win ) {
+ var currentWindow =
target.getSurface().getContext().getInspectors().getCurrentWindow();
+ target.origSelection =
target.getSurface().getModel().getSelection();
// Make sure any open inspectors are closed
if ( currentWindow ) {
@@ -1160,36 +1156,35 @@
}
// Preload the serialization
- if ( !this.docToSave ) {
- this.docToSave = ve.dm.converter.getDomFromModel(
this.getSurface().getModel().getDocument() );
+ if ( !target.docToSave ) {
+ target.docToSave = ve.dm.converter.getDomFromModel(
target.getSurface().getModel().getDocument() );
}
- this.prepareCacheKey( this.docToSave );
+ target.prepareCacheKey( target.docToSave );
- if ( !this.saveDialog ) {
- this.saveDialog = win;
+ if ( !target.saveDialog ) {
+ target.saveDialog = win;
// Connect to save dialog
- this.saveDialog.connect( this, {
+ target.saveDialog.connect( target, {
save: 'saveDocument',
review: 'onSaveDialogReview',
resolve: 'onSaveDialogResolveConflict',
retry: 'onSaveRetry'
} );
// Setup edit summary and checkboxes
- this.saveDialog.setEditSummary( this.initialEditSummary
);
- this.saveDialog.setupCheckboxes( this.$checkboxes );
+ target.saveDialog.setEditSummary(
target.initialEditSummary );
+ target.saveDialog.setupCheckboxes( target.$checkboxes );
}
- this.saveDialog.setSanityCheck( this.sanityCheckVerified );
- this.getSurface().getDialogs().openWindow(
- this.saveDialog,
- { dir:
this.getSurface().getModel().getDocument().getLang() }
- )
+ target.saveDialog.setSanityCheck( target.sanityCheckVerified );
+ target.getSurface().getDialogs().openWindow(
+ target.saveDialog,
+ { dir:
target.getSurface().getModel().getDocument().getLang() }
+ ).done( function ( opened ) {
// Call onSaveDialogClose() when the save dialog starts
closing
- .done( function ( opened ) {
- opened.always( target.onSaveDialogClose.bind(
target ) );
- } );
- }.bind( this ) );
+ opened.always( target.onSaveDialogClose.bind( target )
);
+ } );
+ } );
};
/**
@@ -1198,24 +1193,26 @@
* @fires saveWorkflowEnd
*/
ve.init.mw.ViewPageTarget.prototype.onSaveDialogClose = function () {
+ var target = this;
+
+ function clear() {
+ target.docToSave = null;
+ target.clearPreparedCacheKey();
+ }
+
// Clear the cached HTML and cache key once the document changes
- var clear = function () {
- this.docToSave = null;
- this.clearPreparedCacheKey();
- }.bind( this );
if ( this.getSurface() ) {
this.getSurface().getModel().getDocument().once( 'transact',
clear );
} else {
clear();
}
+
this.getSurface().getModel().setSelection( this.origSelection );
this.emit( 'saveWorkflowEnd' );
};
/**
* Remember the window's scroll position.
- *
- * @method
*/
ve.init.mw.ViewPageTarget.prototype.saveScrollPosition = function () {
this.scrollTop = $( window ).scrollTop();
@@ -1223,8 +1220,6 @@
/**
* Restore the window's scroll position.
- *
- * @method
*/
ve.init.mw.ViewPageTarget.prototype.restoreScrollPosition = function () {
if ( this.scrollTop ) {
@@ -1304,34 +1299,30 @@
/**
* Hide the toolbar.
- *
- * @method
*/
ve.init.mw.ViewPageTarget.prototype.tearDownToolbar = function () {
+ var target = this;
this.toolbar.$bar.slideUp( 'fast', function () {
- this.toolbar.destroy();
- this.toolbar = null;
- }.bind( this ) );
+ target.toolbar.destroy();
+ target.toolbar = null;
+ } );
};
/**
* Hide the debug bar.
- *
- * @method
*/
ve.init.mw.ViewPageTarget.prototype.tearDownDebugBar = function () {
+ var target = this;
if ( this.debugBar ) {
this.debugBar.$element.slideUp( 'fast', function () {
- this.debugBar.$element.remove();
- this.debugBar = null;
- }.bind( this ) );
+ target.debugBar.$element.remove();
+ target.debugBar = null;
+ } );
}
};
/**
* Transform the page title into a VE-style title.
- *
- * @method
*/
ve.init.mw.ViewPageTarget.prototype.transformPageTitle = function () {
$( '#firstHeading' ).addClass( 've-init-mw-viewPageTarget-pageTitle' );
@@ -1339,8 +1330,6 @@
/**
* Fade the page title to indicate it is not editable.
- *
- * @method
*/
ve.init.mw.ViewPageTarget.prototype.mutePageTitle = function () {
$( '#firstHeading, #siteSub' )
@@ -1349,8 +1338,6 @@
/**
* Restore the page title to its original style.
- *
- * @method
*/
ve.init.mw.ViewPageTarget.prototype.restorePageTitle = function () {
var $els = $( '#firstHeading, #siteSub' )
@@ -1364,8 +1351,6 @@
/**
* Change the document title to state that we are now editing.
- *
- * @method
*/
ve.init.mw.ViewPageTarget.prototype.changeDocumentTitle = function () {
document.title = ve.msg(
@@ -1376,8 +1361,6 @@
/**
* Restore the original document title.
- *
- * @method
*/
ve.init.mw.ViewPageTarget.prototype.restoreDocumentTitle = function () {
document.title = this.originalDocumentTitle;
@@ -1716,6 +1699,7 @@
* @param {boolean} [discardChanges] Whether to discard changes or not.
*/
ve.init.mw.ViewPageTarget.prototype.switchToWikitextEditor = function (
discardChanges ) {
+ var target = this;
if ( discardChanges ) {
ve.track( 'mwedit.abort', { type: 'switchwithout', mechanism:
'navigate' } );
this.submitting = true;
@@ -1728,8 +1712,8 @@
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 );
- }.bind( this )
+ target.submitWithSaveFields( { wpDiff: 1,
veswitched: 1 }, wikitext );
+ }
);
}
};
diff --git a/modules/ve-mw/init/ve.init.mw.Target.js
b/modules/ve-mw/init/ve.init.mw.Target.js
index 9b79b64..c1a425f 100644
--- a/modules/ve-mw/init/ve.init.mw.Target.js
+++ b/modules/ve-mw/init/ve.init.mw.Target.js
@@ -511,14 +511,15 @@
* @fires surfaceReady
*/
ve.init.mw.Target.prototype.onReady = function () {
+ var target = this;
// We need to wait until onReady as local notices may require special
messages
this.onNoticesReady();
this.loading = false;
this.edited = false;
this.setupSurface( this.doc, function () {
- this.startSanityCheck();
- this.emit( 'surfaceReady' );
- }.bind( this ) );
+ target.startSanityCheck();
+ target.emit( 'surfaceReady' );
+ } );
};
/**
diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWCitationDialog.js
b/modules/ve-mw/ui/dialogs/ve.ui.MWCitationDialog.js
index a8e1881..6b11996 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWCitationDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWCitationDialog.js
@@ -129,12 +129,13 @@
* @inheritdoc
*/
ve.ui.MWCitationDialog.prototype.onAddParameterBeforeLoad = function ( page ) {
- var hasUsefulParameter = this.hasUsefulParameter();
+ var dialog = this,
+ hasUsefulParameter = this.hasUsefulParameter();
page.preLoad = true;
page.valueInput.on( 'change', function () {
- this.actions.setAbilities( { apply: hasUsefulParameter, insert:
hasUsefulParameter } );
- }.bind( this ) );
+ dialog.actions.setAbilities( { apply: hasUsefulParameter,
insert: hasUsefulParameter } );
+ } );
};
/**
@@ -159,34 +160,35 @@
* @inheritdoc
*/
ve.ui.MWCitationDialog.prototype.getActionProcess = function ( action ) {
+ var dialog = this;
if ( action === 'apply' || action === 'insert' ) {
return new OO.ui.Process( function () {
var deferred = $.Deferred();
- this.checkRequiredParameters().done( function () {
+ dialog.checkRequiredParameters().done( function () {
var item,
- surfaceModel =
this.getFragment().getSurface(),
+ surfaceModel =
dialog.getFragment().getSurface(),
doc = surfaceModel.getDocument(),
internalList = doc.getInternalList(),
- obj =
this.transclusionModel.getPlainObject();
+ obj =
dialog.transclusionModel.getPlainObject();
- if ( !this.referenceModel ) {
- // Collapse returns a new fragment, so
update this.fragment
- this.fragment =
this.getFragment().collapseToEnd();
- this.referenceModel = new
ve.dm.MWReferenceModel();
- this.referenceModel.setDir(
doc.getDir() );
- this.referenceModel.setLang(
doc.getLang() );
- this.referenceModel.insertInternalItem(
surfaceModel );
-
this.referenceModel.insertReferenceNode( this.getFragment() );
+ if ( !dialog.referenceModel ) {
+ // Collapse returns a new fragment, so
update dialog.fragment
+ dialog.fragment =
dialog.getFragment().collapseToEnd();
+ dialog.referenceModel = new
ve.dm.MWReferenceModel();
+ dialog.referenceModel.setDir(
doc.getDir() );
+ dialog.referenceModel.setLang(
doc.getLang() );
+
dialog.referenceModel.insertInternalItem( surfaceModel );
+
dialog.referenceModel.insertReferenceNode( dialog.getFragment() );
}
- item = this.referenceModel.findInternalItem(
surfaceModel );
+ item = dialog.referenceModel.findInternalItem(
surfaceModel );
if ( item ) {
- if ( this.selectedNode ) {
-
this.transclusionModel.updateTransclusionNode(
- surfaceModel,
this.selectedNode
+ if ( dialog.selectedNode ) {
+
dialog.transclusionModel.updateTransclusionNode(
+ surfaceModel,
dialog.selectedNode
);
} else if ( obj !== null ) {
-
this.transclusionModel.insertTransclusionNode(
+
dialog.transclusionModel.insertTransclusionNode(
// HACK: This is trying
to place the cursor inside the first content branch
// node but this
theoretically not a safe assumption - in practice, the
// citation dialog will
only reach this code if we are inserting (not
@@ -194,7 +196,7 @@
// initialized the
internal node with a paragraph - getting the range of the
// item covers the
entire paragraph so we have to get the range of it's
// first (and empty)
child
-
this.getFragment().clone(
+
dialog.getFragment().clone(
new
ve.dm.LinearSelection( doc, item.getChildren()[0].getRange() )
)
);
@@ -203,20 +205,18 @@
// HACK: Scorch the earth - this is only needed
because without it, the references list
// won't re-render properly, and can be removed
once someone fixes that
- this.referenceModel.setDocument(
+ dialog.referenceModel.setDocument(
doc.cloneFromRange(
- internalList.getItemNode(
this.referenceModel.getListIndex() ).getRange()
+ internalList.getItemNode(
dialog.referenceModel.getListIndex() ).getRange()
)
);
- this.referenceModel.updateInternalItem(
surfaceModel );
+ dialog.referenceModel.updateInternalItem(
surfaceModel );
- this.close( { action: action } );
- }.bind( this ) ).always( function () {
- deferred.resolve();
- } );
+ dialog.close( { action: action } );
+ } ).always( deferred.resolve );
return deferred;
- }, this );
+ } );
}
// Parent method
diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js
b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js
index 84ed6c1..7b96970 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js
@@ -649,6 +649,7 @@
* @param {string} panel Panel name
*/
ve.ui.MWMediaDialog.prototype.switchPanels = function ( panel ) {
+ var dialog = this;
switch ( panel ) {
case 'edit':
// Set the edit panel
@@ -677,21 +678,21 @@
// Get the repos from the API first
// The ajax request will only be done once per session
- this.getFileRepos().done( function ( repos ) {
- this.search.setSources( repos );
+ dialog.getFileRepos().done( function ( repos ) {
+ dialog.search.setSources( repos );
// Done, hide the spinner
- this.$spinner.hide();
+ dialog.$spinner.hide();
// Show the search and query the media sources
- this.search.$element.show();
- this.search.query.setValue( this.pageTitle );
- this.search.queryMediaSources();
+ dialog.search.$element.show();
+ dialog.search.query.setValue( dialog.pageTitle
);
+ dialog.search.queryMediaSources();
// Initialization
// This must be done only after there are proper
// sources defined
- this.search.getQuery().focus().select();
- this.search.getResults().selectItem();
- this.search.getResults().highlightItem();
- }.bind( this ) );
+ dialog.search.getQuery().focus().select();
+ dialog.search.getResults().selectItem();
+ dialog.search.getResults().highlightItem();
+ } );
// Set the edit panel
this.panels.setItem( this.mediaSearchPanel );
diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js
b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js
index e4a3730..2af2be0 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js
@@ -313,15 +313,17 @@
* @param {jQuery} $checkboxes jQuery collection of checkboxes
*/
ve.ui.MWSaveDialog.prototype.setupCheckboxes = function ( $checkboxes ) {
+ var dialog = this;
this.setupDeferred.done( function () {
- this.$saveOptions.find( '.ve-ui-mwSaveDialog-checkboxes' )
- .html( $checkboxes )
+ dialog.$saveOptions.find( '.ve-ui-mwSaveDialog-checkboxes' )
+ .empty()
+ .append( $checkboxes )
.find( 'a' )
.attr( 'target', '_blank' )
.end()
.find( 'input' )
.prop( 'tabIndex', 0 );
- }.bind( this ) );
+ } );
};
/**
@@ -332,16 +334,18 @@
* @param {string} summary Edit summary to prefill
*/
ve.ui.MWSaveDialog.prototype.setEditSummary = function ( summary ) {
+ var dialog = this;
this.setupDeferred.done( function () {
- this.editSummaryInput.setValue( summary );
- }.bind( this ) );
+ dialog.editSummaryInput.setValue( summary );
+ } );
};
/**
* @inheritdoc
*/
ve.ui.MWSaveDialog.prototype.initialize = function () {
- var saveAccessKey;
+ var saveAccessKey,
+ dialog = this;
// Parent method
ve.ui.MWSaveDialog.super.prototype.initialize.call( this );
@@ -377,10 +381,10 @@
// TODO: This looks a bit weird, there is no unit in the UI,
just numbers
// Users likely assume characters but then it seems to count
down quicker
// than expected. Facing users with the word "byte" is bad?
(bug 40035)
- this.editSummaryCountLabel.setLabel(
- String( this.editSummaryByteLimit - $.byteLength(
this.editSummaryInput.getValue() ) )
+ dialog.editSummaryCountLabel.setLabel(
+ String( dialog.editSummaryByteLimit - $.byteLength(
dialog.editSummaryInput.getValue() ) )
);
- }.bind( this ) );
+ } );
this.$saveOptions = this.$( '<div>' ).addClass(
've-ui-mwSaveDialog-options' ).append(
this.$( '<div>' ).addClass( 've-ui-mwSaveDialog-checkboxes' ),
diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js
b/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js
index 7dec781..b960c0c 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js
@@ -395,28 +395,27 @@
* @inheritdoc
*/
ve.ui.MWTemplateDialog.prototype.getActionProcess = function ( action ) {
+ var dialog = this;
if ( action === 'apply' || action === 'insert' ) {
return new OO.ui.Process( function () {
var deferred = $.Deferred();
- this.checkRequiredParameters().done( function () {
- var surfaceModel =
this.getFragment().getSurface(),
- obj =
this.transclusionModel.getPlainObject();
+ dialog.checkRequiredParameters().done( function () {
+ var surfaceModel =
dialog.getFragment().getSurface(),
+ obj =
dialog.transclusionModel.getPlainObject();
- if ( this.selectedNode instanceof
ve.dm.MWTransclusionNode ) {
-
this.transclusionModel.updateTransclusionNode( surfaceModel, this.selectedNode
);
+ if ( dialog.selectedNode instanceof
ve.dm.MWTransclusionNode ) {
+
dialog.transclusionModel.updateTransclusionNode( surfaceModel,
dialog.selectedNode );
} else if ( obj !== null ) {
- // Collapse returns a new fragment, so
update this.fragment
- this.fragment =
this.getFragment().collapseToEnd();
-
this.transclusionModel.insertTransclusionNode( this.getFragment() );
+ // Collapse returns a new fragment, so
update dialog.fragment
+ dialog.fragment =
dialog.getFragment().collapseToEnd();
+
dialog.transclusionModel.insertTransclusionNode( dialog.getFragment() );
}
- this.close( { action: action } );
- }.bind( this ) ).always( function () {
- deferred.resolve();
- } );
+ dialog.close( { action: action } );
+ } ).always( deferred.resolve );
return deferred;
- }, this );
+ } );
}
return ve.ui.MWTemplateDialog.super.prototype.getActionProcess.call(
this, action );
@@ -470,8 +469,6 @@
/**
* Initialize parameters for new template insertion
- *
- * @method
*/
ve.ui.MWTemplateDialog.prototype.initializeNewTemplateParameters = function ()
{
var i, parts = this.transclusionModel.getParts();
@@ -484,8 +481,6 @@
/**
* Intentionally empty. This is provided for Wikia extensibility.
- *
- * @method
*/
ve.ui.MWTemplateDialog.prototype.initializeTemplateParameters = function () {};
@@ -496,8 +491,8 @@
return ve.ui.MWTemplateDialog.super.prototype.getReadyProcess.call(
this, data )
.next( function () {
// TODO: Uncomment this when OOUI is updated so
.focus() on an empty booklet doesn't crash
- //this.bookletLayout.focus();
- }, this );
+ //dialog.bookletLayout.focus();
+ } );
};
/**
diff --git a/modules/ve-mw/ui/pages/ve.ui.MWCategoriesPage.js
b/modules/ve-mw/ui/pages/ve.ui.MWCategoriesPage.js
index b93c686..dd23f22 100644
--- a/modules/ve-mw/ui/pages/ve.ui.MWCategoriesPage.js
+++ b/modules/ve-mw/ui/pages/ve.ui.MWCategoriesPage.js
@@ -230,13 +230,16 @@
* @param {Object} [data] Dialog setup data
*/
ve.ui.MWCategoriesPage.prototype.setup = function ( metaList ) {
+ var defaultSortKeyItem,
+ page = this;
+
this.metaList = metaList;
this.metaList.connect( this, {
insert: 'onMetaListInsert',
remove: 'onMetaListRemove'
} );
- var defaultSortKeyItem = this.getDefaultSortKeyItem();
+ defaultSortKeyItem = this.getDefaultSortKeyItem();
this.categoryWidget.addItems( this.getCategoryItems() );
@@ -247,8 +250,8 @@
// Update input position once visible
setTimeout( function () {
- this.categoryWidget.fitInput();
- }.bind( this ) );
+ page.categoryWidget.fitInput();
+ } );
};
/**
diff --git a/modules/ve-mw/ui/tools/ve.ui.MWPopupTool.js
b/modules/ve-mw/ui/tools/ve.ui.MWPopupTool.js
index 7686f2a..181c434 100644
--- a/modules/ve-mw/ui/tools/ve.ui.MWPopupTool.js
+++ b/modules/ve-mw/ui/tools/ve.ui.MWPopupTool.js
@@ -16,6 +16,7 @@
*/
ve.ui.MWNoticesPopupTool = function VeUiMWNoticesPopupTool( toolGroup, config
) {
var key,
+ tool = this,
items = toolGroup.getToolbar().getTarget().getEditNotices(),
count = ve.getObjectKeys( items ).length,
title = ve.msg( 'visualeditor-editnotices-tool', count );
@@ -41,11 +42,11 @@
this.popup.$body.append( this.$items );
- // Automatically show/hide
+ // Automatically show
if ( count ) {
setTimeout( function () {
- this.popup.toggle( true );
- }.bind( this ), 500 );
+ tool.popup.toggle( true );
+ }, 500 );
} else {
this.$element = $( [] );
}
diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWCategoryInputWidget.js
b/modules/ve-mw/ui/widgets/ve.ui.MWCategoryInputWidget.js
index 364ce62..29e376c 100644
--- a/modules/ve-mw/ui/widgets/ve.ui.MWCategoryInputWidget.js
+++ b/modules/ve-mw/ui/widgets/ve.ui.MWCategoryInputWidget.js
@@ -98,7 +98,8 @@
* @inheritdoc
*/
ve.ui.MWCategoryInputWidget.prototype.getLookupMenuItemsFromData = function (
data ) {
- var exactMatch = false,
+ var widget = this,
+ exactMatch = false,
itemWidgets = [],
existingCategoryItems = [], matchingCategoryItems = [],
hiddenCategoryItems = [], newCategoryItems = [],
@@ -138,7 +139,7 @@
matchingCategoryItems.push( suggestedCategory );
}
}
- }.bind( this ) );
+ } );
// Existing categories
$.each( existingCategories, function ( index, existingCategory ) {
@@ -184,15 +185,15 @@
], function ( index, sectionData ) {
if ( sectionData.items.length ) {
itemWidgets.push( new OO.ui.MenuSectionOptionWidget( {
- $: this.lookupMenu.$,
+ $: widget.lookupMenu.$,
data: sectionData.id,
label: sectionData.label
} ) );
$.each( sectionData.items, function ( index,
categoryItem ) {
- itemWidgets.push(
this.getCategoryWidgetFromName( categoryItem ) );
- }.bind( this ) );
+ itemWidgets.push(
widget.getCategoryWidgetFromName( categoryItem ) );
+ } );
}
- }.bind( this ) );
+ } );
return itemWidgets;
};
diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTocItemWidget.js
b/modules/ve-mw/ui/widgets/ve.ui.MWTocItemWidget.js
index fb079b1..ba1eb71 100644
--- a/modules/ve-mw/ui/widgets/ve.ui.MWTocItemWidget.js
+++ b/modules/ve-mw/ui/widgets/ve.ui.MWTocItemWidget.js
@@ -72,10 +72,11 @@
*
*/
ve.ui.MWTocItemWidget.prototype.onUpdate = function () {
+ var widget = this;
// Timeout needed to let the dom element actually update
setTimeout( function () {
- this.$tocText.text( this.node.$element.text() );
- }.bind( this ), 0 );
+ widget.$tocText.text( widget.node.$element.text() );
+ } );
};
/**
diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTocWidget.js
b/modules/ve-mw/ui/widgets/ve.ui.MWTocWidget.js
index f605bc2..dc39686 100644
--- a/modules/ve-mw/ui/widgets/ve.ui.MWTocWidget.js
+++ b/modules/ve-mw/ui/widgets/ve.ui.MWTocWidget.js
@@ -16,6 +16,8 @@
* @param {Object} [config] Configuration options
*/
ve.ui.MWTocWidget = function VeUiMWTocWidget( surface, config ) {
+ var widget = this;
+
// Parent constructor
OO.ui.Widget.call( this, config );
@@ -53,15 +55,15 @@
$( '#bodyContent' ).append( this.$element );
this.toggle.$link.on( 'click', function () {
- if ( this.toggle.open ) {
- this.toggle.$link.text( this.toggle.showMsg );
- this.toggle.open = false;
+ if ( widget.toggle.open ) {
+ widget.toggle.$link.text( widget.toggle.showMsg );
+ widget.toggle.open = false;
} else {
- this.toggle.$link.text( this.toggle.hideMsg );
- this.toggle.open = true;
+ widget.toggle.$link.text( widget.toggle.hideMsg );
+ widget.toggle.open = true;
}
- this.topics.$group.add( this.$tempTopics ).slideToggle();
- }.bind( this ) );
+ widget.topics.$group.add( widget.$tempTopics ).slideToggle();
+ } );
this.metaList.connect( this, {
insert: 'onMetaListInsert',
@@ -146,15 +148,16 @@
* Rebuilds on both teardown and setup of a node, so rebuild is debounced
*/
ve.ui.MWTocWidget.prototype.rebuild = ve.debounce( function () {
+ var widget = this;
// Only rebuild when initialized
if ( this.surface.mwTocWidget.initialized ) {
this.$tempTopics.append( this.topics.$group.children().clone()
);
this.teardownItems();
// Build after transactions
setTimeout( function () {
- this.build();
- this.$tempTopics.empty();
- }.bind( this ), 0 );
+ widget.build();
+ widget.$tempTopics.empty();
+ }, 0 );
}
}, 0 );
--
To view, visit https://gerrit.wikimedia.org/r/180301
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I797a3667c67d52568150be9be5d043d149f22077
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits