Amire80 has uploaded a new change for review.

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

Change subject: WIP: Focus on the target field when opening a suggestion
......................................................................

WIP: Focus on the target field when opening a suggestion

Not fully done yet, but comments are welcome.

Bug: T113332
Change-Id: I198a68325c10bef8b128615bb5618bc4b74e7498
---
M modules/dashboard/ext.cx.suggestionlist.js
M modules/source/ext.cx.source.selector.js
2 files changed, 30 insertions(+), 7 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation 
refs/changes/64/248864/1

diff --git a/modules/dashboard/ext.cx.suggestionlist.js 
b/modules/dashboard/ext.cx.suggestionlist.js
index 0e56f88..6b2c62c 100644
--- a/modules/dashboard/ext.cx.suggestionlist.js
+++ b/modules/dashboard/ext.cx.suggestionlist.js
@@ -595,20 +595,24 @@
         */
        CXSuggestionList.prototype.listen = function () {
                this.$container.on( 'click', '.cx-suggestionlist .cx-slitem', 
function () {
-                       var cxSelector, suggestion;
+                       var cxSelector, suggestion,
+                               $this = $( this );
 
-                       cxSelector = $( this ).data( 'cxsourceselector' );
+                       cxSelector = $this.data( 'cxsourceselector' );
 
                        if ( cxSelector ) {
+                               cxSelector.options.initialFocus = 'target';
                                cxSelector.prefill();
                        } else {
-                               suggestion = $( this ).find( 
'.cx-slitem__translation-link' ).data( 'suggestion' );
-                               $( this ).cxSourceSelector( {
+                               suggestion = $this.find( 
'.cx-slitem__translation-link' ).data( 'suggestion' );
+                               $this.cxSourceSelector( {
                                        sourceLanguage: 
suggestion.sourceLanguage,
                                        targetLanguage: 
suggestion.targetLanguage,
                                        sourceTitle: suggestion.title,
+                                       initialFocus: 'target',
                                        campaign: 'suggestions'
                                } );
+                               cxSelector = $this.data( 'cxsourceselector' );
                        }
                } );
 
diff --git a/modules/source/ext.cx.source.selector.js 
b/modules/source/ext.cx.source.selector.js
index 63d4dcb..abef4e4 100644
--- a/modules/source/ext.cx.source.selector.js
+++ b/modules/source/ext.cx.source.selector.js
@@ -17,7 +17,7 @@
         */
        function CXSourceSelector( $trigger, siteMapper, options ) {
                this.$trigger = $( $trigger );
-               this.options = $.extend( {}, options );
+               this.options = $.extend( {}, $.fn.cxSourceSelector.defaults, 
options );
                this.siteMapper = siteMapper;
 
                this.languagePairs = null;
@@ -108,6 +108,21 @@
                        this.show();
                        this.check();
                }
+       };
+
+       /**
+        * Focus on a given field.
+        * @param string 'source' or 'target'.
+        */
+       CXSourceSelector.prototype.focus = function ( field ) {
+               var fields;
+
+               fields = {
+                       source: this.$sourceTitleInput,
+                       target: this.$targetTitleInput
+               };
+
+               fields[ field ].focus();
        };
 
        /**
@@ -627,7 +642,7 @@
                        this.showAsDialog();
                }
 
-               this.$sourceTitleInput.focus();
+               this.focus( this.options.initialFocus );
        };
 
        /**
@@ -740,7 +755,7 @@
                ).done( function ( sourceTitle ) {
                        if ( sourceTitle === false ) {
                                selector.showSourceTitleError( sourceLanguage );
-                               selector.$sourceTitleInput.focus();
+                               selector.focus( 'source' );
                                return;
                        }
 
@@ -991,4 +1006,8 @@
                        }
                } );
        };
+
+       $.fn.cxSourceSelector.defaults = {
+               initialFocus: 'source'
+       };
 }( jQuery, mediaWiki ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I198a68325c10bef8b128615bb5618bc4b74e7498
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Amire80 <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to