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

Change subject: Reduce the code duplication in applyTranslationTemplate method
......................................................................


Reduce the code duplication in applyTranslationTemplate method

Change-Id: If38aa7cf381cb72a136a038724d29bf38e7b6fd4
---
M modules/translation/ext.cx.translation.js
1 file changed, 11 insertions(+), 23 deletions(-)

Approvals:
  Amire80: 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 f7081ea..41e5247 100644
--- a/modules/translation/ext.cx.translation.js
+++ b/modules/translation/ext.cx.translation.js
@@ -265,39 +265,27 @@
                                        'data-cx-state': 'source'
                                } );
 
-                       if ( origin === 'mt-user-disabled' ) {
+                       if ( origin === 'mt-user-disabled' || origin === 
'clear' ) {
                                $clone.attr( 'data-cx-state', 'empty' );
-                               if ( $sourceSection.prop( 'tagName' ) === 
'FIGURE' ) {
-                                       // Clear figure caption alone.
-                                       $clone.find( 'figcaption' ).empty();
+                               if ( $sourceSection.is( 'figure' ) ) {
+                                       if ( origin === 'clear' ) {
+                                               // When clearing figures, 
replace it with placeholder.
+                                               $clone = getPlaceholder( 
sourceId ).attr( 'data-cx-section-type', 'figure' );
+                                       } else {
+                                               // Clear figure caption alone.
+                                               $clone.find( 'figcaption' 
).empty();
+                                       }
                                } else if ( $sourceSection.is( 'ul, ol' ) ) {
-                                       $clone = $sourceSection.clone();
                                        // Explicit contenteditable attribute 
helps to place the cursor
-                                       // in empty UL.
+                                       // in empty <ul> or <ol>.
                                        $clone.prop( 'contenteditable', true 
).find( 'li' ).empty();
                                } else {
                                        $clone.empty();
                                }
                        }
-
-                       if ( origin === 'clear' ) {
-                               $clone.attr( 'data-cx-state', 'empty' );
-                               if ( $sourceSection.prop( 'tagName' ) === 
'FIGURE' ) {
-                                       // When clearing figures, replace it 
with placeholder.
-                                       $clone = getPlaceholder( sourceId )
-                                               .attr( 'data-cx-section-type', 
$sourceSection.prop( 'tagName' ) );
-                               } else if ( $sourceSection.is( 'ul, ol' ) ) {
-                                       $clone = $sourceSection.clone();
-                                       // Explicit contenteditable attribute 
helps to place the cursor
-                                       // in empty UL.
-                                       $clone.prop( 'contenteditable', true 
).find( 'li' ).empty();
-                               } else {
-                                       $clone.empty();
-                               }
-                       } // else: service-failure, non-editable, 
mt-not-available
+                       // else: service-failure, non-editable, mt-not-available
                        // Replace the placeholder with a translatable element
                        $section.replaceWith( $clone );
-
                        // $section was replaced. Get the updated instance.
                        $section = mw.cx.getTranslationSection( sourceId );
                        mw.hook( 'mw.cx.translation.postMT' ).fire( $section );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: If38aa7cf381cb72a136a038724d29bf38e7b6fd4
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>
Gerrit-Reviewer: Amire80 <amir.ahar...@mail.huji.ac.il>
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