From 431f2abcfd5ad338ed91cabf8cead83d73eb501e Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 8 May 2015 16:15:16 +0100 Subject: [PATCH] Use new selectItemByData method where possible Change-Id: I32f213bf2977623a0bde83fb9119fda42a1e9848 --- .../ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js | 46 +++++-------------- .../ui/dialogs/ve.ui.MWTemplateDialog.js | 4 +- .../ve.ui.MWLinkAnnotationInspector.js | 8 ++-- .../ui/pages/ve.ui.MWAdvancedSettingsPage.js | 4 +- .../ve-mw/ui/pages/ve.ui.MWSettingsPage.js | 2 +- 5 files changed, 18 insertions(+), 46 deletions(-) diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js index ebd03dc9d3..f30bdbc3c1 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js @@ -773,16 +773,14 @@ ve.ui.MWMediaDialog.prototype.confirmSelectedImage = function () { /** * Handle image model alignment change + * * @param {string} alignment Image alignment */ ve.ui.MWMediaDialog.prototype.onImageModelAlignmentChange = function ( alignment ) { - var item; alignment = alignment || 'none'; - item = alignment !== 'none' ? this.positionSelect.getItemFromData( alignment ) : null; - // Select the item without triggering the 'choose' event - this.positionSelect.selectItem( item ); + this.positionSelect.selectItemByData( alignment !== 'none' ? alignment : undefined ); this.positionCheckbox.setSelected( alignment !== 'none' ); this.checkChanged(); @@ -790,13 +788,11 @@ ve.ui.MWMediaDialog.prototype.onImageModelAlignmentChange = function ( alignment /** * Handle image model type change + * * @param {string} alignment Image alignment */ - ve.ui.MWMediaDialog.prototype.onImageModelTypeChange = function ( type ) { - var item = type ? this.typeSelect.getItemFromData( type ) : null; - - this.typeSelect.selectItem( item ); + this.typeSelect.selectItemByData( type ); this.borderCheckbox.setDisabled( !this.imageModel.isBorderable() @@ -1079,39 +1075,19 @@ ve.ui.MWMediaDialog.prototype.attachImageModel = function () { this.sizeWidget.updateDefaultDimensions(); // Set initial alt text - this.altTextInput.setValue( - this.imageModel.getAltText() - ); + this.altTextInput.setValue( this.imageModel.getAltText() ); // Set initial alignment - this.positionSelect.setDisabled( - !this.imageModel.isAligned() - ); - this.positionSelect.selectItem( - this.imageModel.isAligned() ? - this.positionSelect.getItemFromData( - this.imageModel.getAlignment() - ) : - null - ); - this.positionCheckbox.setSelected( - this.imageModel.isAligned() - ); + this.positionSelect.setDisabled( !this.imageModel.isAligned() ); + this.positionSelect.selectItemByData( this.imageModel.isAligned() && this.imageModel.getAlignment() ); + this.positionCheckbox.setSelected( this.imageModel.isAligned() ); // Border flag - this.borderCheckbox.setDisabled( - !this.imageModel.isBorderable() - ); - this.borderCheckbox.setSelected( - this.imageModel.isBorderable() && this.imageModel.hasBorder() - ); + this.borderCheckbox.setDisabled( !this.imageModel.isBorderable() ); + this.borderCheckbox.setSelected( this.imageModel.isBorderable() && this.imageModel.hasBorder() ); // Type select - this.typeSelect.selectItem( - this.typeSelect.getItemFromData( - this.imageModel.getType() || 'none' - ) - ); + this.typeSelect.selectItemByData( this.imageModel.getType() || 'none' ); this.isSettingUpModel = false; }; diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js index 5767f5acb0..6cdbad0088 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWTemplateDialog.js @@ -339,9 +339,7 @@ ve.ui.MWTemplateDialog.prototype.getSelectedNode = function ( data ) { */ ve.ui.MWTemplateDialog.prototype.setPageByName = function ( name ) { if ( this.bookletLayout.isOutlined() ) { - this.bookletLayout.getOutline().selectItem( - this.bookletLayout.getOutline().getItemFromData( name ) - ); + this.bookletLayout.getOutline().selectItemByData( name ); } else { this.bookletLayout.setPage( name ); } diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js index 1a86b06bd8..c1aca8ea26 100644 --- a/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js +++ b/modules/ve-mw/ui/inspectors/ve.ui.MWLinkAnnotationInspector.js @@ -98,7 +98,7 @@ ve.ui.MWLinkAnnotationInspector.prototype.onInternalLinkChange = function ( anno !this.allowProtocolInInternal && ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( href ) ) { - this.linkTypeSelect.selectItem( this.linkTypeSelect.getItemFromData( 'external' ) ); + this.linkTypeSelect.selectItemByData( 'external' ); } }; @@ -115,10 +115,8 @@ ve.ui.MWLinkAnnotationInspector.prototype.createAnnotationInput = function () { ve.ui.MWLinkAnnotationInspector.prototype.getSetupProcess = function ( data ) { return ve.ui.MWLinkAnnotationInspector.super.prototype.getSetupProcess.call( this, data ) .next( function () { - this.linkTypeSelect.selectItem( - this.linkTypeSelect.getItemFromData( - this.initialAnnotation instanceof ve.dm.MWExternalLinkAnnotation ? 'external' : 'internal' - ) + this.linkTypeSelect.selectItemByData( + this.initialAnnotation instanceof ve.dm.MWExternalLinkAnnotation ? 'external' : 'internal' ); this.annotationInput.setAnnotation( this.initialAnnotation ); }, this ); diff --git a/modules/ve-mw/ui/pages/ve.ui.MWAdvancedSettingsPage.js b/modules/ve-mw/ui/pages/ve.ui.MWAdvancedSettingsPage.js index afca8643cf..28f65248e5 100644 --- a/modules/ve-mw/ui/pages/ve.ui.MWAdvancedSettingsPage.js +++ b/modules/ve-mw/ui/pages/ve.ui.MWAdvancedSettingsPage.js @@ -231,11 +231,11 @@ ve.ui.MWAdvancedSettingsPage.prototype.setup = function ( metaList ) { advancedSettingsPage = this; // Indexing items - indexingField.selectItem( indexingField.getItemFromData( indexingType ) ); + indexingField.selectItemByData( indexingType ); this.indexingOptionTouched = false; // New section edit link items - newSectionEditField.selectItem( newSectionEditField.getItemFromData( newSectionEditLinkType ) ); + newSectionEditField.selectItemByData( newSectionEditLinkType ); this.newSectionEditLinkOptionTouched = false; this.enableDisplayTitleCheckbox.setSelected( !!displayTitleItem ); diff --git a/modules/ve-mw/ui/pages/ve.ui.MWSettingsPage.js b/modules/ve-mw/ui/pages/ve.ui.MWSettingsPage.js index 9b4d8257a4..d70f3d1668 100644 --- a/modules/ve-mw/ui/pages/ve.ui.MWSettingsPage.js +++ b/modules/ve-mw/ui/pages/ve.ui.MWSettingsPage.js @@ -250,7 +250,7 @@ ve.ui.MWSettingsPage.prototype.setup = function ( metaList ) { settingsPage = this; // Table of Contents items - tableOfContentsField.selectItem( tableOfContentsField.getItemFromData( tableOfContentsMode ) ); + tableOfContentsField.selectItemByData( tableOfContentsMode ); this.tableOfContentsTouched = false; // Redirect items (disabled states set by change event)