jenkins-bot has submitted this change and it was merged.

Change subject: Highlight the source sections also on hover
......................................................................


Highlight the source sections also on hover

Refactored the addPlaceholder method to avoid code duplication

Change-Id: I0977b4f6dcdaa20be5b5797de55e1c5ffc2768be
---
M modules/translation/ext.cx.translation.js
1 file changed, 41 insertions(+), 24 deletions(-)

Approvals:
  KartikMistry: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/translation/ext.cx.translation.js 
b/modules/translation/ext.cx.translation.js
index 1b82c9b..3a1fff5 100644
--- a/modules/translation/ext.cx.translation.js
+++ b/modules/translation/ext.cx.translation.js
@@ -134,42 +134,59 @@
                return sectionSelector;
        };
 
+       function sectionClick() {
+               /*jshint validthis:true */
+               $( this ).removeClass( 'placeholder' )
+                       .unbind( 'hover click' );
+               $( '#' + $( this ).data( 'source' ) ).removeClass( 'highlight' 
);
+               mw.hook( 'mw.cx.translation.add' ).fire( $( this ).data( 
'source' ) );
+       }
+
+       function sectionMouseEnter() {
+               /*jshint validthis:true */
+               $( this ).addClass( 'placeholder' ).html( '+ Add Translation' );
+               $( '#' + $( this ).data( 'source' ) ).addClass( 'highlight' );
+       }
+
+       function sectionMouseLeave() {
+               /*jshint validthis:true */
+               $( this ).removeClass( 'placeholder' ).empty();
+               $( '#' + $( this ).data( 'source' ) ).removeClass( 'highlight' 
);
+       }
+
+       /**
+        * Add placeholders for translation sections. The placeholders
+        * are aligned to the source sections. Also provides mouse hover 
effects.
+        */
        ContentTranslationEditor.prototype.addPlaceholders = function () {
                var cxSectionSelector = this.getSectionSelector();
 
                this.$content.html( mw.cx.data.segmentedContent );
                this.$content.find( cxSectionSelector ).each( function () {
-                       var $section = $( this ),
-                               sourceSectionId = $section.attr( 'id' ),
-                               $sourceSection = $( '#' + sourceSectionId );
-                       $section.css( 'min-height', $section.height() );
-                       $section.attr( {
-                               'id': 't' + sourceSectionId,
-                               'data-source': sourceSectionId,
-                               'contenteditable': true
-                       } );
+                       var $section, sourceSectionId, $sourceSection;
+
+                       $section = $( this );
+                       sourceSectionId = $section.attr( 'id' );
+                       $sourceSection = $( '#' + sourceSectionId );
+                       $section.css( 'min-height', $section.height() )
+                               .attr( {
+                                       'id': 't' + sourceSectionId,
+                                       'data-source': sourceSectionId,
+                                       'contenteditable': true
+                               } );
                        $section.empty();
                        $section.on( 'input', keepAlignment );
-
                        // Bind events to the placeholder sections
                        $sourceSection.click( function () {
                                $( '#t' + $( this ).attr( 'id' ) ).click();
                        } );
-                       $section.on( 'mouseenter', function () {
-                               $( this ).addClass( 'placeholder' ).html( '+ 
Add Translation' );
-                               $( '#' + $( this ).data( 'source' ) ).addClass( 
'highlight' );
+                       $sourceSection.hover( function () {
+                               $( '#t' + $( this ).attr( 'id' ) ).mouseenter();
+                       }, function () {
+                               $( '#t' + $( this ).attr( 'id' ) ).mouseleave();
                        } );
-                       $section.on( 'mouseleave', function () {
-                               $( this ).removeClass( 'placeholder' ).empty();
-                               $( '#' + $( this ).data( 'source' ) 
).removeClass( 'highlight' );
-                       } );
-                       $section.on( 'click', function () {
-                               $( this ).removeClass( 'placeholder' )
-                                       .unbind( 'mouseenter mouseleave click' 
);
-                               $( '#' + $( this ).data( 'source' ) 
).removeClass( 'highlight' );
-                               mw.hook( 'mw.cx.translation.add' ).fire( $( 
this ).data( 'source' ) );
-                       } );
-
+                       $section.hover( sectionMouseEnter, sectionMouseLeave );
+                       $section.on( 'click', sectionClick );
                } );
        };
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0977b4f6dcdaa20be5b5797de55e1c5ffc2768be
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>
Gerrit-Reviewer: KartikMistry <kartik.mis...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to