Santhosh has uploaded a new change for review.

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

Change subject: Make it possible to adapt references manually to an empty 
paragraph
......................................................................

Make it possible to adapt references manually to an empty paragraph

Bug: T99507, T85714
Change-Id: Id3f70219af6a6f5e3641c1df65eb5d292e4e1646
---
M Resources.php
M i18n/en.json
M i18n/qqq.json
M modules/tools/ext.cx.tools.reference.js
M modules/tools/styles/ext.cx.tools.reference.less
5 files changed, 66 insertions(+), 4 deletions(-)


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

diff --git a/Resources.php b/Resources.php
index 0602e6a..b5c127f 100644
--- a/Resources.php
+++ b/Resources.php
@@ -448,6 +448,7 @@
        ),
        'messages' => array(
                'cx-tools-reference-title',
+               'cx-tools-reference-add',
                'cx-tools-reference-remove',
        ),
        'dependencies' => array(
diff --git a/i18n/en.json b/i18n/en.json
index 6a7dc43..1ab7ca7 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -71,6 +71,7 @@
        "cx-stats-title": "Content Translation statistics",
        "cx-stats-unknown": "unknown",
        "cx-tools-reference-title": "Reference",
+       "cx-tools-reference-add": "Add reference",
        "cx-tools-reference-remove": "Remove reference",
        "cx-tools-link-instruction-shortcut": "Shift + click any link to open",
        "cx-tools-link-hover-tooltip": "Click to open",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index cca01f3..6bd6737 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -79,6 +79,7 @@
        "cx-stats-title": "The title for the Special:ContentTranslationStats 
special page.",
        "cx-stats-unknown": "Text when the source or target language is 
unknown. An adjective that describes the language.\n{{Identical|Unknown}}",
        "cx-tools-reference-title": "Title of Reference (footnote) tool card on 
Special:ContentTranslation.\n{{Identical|Reference}}",
+       "cx-tools-reference-add": "Text shown in the reference tool card. 
Clicking on it add the reference in the cursor position.",
        "cx-tools-reference-remove": "Text shown in the reference tool card. 
Clicking on it removes the reference in the context.",
        "cx-tools-link-instruction-shortcut": "Text explaining the shortcut for 
opening a link. Appears in the link tool card.",
        "cx-tools-link-hover-tooltip": "Tooltip text shown when the mouse is 
over the link with shift or control key is pressed.",
diff --git a/modules/tools/ext.cx.tools.reference.js 
b/modules/tools/ext.cx.tools.reference.js
index b604753..211cfc4 100644
--- a/modules/tools/ext.cx.tools.reference.js
+++ b/modules/tools/ext.cx.tools.reference.js
@@ -18,6 +18,7 @@
        function ReferenceCard() {
                this.$card = null;
                this.$removeReference = null;
+               this.$addReference = null;
                this.$reference = null;
        }
 
@@ -30,6 +31,9 @@
 
                this.$card = $( '<div>' )
                        .addClass( 'card reference' );
+               this.$addReference = $( '<div>' )
+                       .addClass( 'card__add-reference' )
+                       .text( mw.msg( 'cx-tools-reference-add' ) );
                this.$removeReference = $( '<div>' )
                        .addClass( 'card__remove-reference' )
                        .text( mw.msg( 'cx-tools-reference-remove' ) );
@@ -49,7 +53,7 @@
                $referenceInfo.append( $( '<div>' )
                        .addClass( 'card__reference-content' ) );
 
-               $referenceInfo.append( this.$removeReference );
+               $referenceInfo.append( this.$addReference, 
this.$removeReference );
                this.$card.append( $referenceInfo );
                this.listen();
                return this.$card;
@@ -71,6 +75,32 @@
                        this.$reference.remove();
                        this.stop();
                }
+       };
+
+       /**
+        * Add the reference to the cursor position in translation
+        */
+       ReferenceCard.prototype.addReference = function () {
+               var $reference, referenceId, targetReferenceId;
+
+               mw.cx.selection.restore( 'translation' );
+               $reference = this.$reference.clone();
+               referenceId = $reference.prop( 'id' );
+               targetReferenceId = 'cx' + referenceId;
+               $reference.attr( {
+                       'id': targetReferenceId,
+                       'data-sourceid': referenceId
+               } );
+               mw.cx.selection.pasteHTML( $reference[ 0 ].outerHTML );
+               // Adapt references.
+               this.adaptReference( targetReferenceId );
+               // Click handler for references.
+               $( document.getElementById( targetReferenceId ) )
+                       .on( 'click', referenceClickHandler )
+                       // Mark it readonly
+                       .attr( 'contenteditable', false );
+
+               this.stop();
        };
 
        /**
@@ -157,10 +187,15 @@
                        .text( $sourceReference.text() );
                this.$card.find( '.card__reference-content' )
                        .html( referenceContent );
-               if ( $targetReference.length ) {
+
+               if ( $targetReference.length && language === 
mw.cx.targetLanguage ) {
                        this.$reference = $targetReference;
                        this.$removeReference.on( 'click', $.proxy( 
this.removeReference, this ) );
-               } else {
+                       this.$addReference.remove();
+               }
+               if ( $sourceReference.length && language === 
mw.cx.sourceLanguage ) {
+                       this.$reference = $sourceReference;
+                       this.$addReference.on( 'click', $.proxy( 
this.addReference, this ) );
                        this.$removeReference.remove();
                }
                this.$card.find( '.card__title--language' )
@@ -247,6 +282,7 @@
                if ( !mwData || !mwData.body ) {
                        return;
                }
+
                $referenceContent = $( '<div>' ).html( mwData.body.html );
                /*
                Reference template expands in references section as below
@@ -287,7 +323,10 @@
                                referenceId;
 
                        // Click handler for references.
-                       $reference.on( 'click', referenceClickHandler );
+                       $reference
+                               .on( 'click', referenceClickHandler )
+                               // Mark it readonly
+                               .attr( 'contenteditable', false );
                        if ( isRestoredFromDraft ) {
                                // This section is restored from draft. No need 
of reference adaptation.
                                return;
diff --git a/modules/tools/styles/ext.cx.tools.reference.less 
b/modules/tools/styles/ext.cx.tools.reference.less
index beaf046..99cb761 100644
--- a/modules/tools/styles/ext.cx.tools.reference.less
+++ b/modules/tools/styles/ext.cx.tools.reference.less
@@ -9,6 +9,26 @@
        padding: 0;
 }
 
+.card__add-reference {
+       @vertical-margin: 10px;
+       @horizontal-margin: 15px;
+       .mw-ui-item;
+       .mw-ui-one-whole;
+       float: none;
+       padding: @vertical-margin @horizontal-margin;
+       font-size: large;
+       color: #565656; // TODO Should come from library?
+       .background-image-svg('../images/add.svg', '../images/add.png');
+       background-color: #FFF;
+       background-position: 10px center;
+       background-repeat: no-repeat;
+       background-size: 15px;
+       padding: 5px 10px 5px 32px;
+       cursor: pointer;
+       clear: both;
+       border-top: 1px solid #dddddd;
+}
+
 .card__remove-reference {
        @vertical-margin: 10px;
        @horizontal-margin: 15px;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id3f70219af6a6f5e3641c1df65eb5d292e4e1646
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>

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

Reply via email to