Mooeypoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/117025

Change subject: Inline CR fixes for Media Edit Dialog
......................................................................

Inline CR fixes for Media Edit Dialog

Fixing several inline comments from the previous commit, and
reorganizing the usability of size select clicks to prevent loop
click bug.

Change-Id: I259d86e9bbe90270d8883b7a3de96979b1d5a156
---
M modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js
1 file changed, 61 insertions(+), 75 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/25/117025/1

diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js 
b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js
index 811d425..8cee8b0 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js
@@ -324,48 +324,38 @@
  * the widget.
  */
 ve.ui.MWMediaEditDialog.prototype.onSizeWidgetChange = function () {
-       var selectedType = ( this.typeInput.getSelectedItem() ) ? 
this.typeInput.getSelectedItem().getData() : '';
+       var selectedType = this.typeInput.getSelectedItem() ? 
this.typeInput.getSelectedItem().getData() : '',
+               thumbOrFrameless = selectedType === 'thumb' || selectedType === 
'frameless';
+
        // Switch to 'default' or 'custom' size
        if ( this.sizeWidget.isEmpty() ) {
-               if (
-                       selectedType === 'thumb' ||
-                       selectedType === 'frameless'
-               ) {
-                       this.sizeSelectWidget.selectItem(
-                               this.sizeSelectWidget.getItemFromData( 
'default' )
-                       );
-               } else {
-                       this.sizeSelectWidget.selectItem(
-                               this.sizeSelectWidget.getItemFromData( 'full' )
-                       );
-               }
-       } else {
-               // If the value is full size for either thumb or frameless
-               // images, make sure the size select is on 'full' despite the
-               // fact that there are actual "custom" numbers in the
-               // size widget
-               if (
-                       (
-                               selectedType === 'thumb' ||
-                               selectedType === 'frameless'
-                       ) &&
-                       OO.compare(
-                               this.sizeWidget.getCurrentDimensions(),
-                               this.sizeWidget.getOriginalDimensions()
+               this.sizeSelectWidget.selectItem(
+                       this.sizeSelectWidget.getItemFromData(
+                               thumbOrFrameless ?
+                               'default' :
+                               'full'
                        )
-               ) {
-                       this.sizeSelectWidget.selectItem(
-                               this.sizeSelectWidget.getItemFromData( 'full' )
-                       );
-               } else {
-                       // Otherwise, when the widget has actual typed values, 
it
-                       // is considerind 'custom' so clicking the 'full' button
-                       // will result in removing size attributes altogether 
from
-                       // the wikitext (faux-default)
-                       this.sizeSelectWidget.selectItem(
-                               this.sizeSelectWidget.getItemFromData( 'custom' 
)
-                       );
-               }
+               );
+       } else {
+               this.sizeSelectWidget.selectItem(
+                       this.sizeSelectWidget.getItemFromData(
+                               thumbOrFrameless &&
+                               OO.compare(
+                                       this.sizeWidget.getCurrentDimensions(),
+                                       this.sizeWidget.getOriginalDimensions()
+                               ) ?
+                               // If the value is full size for either thumb 
or frameless
+                               // images, make sure the size select is on 
'full' despite the
+                               // fact that there are actual "custom" numbers 
in the
+                               // size widget
+                               'full' :
+                               // Otherwise, when the widget has actual typed 
values, it
+                               // is considerind 'custom' so clicking the 
'full' button
+                               // will result in removing size attributes 
altogether from
+                               // the wikitext (faux-default)
+                               'custom'
+                       )
+               );
        }
 };
 
@@ -374,14 +364,14 @@
  * sure size is limited.
  */
 ve.ui.MWMediaEditDialog.prototype.onTypeChange = function () {
-       var currentChoice = this.typeInput.getSelectedItem().getData();
-       if (
-               currentChoice === 'thumb' ||
-               // As per wikitext docs, both 'thumb' and 'frameless' have
-               // explicitly limited size, as opposed to the similar case
-               // of having no type specified
-               currentChoice === 'frameless'
-       ) {
+       var selectedType = this.typeInput.getSelectedItem() ? 
this.typeInput.getSelectedItem().getData() : '',
+               thumbOrFrameless = selectedType === 'thumb' || selectedType === 
'frameless';
+
+       // As per wikitext docs, both 'thumb' and 'frameless' have
+       // explicitly limited size, as opposed to the similar case
+       // of having no type specified
+       if ( thumbOrFrameless ) {
+
                // Set the placeholders to be wiki default
                if ( this.mediaNode.getAttribute( 'width' ) > 
this.mediaNode.getAttribute( 'height' ) ) {
                        this.sizeWidget.setPlaceholderDimensions( {
@@ -398,20 +388,6 @@
                // Tell the size widget to limit maxDimensions
                this.sizeWidget.setEnforcedMax( true );
 
-               // For these types, select 'full size' if the size widget is 
not empty
-               // and the dimensions are equal to original dimensions
-               if (
-                       !this.sizeWidget.isEmpty() &&
-                       OO.compare(
-                               this.sizeWidget.getCurrentDimensions(),
-                               this.sizeWidget.getOriginalDimensions()
-                       )
-               ) {
-                       this.sizeSelectWidget.selectItem(
-                               this.sizeSelectWidget.getItemFromData( 'full' )
-                       );
-               }
-
        } else {
                // Set placeholders to be image original dimensions
                // Technically, this is the 'default' of non thumb/frameless
@@ -426,7 +402,7 @@
                // Don't limit the widget for other types (Wikitext doesn't)
                this.sizeWidget.setEnforcedMax( false );
 
-               // For these types, filled in information is custom, unlike
+               // For these types, filled in information is custom
                if ( !this.sizeWidget.isEmpty() ) {
                        this.sizeSelectWidget.selectItem(
                                this.sizeSelectWidget.getItemFromData( 'custom' 
)
@@ -434,33 +410,43 @@
                }
        }
 
-       // Default and faux-default
+       // Default, faux-default (full) buttons on type change
        if ( this.sizeWidget.isEmpty() ) {
+
+               this.sizeSelectWidget.selectItem(
+                       this.sizeSelectWidget.getItemFromData(
+                               thumbOrFrameless ?
+                               // default for thumb and frameless
+                               'default' :
+                               // full is the default of basic and frame
+                               'full'
+                       )
+               );
+       } else {
+               // If the size widget is not empty and the dimensions are
+               // equal to original dimensions, set button to 'full' in
+               // thumbnail or frameless
                if (
-                       currentChoice === 'thumb' ||
-                       currentChoice === 'frameless'
+                       thumbOrFrameless &&
+                       OO.compare(
+                               this.sizeWidget.getCurrentDimensions(),
+                               this.sizeWidget.getOriginalDimensions()
+                       )
                ) {
-                       this.sizeSelectWidget.selectItem(
-                               this.sizeSelectWidget.getItemFromData( 
'default' )
-                       );
-               } else {
-                       // full is the default of basic and frame
                        this.sizeSelectWidget.selectItem(
                                this.sizeSelectWidget.getItemFromData( 'full' )
                        );
                }
        }
 
-       // Border
-       if (
-               currentChoice === 'thumb' ||
-               currentChoice === 'frame'
-       ) {
+       // Enable or disable border
+       if ( thumbOrFrameless ) {
                this.borderCheckbox.setDisabled( true );
                this.borderCheckbox.setValue( false );
        } else {
                this.borderCheckbox.setDisabled( false );
        }
+
        // Re-validate the existing dimensions
        this.sizeWidget.validateDimensions();
 };

-- 
To view, visit https://gerrit.wikimedia.org/r/117025
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I259d86e9bbe90270d8883b7a3de96979b1d5a156
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <mor...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to