Esanders has uploaded a new change for review. https://gerrit.wikimedia.org/r/236346
Change subject: De-duplicate methods in NodeDialog and NodeInspector using mixin ...................................................................... De-duplicate methods in NodeDialog and NodeInspector using mixin Change-Id: I57f984543cd1fc86e892f08f82708332e4dc45e7 --- M build/modules.json M demos/ve/desktop.html M demos/ve/mobile.html M src/ui/dialogs/ve.ui.NodeDialog.js M src/ui/inspectors/ve.ui.NodeInspector.js A src/ui/ve.ui.NodeWindow.js M tests/index.html 7 files changed, 104 insertions(+), 88 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/46/236346/1 diff --git a/build/modules.json b/build/modules.json index e596f29..9894893 100644 --- a/build/modules.json +++ b/build/modules.json @@ -400,6 +400,7 @@ "src/ui/ve.ui.DataTransferHandlerFactory.js", "src/ui/ve.ui.DataTransferItem.js", "src/ui/ve.ui.WindowManager.js", + "src/ui/ve.ui.NodeWindow.js", "src/ui/windowmanagers/ve.ui.SurfaceWindowManager.js", "src/ui/actions/ve.ui.AnnotationAction.js", "src/ui/actions/ve.ui.ContentAction.js", diff --git a/demos/ve/desktop.html b/demos/ve/desktop.html index 6310557..b443ec9 100644 --- a/demos/ve/desktop.html +++ b/demos/ve/desktop.html @@ -362,6 +362,7 @@ <script src="../../src/ui/ve.ui.DataTransferHandlerFactory.js"></script> <script src="../../src/ui/ve.ui.DataTransferItem.js"></script> <script src="../../src/ui/ve.ui.WindowManager.js"></script> + <script src="../../src/ui/ve.ui.NodeWindow.js"></script> <script src="../../src/ui/windowmanagers/ve.ui.SurfaceWindowManager.js"></script> <script src="../../src/ui/actions/ve.ui.AnnotationAction.js"></script> <script src="../../src/ui/actions/ve.ui.ContentAction.js"></script> diff --git a/demos/ve/mobile.html b/demos/ve/mobile.html index eb08fb6..49965ab 100644 --- a/demos/ve/mobile.html +++ b/demos/ve/mobile.html @@ -364,6 +364,7 @@ <script src="../../src/ui/ve.ui.DataTransferHandlerFactory.js"></script> <script src="../../src/ui/ve.ui.DataTransferItem.js"></script> <script src="../../src/ui/ve.ui.WindowManager.js"></script> + <script src="../../src/ui/ve.ui.NodeWindow.js"></script> <script src="../../src/ui/windowmanagers/ve.ui.SurfaceWindowManager.js"></script> <script src="../../src/ui/actions/ve.ui.AnnotationAction.js"></script> <script src="../../src/ui/actions/ve.ui.ContentAction.js"></script> diff --git a/src/ui/dialogs/ve.ui.NodeDialog.js b/src/ui/dialogs/ve.ui.NodeDialog.js index 1a64e4d..d396f13 100644 --- a/src/ui/dialogs/ve.ui.NodeDialog.js +++ b/src/ui/dialogs/ve.ui.NodeDialog.js @@ -9,6 +9,7 @@ * * @class * @extends ve.ui.FragmentDialog + * @mixins ve.ui.NodeWindow * * @constructor * @param {Object} [config] Configuration options @@ -17,48 +18,15 @@ // Parent constructor ve.ui.NodeDialog.super.call( this, config ); - // Properties - this.selectedNode = null; + // Mixin constructor + ve.ui.NodeWindow.call( this ); }; /* Inheritance */ OO.inheritClass( ve.ui.NodeDialog, ve.ui.FragmentDialog ); -/* Static Properties */ - -/** - * Node classes compatible with this dialog. - * - * @static - * @property {Function} - * @inheritable - */ -ve.ui.NodeDialog.static.modelClasses = []; - -/* Methods */ - -/** - * Get the selected node. - * - * Should only be called after setup and before teardown. - * If no node is selected or the selected node is incompatible, null will be returned. - * - * @param {Object} [data] Dialog opening data - * @return {ve.dm.Node|null} Selected node - */ -ve.ui.NodeDialog.prototype.getSelectedNode = function () { - var i, len, - modelClasses = this.constructor.static.modelClasses, - selectedNode = this.getFragment().getSelectedNode(); - - for ( i = 0, len = modelClasses.length; i < len; i++ ) { - if ( selectedNode instanceof modelClasses[ i ] ) { - return selectedNode; - } - } - return null; -}; +OO.mixinClass( ve.ui.NodeDialog, ve.ui.NodeWindow ); /** * @inheritdoc @@ -75,18 +43,18 @@ * @inheritdoc */ ve.ui.NodeDialog.prototype.getSetupProcess = function ( data ) { - return ve.ui.NodeDialog.super.prototype.getSetupProcess.call( this, data ) - .next( function () { - this.selectedNode = this.getSelectedNode( data ); - }, this ); + // Parent method + var process = ve.ui.NodeDialog.super.prototype.getSetupProcess.call( this, data ); + // Mixin method + return ve.ui.NodeWindow.prototype.getSetupProcess.call( this, data, process ); }; /** * @inheritdoc */ ve.ui.NodeDialog.prototype.getTeardownProcess = function ( data ) { - return ve.ui.NodeDialog.super.prototype.getTeardownProcess.call( this, data ) - .first( function () { - this.selectedNode = null; - }, this ); + // Parent method + var process = ve.ui.NodeDialog.super.prototype.getTeardownProcess.call( this, data ); + // Mixin method + return ve.ui.NodeWindow.prototype.getTeardownProcess.call( this, data, process ); }; diff --git a/src/ui/inspectors/ve.ui.NodeInspector.js b/src/ui/inspectors/ve.ui.NodeInspector.js index 5136cd1..7b2dc8a 100644 --- a/src/ui/inspectors/ve.ui.NodeInspector.js +++ b/src/ui/inspectors/ve.ui.NodeInspector.js @@ -9,6 +9,7 @@ * * @class * @extends ve.ui.FragmentInspector + * @mixins ve.ui.NodeWindow * * @constructor * @param {Object} [config] Configuration options @@ -17,48 +18,15 @@ // Parent constructor ve.ui.FragmentInspector.call( this, config ); - // Properties - this.selectedNode = null; + // Mixin constructor + ve.ui.NodeWindow.call( this ); }; /* Inheritance */ OO.inheritClass( ve.ui.NodeInspector, ve.ui.FragmentInspector ); -/* Static Properties */ - -/** - * Node classes compatible with this dialog. - * - * @static - * @property {Function} - * @inheritable - */ -ve.ui.NodeInspector.static.modelClasses = []; - -/* Methods */ - -/** - * Get the selected node. - * - * Should only be called after setup and before teardown. - * If no node is selected or the selected node is incompatible, null will be returned. - * - * @param {Object} [data] Inspector opening data - * @return {ve.dm.Node|null} Selected node - */ -ve.ui.NodeInspector.prototype.getSelectedNode = function () { - var i, len, - modelClasses = this.constructor.static.modelClasses, - selectedNode = this.getFragment().getSelectedNode(); - - for ( i = 0, len = modelClasses.length; i < len; i++ ) { - if ( selectedNode instanceof modelClasses[ i ] ) { - return selectedNode; - } - } - return null; -}; +OO.mixinClass( ve.ui.NodeInspector, ve.ui.NodeWindow ); /** * @inheritdoc @@ -75,18 +43,18 @@ * @inheritdoc */ ve.ui.NodeInspector.prototype.getSetupProcess = function ( data ) { - return ve.ui.NodeInspector.super.prototype.getSetupProcess.call( this, data ) - .next( function () { - this.selectedNode = this.getSelectedNode( data ); - }, this ); + // Parent method + var process = ve.ui.NodeInspector.super.prototype.getSetupProcess.call( this, data ); + // Mixin method + return ve.ui.NodeWindow.prototype.getSetupProcess.call( this, data, process ); }; /** * @inheritdoc */ ve.ui.NodeInspector.prototype.getTeardownProcess = function ( data ) { - return ve.ui.NodeInspector.super.prototype.getTeardownProcess.call( this, data ) - .next( function () { - this.selectedNode = null; - }, this ); + // Parent method + var process = ve.ui.NodeInspector.super.prototype.getTeardownProcess.call( this, data ); + // Mixin method + return ve.ui.NodeWindow.prototype.getTeardownProcess.call( this, data, process ); }; diff --git a/src/ui/ve.ui.NodeWindow.js b/src/ui/ve.ui.NodeWindow.js new file mode 100644 index 0000000..b5b364c --- /dev/null +++ b/src/ui/ve.ui.NodeWindow.js @@ -0,0 +1,76 @@ +/*! + * VisualEditor user interface NodeWindow class. + * + * @copyright 2011-2015 VisualEditor Team and others; see http://ve.mit-license.org + */ + +/** + * Mixin for window for working with a node. + * + * @class + * @abstract + * + * @constructor + * @param {Object} [config] Configuration options + */ +ve.ui.NodeWindow = function VeUiNodeWindow( config ) { + // Properties + this.selectedNode = null; +}; + +/* Inheritance */ + +OO.initClass( ve.ui.NodeWindow ); + +/* Static Properties */ + +/** + * Node classes compatible with this dialog. + * + * @static + * @property {Function} + * @inheritable + */ +ve.ui.NodeWindow.static.modelClasses = []; + +/* Methods */ + +/** + * Get the selected node. + * + * Should only be called after setup and before teardown. + * If no node is selected or the selected node is incompatible, null will be returned. + * + * @param {Object} [data] Window opening data + * @return {ve.dm.Node|null} Selected node + */ +ve.ui.NodeWindow.prototype.getSelectedNode = function () { + var i, len, + modelClasses = this.constructor.static.modelClasses, + selectedNode = this.getFragment().getSelectedNode(); + + for ( i = 0, len = modelClasses.length; i < len; i++ ) { + if ( selectedNode instanceof modelClasses[ i ] ) { + return selectedNode; + } + } + return null; +}; + +/** + * @inheritdoc + */ +ve.ui.NodeWindow.prototype.getSetupProcess = function ( data, process ) { + return process.next( function () { + this.selectedNode = this.getSelectedNode( data ); + }, this ); +}; + +/** + * @inheritdoc + */ +ve.ui.NodeWindow.prototype.getTeardownProcess = function ( data, process ) { + return process.first( function () { + this.selectedNode = null; + }, this ); +}; diff --git a/tests/index.html b/tests/index.html index 67d65e3..eba6e68 100644 --- a/tests/index.html +++ b/tests/index.html @@ -290,6 +290,7 @@ <script src="../src/ui/ve.ui.DataTransferHandlerFactory.js"></script> <script src="../src/ui/ve.ui.DataTransferItem.js"></script> <script src="../src/ui/ve.ui.WindowManager.js"></script> + <script src="../src/ui/ve.ui.NodeWindow.js"></script> <script src="../src/ui/windowmanagers/ve.ui.SurfaceWindowManager.js"></script> <script src="../src/ui/actions/ve.ui.AnnotationAction.js"></script> <script src="../src/ui/actions/ve.ui.ContentAction.js"></script> -- To view, visit https://gerrit.wikimedia.org/r/236346 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I57f984543cd1fc86e892f08f82708332e4dc45e7 Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits