From 741dbe5ccf51b0953323cd6c121af5f6fa2f6f2a Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Fri, 22 Jul 2022 15:10:46 +0200 Subject: [PATCH] Minor code cleanups in forked BookletLayout and related E.g. renaming variables and moving code around. No functional change. Change-Id: I39e76356c62a0d1bcdf1d20bc8215f09604ad07d --- .../ui/dialogs/ve.ui.MWTransclusionDialog.js | 6 ++-- ...ve.ui.MWTwoPaneTransclusionDialogLayout.js | 28 ++++++++----------- .../ve.ui.MWTransclusionOutlineWidget.js | 2 +- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js index e6292a79e1..c7145a3cbf 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js @@ -89,7 +89,7 @@ ve.ui.MWTransclusionDialog.prototype.onOutlineControlsMove = function ( places ) // Move part to new location, and if dialog is loaded switch to new part page var promise = this.transclusionModel.addPart( part, newPlace ); if ( this.loaded && !this.preventReselection ) { - // FIXME: Should be handled internally to bookletLayout. + // FIXME: Should be handled internally {@see ve.ui.MWTwoPaneTransclusionDialogLayout} promise.done( this.bookletLayout.focusPart.bind( this.bookletLayout, part.getId() ) ); } }; @@ -109,8 +109,8 @@ ve.ui.MWTransclusionDialog.prototype.onOutlineControlsRemove = function () { return; } - var itemId = this.bookletLayout.getSelectedTopLevelPartId(), - part = this.transclusionModel.getPartFromId( itemId ); + var partId = this.bookletLayout.getSelectedTopLevelPartId(), + part = this.transclusionModel.getPartFromId( partId ); if ( part ) { this.transclusionModel.removePart( part ); } diff --git a/modules/ve-mw/ui/layouts/ve.ui.MWTwoPaneTransclusionDialogLayout.js b/modules/ve-mw/ui/layouts/ve.ui.MWTwoPaneTransclusionDialogLayout.js index 13289c4ea5..bf24f335b7 100644 --- a/modules/ve-mw/ui/layouts/ve.ui.MWTwoPaneTransclusionDialogLayout.js +++ b/modules/ve-mw/ui/layouts/ve.ui.MWTwoPaneTransclusionDialogLayout.js @@ -1,6 +1,6 @@ /** - * Specialized layout similar to BookletLayout, but to synchronize the sidebar - * and content pane of the transclusion dialog + * Specialized layout forked from and similar to {@see OO.ui.BookletLayout}, but to synchronize the + * sidebar and content pane of the transclusion dialog. * * Also owns the outline controls. * @@ -22,9 +22,6 @@ * pane, but has no corresponding item in the sidebar. */ ve.ui.MWTwoPaneTransclusionDialogLayout = function VeUiMWTwoPaneTransclusionDialogLayout( config ) { - // Configuration initialization - config = config || {}; - // Parent constructor ve.ui.MWTwoPaneTransclusionDialogLayout.super.call( this, config ); @@ -159,12 +156,12 @@ ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.onSidebarItemSelected = functi ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.toggleOutline = function ( show ) { this.toggleMenu( show ); if ( show ) { - var booklet = this; + var self = this; // HACK: Kill dumb scrollbars when the sidebar stops animating, see T161798. // Only necessary when outline controls are present, delay matches transition on // `.oo-ui-menuLayout-menu`. setTimeout( function () { - OO.ui.Element.static.reconsiderScrollbars( booklet.outlinePanel.$element[ 0 ] ); + OO.ui.Element.static.reconsiderScrollbars( self.outlinePanel.$element[ 0 ] ); }, OO.ui.theme.getDialogTransitionDuration() ); } }; @@ -345,18 +342,15 @@ ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.setPage = function ( name ) { */ ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.refreshControls = function () { var partId = this.getSelectedTopLevelPartId(), - pages = this.stackLayout.getItems(), - page = this.getPage( partId ), - index = pages.indexOf( page ), - isPart = !!partId, canMoveUp, canMoveDown = false, - canBeDeleted = isPart; + canBeDeleted = !!partId; - /* check if this is the first element and no parameter */ - canMoveUp = isPart && index > 0; - - /* check if this is the last element and no parameter */ - if ( isPart ) { + if ( partId ) { + var pages = this.stackLayout.getItems(), + page = this.getPage( partId ), + index = pages.indexOf( page ); + canMoveUp = index > 0; + // Check if there is at least one more top-level part below the current one for ( var i = index + 1; i < pages.length; i++ ) { if ( !( pages[ i ] instanceof ve.ui.MWParameterPage || pages[ i ] instanceof ve.ui.MWAddParameterPage ) ) { canMoveDown = true; diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWidget.js index b8ebee94a6..93c0d6d589 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineWidget.js @@ -157,7 +157,7 @@ ve.ui.MWTransclusionOutlineWidget.prototype.setSelectionByPageName = function ( * @param {boolean} hasValue */ ve.ui.MWTransclusionOutlineWidget.prototype.toggleHasValueByPageName = function ( pageName, hasValue ) { - var idParts = pageName.split( '/' ), + var idParts = pageName.split( '/', 2 ), templatePartWidget = this.partWidgets[ idParts[ 0 ] ]; templatePartWidget.toggleHasValue( idParts[ 1 ], hasValue );