Mooeypoo has uploaded a new change for review.

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


Change subject: RTL fix for VE's link widget
......................................................................

RTL fix for VE's link widget

The purpose is to flip the direction of the input inside
the link widget for RTL wikis, but flip it again to LTR
if the user inserts an external URL. This is my first VE
fix, I tried to follow conventions and avoid touching the
parent objects that are unrelated to URLs.

Bug: 47717
Change-Id: Ic13b9c3b155ce2979298cac9518c7419b9d45bac
---
M modules/ve/ui/styles/ve.ui.Widget.css
M modules/ve/ui/widgets/ve.ui.LinkTargetInputWidget.js
2 files changed, 39 insertions(+), 1 deletion(-)


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

diff --git a/modules/ve/ui/styles/ve.ui.Widget.css 
b/modules/ve/ui/styles/ve.ui.Widget.css
index f066780..f31d7fe 100644
--- a/modules/ve/ui/styles/ve.ui.Widget.css
+++ b/modules/ve/ui/styles/ve.ui.Widget.css
@@ -481,3 +481,12 @@
 .ve-ui-mwCategorySortkeyForm .ve-ui-inputLabelWidget {
        padding: 0 0.125em 0.5em 0.125em;
 }
+
+/* RTL Definitions */
+
+.ve-ui-rtl {
+       direction: rtl;
+}
+.ve-ui-ltr {
+       direction: ltr;
+}
\ No newline at end of file
diff --git a/modules/ve/ui/widgets/ve.ui.LinkTargetInputWidget.js 
b/modules/ve/ui/widgets/ve.ui.LinkTargetInputWidget.js
index 2545ba6..615e4d1 100644
--- a/modules/ve/ui/widgets/ve.ui.LinkTargetInputWidget.js
+++ b/modules/ve/ui/widgets/ve.ui.LinkTargetInputWidget.js
@@ -23,6 +23,11 @@
 
        // Initialization
        this.$.addClass( 've-ui-linkTargetInputWidget' );
+
+       // Default RTL/LTR check 
+       if ( $( 'body' ).hasClass( 'rtl' ) ) {
+               this.$input.addClass( 've-ui-rtl' );
+       }
 };
 
 /* Inheritance */
@@ -30,7 +35,32 @@
 ve.inheritClass( ve.ui.LinkTargetInputWidget, ve.ui.TextInputWidget );
 
 /* Methods */
+ve.ui.LinkTargetInputWidget.prototype.onEdit = function () {
+       if ( !this.disabled ) {
 
+               // RTL/LTR check:
+               if ( $( 'body' ).hasClass( 'rtl' ) ) {
+                       if ( 
ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( this.$input.val() ) 
) {
+                               // External link
+                               if ( this.$input.hasClass( 've-ui-rtl' ) ) {
+                                        this.$input.removeClass( 've-ui-rtl' );
+                                        this.$input.addClass( 've-ui-ltr' );
+                               }
+                       } else {
+                               // Internal link
+                               if ( this.$input.hasClass( 've-ui-ltr' ) ) {
+                                        this.$input.removeClass( 've-ui-ltr');
+                                        this.$input.addClass( 've-ui-rtl' );
+                               }
+                       }
+               }               
+               // Allow the stack to clear so the value will be updated
+               setTimeout( ve.bind( function () {
+                       this.setValue( this.$input.val() );
+               }, this ) );
+       }
+       
+};
 /**
  * Set the value of the input.
  *
@@ -70,7 +100,6 @@
        this.annotation = annotation;
 
        // Call parent method
-
        ve.ui.TextInputWidget.prototype.setValue.call(
                this, this.getTargetFromAnnotation( annotation )
        );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic13b9c3b155ce2979298cac9518c7419b9d45bac
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