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

Change subject: Reference card - Show the reference informaton and allow 
deleting it
......................................................................


Reference card - Show the reference informaton and allow deleting it

* Experimental feature

Change-Id: Iec4f2d0d79497fe1019482444c00a6e9f3c513e4
---
M ContentTranslation.hooks.php
M Resources.php
M i18n/en.json
M i18n/qqq.json
M modules/source/ext.cx.source.js
A modules/tools/ext.cx.tools.reference.js
A modules/tools/styles/ext.cx.tools.reference.less
M modules/translation/ext.cx.translation.js
8 files changed, 193 insertions(+), 2 deletions(-)

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



diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php
index 22c82ef..1887e11 100644
--- a/ContentTranslation.hooks.php
+++ b/ContentTranslation.hooks.php
@@ -44,6 +44,8 @@
                if ( $wgContentTranslationExperimentalFeatures ) {
                        // WYSIWYGEditor
                        $out->addModules( 'ext.cx.editor.medium' );
+                       // Reference card
+                       $out->addModules( 'ext.cx.tools.reference' );
                } else {
                        // Just ContentEditable
                        $out->addModules( 'ext.cx.editor' );
diff --git a/Resources.php b/Resources.php
index e4726ed..a07ec2c 100644
--- a/Resources.php
+++ b/Resources.php
@@ -179,6 +179,23 @@
        ),
 ) + $resourcePaths;
 
+$wgResourceModules['ext.cx.tools.reference'] = array(
+       'scripts' => array(
+               'tools/ext.cx.tools.reference.js',
+       ),
+       'styles' => array(
+               'tools/styles/ext.cx.tools.reference.less',
+       ),
+       'messages' => array(
+               'cx-tools-reference-title',
+               'cx-tools-reference-remove',
+       ),
+       'dependencies' => array(
+               'ext.cx.tools.manager',
+               'ext.cx.tools.card',
+       ),
+) + $resourcePaths;
+
 $wgResourceModules['ext.cx.tools.images'] = array(
        'scripts' => array(
                'tools/ext.cx.tools.images.js',
diff --git a/i18n/en.json b/i18n/en.json
index 9f244eb..771388c 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -46,5 +46,7 @@
        "cx-stats-to": "Target language",
        "cx-stats-pages-title": "Translated pages",
        "cx-stats-unknown": "unknown",
-       "cx-stats-summary": "{{PLURAL:$1|One page|$1/$2 pages ($3%)}} in the 
main namespace."
+       "cx-stats-summary": "{{PLURAL:$1|One page|$1/$2 pages ($3%)}} in the 
main namespace.",
+       "cx-tools-reference-title": "Reference",
+       "cx-tools-reference-remove": "Remove reference"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index bb6418a..8b3ab60 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -48,5 +48,7 @@
        "cx-stats-to": "A header for a table column. The column lists the 
languages into which the pages were translated.",
        "cx-stats-pages-title": "A heading for the section at 
Special:ContentTranslationStats. The section shows a list of translated 
articles.",
        "cx-stats-unknown": "Text when the source or target language is 
unknown. An adjective that describes the language.",
-       "cx-stats-summary": "A summary of the number of published pages. $1 is 
the number of translated pages that were moved to the main namespace, $2 is the 
total number of translated pages, and $3 is percent of pages in the main 
namespace."
+       "cx-stats-summary": "A summary of the number of published pages. $1 is 
the number of translated pages that were moved to the main namespace, $2 is the 
total number of translated pages, and $3 is percent of pages in the main 
namespace.",
+       "cx-tools-reference-title": "Title of Reference tool 
card.\n{{Identical|Reference}}",
+       "cx-tools-reference-remove": "Text shown in reference tool card. 
Clicking on it removes the reference in the context."
 }
diff --git a/modules/source/ext.cx.source.js b/modules/source/ext.cx.source.js
index 09ab610..c343993 100644
--- a/modules/source/ext.cx.source.js
+++ b/modules/source/ext.cx.source.js
@@ -107,6 +107,23 @@
                mw.hook( 'mw.cx.source.ready' ).fire();
        };
 
+       /**
+        * Disable all links in the content area.
+        */
+       ContentTranslationSource.prototype.disableLinks = function () {
+               this.$content.find( 'a' ).bind( 'click', function () {
+                       var $link = $( this );
+                       // avoid all reference links
+                       if ( $link.parent().attr( 'typeof' ) === 
'mw:Extension/ref' ) {
+                               mw.hook( 'mw.cx.select.reference' ).fire( 
$link.text(), $link.parent().data( 'mw' ) );
+                       } else {
+                               mw.hook( 'mw.cx.select.link' ).fire( 
$link.text(), mw.cx.sourceLanguage );
+                       }
+                       // Disable link click
+                       return false;
+               } );
+       };
+
        ContentTranslationSource.prototype.listen = function () {
                mw.hook( 'mw.cx.source.loaded' ).add( $.proxy( this.load, this 
) );
 
diff --git a/modules/tools/ext.cx.tools.reference.js 
b/modules/tools/ext.cx.tools.reference.js
new file mode 100644
index 0000000..48fdba1
--- /dev/null
+++ b/modules/tools/ext.cx.tools.reference.js
@@ -0,0 +1,95 @@
+/**
+ * ContentTranslation Tools
+ * A tool that allows editors to translate pages from one language
+ * to another with the help of machine translation and other translation tools
+ *
+ * @file
+ * @ingroup Extensions
+ * @copyright See AUTHORS.txt
+ * @license GPL-2.0+
+ */
+( function ( $, mw ) {
+       'use strict';
+
+       function ReferenceCard() {
+               this.$card = null;
+               this.$removeReference = null;
+               this.$reference = null;
+       }
+
+       ReferenceCard.prototype.getCard = function () {
+               var $referenceInfo;
+
+               this.$card = $( '<div>' )
+                       .addClass( 'card reference' );
+               this.$removeReference = $( '<div>' )
+                       .addClass( 'card__remove-reference' )
+                       .text( mw.msg( 'cx-tools-reference-remove' ) );
+
+               $referenceInfo = $( '<div>' )
+                       .addClass( 'card__reference-info' );
+               $referenceInfo.append( $( '<div>' )
+                       .addClass( 'card__title' )
+                       .text( mw.msg( 'cx-tools-reference-title' ) ) );
+               $referenceInfo.append( $( '<div>' )
+                       .addClass( 'card__reference-number' ) );
+               $referenceInfo.append( $( '<div>' )
+                       .addClass( 'card__reference-content' ) );
+
+               $referenceInfo.append( this.$removeReference );
+               this.$card.append( $referenceInfo );
+               this.listen();
+               return this.$card;
+       };
+
+       ReferenceCard.prototype.removeReference = function () {
+               if ( this.$reference ) {
+                       this.$reference.remove();
+                       this.stop();
+               }
+       };
+
+       ReferenceCard.prototype.listen = function () {
+               this.$removeReference.on( 'click', $.proxy( 
this.removeReference, this ) );
+       };
+
+       ReferenceCard.prototype.start = function ( refNumber, reference, 
$reference ) {
+               this.$card.find( '.card__reference-number' )
+                       .text( refNumber );
+               this.$card.find( '.card__reference-content' )
+                       .html( reference.body.html );
+               if ( $reference ) {
+                       this.$reference = $reference;
+                       this.$removeReference.on( 'click', $.proxy( 
this.removeReference, this ) );
+               } else {
+                       this.$removeReference.remove();
+               }
+       };
+
+       ReferenceCard.prototype.stop = function () {
+               this.$card.remove();
+       };
+
+       ReferenceCard.prototype.getTriggerEvents = function () {
+               return [
+                       'mw.cx.select.reference',
+                       'mw.cx.search.reference'
+               ];
+       };
+       /**
+        * jQuery plugin to adapt all the references with rel="mw:WikiLink"
+        * @param {string} targetLanguage
+        */
+       $.fn.adaptReferences = function () {
+               return this.each( function () {
+                       var $this = $( this );
+
+                       $this.on( 'click', '[typeof="mw:Extension/ref"]', 
function () {
+                               var $reference = $( this );
+                               mw.hook( 'mw.cx.select.reference' ).fire( 
$reference.text(), $reference.data( 'mw' ), $reference );
+                       } );
+               } );
+       };
+
+       mw.cx.tools.reference = ReferenceCard;
+}( jQuery, mediaWiki ) );
diff --git a/modules/tools/styles/ext.cx.tools.reference.less 
b/modules/tools/styles/ext.cx.tools.reference.less
new file mode 100644
index 0000000..5f2a89e
--- /dev/null
+++ b/modules/tools/styles/ext.cx.tools.reference.less
@@ -0,0 +1,50 @@
+@import "../../base/styles/grid/agora-grid";
+
+.card.reference {
+       .mw-ui-item;
+       animation-name: card-show-animation;
+       animation-duration: 0.5s;
+       position: relative;
+       padding: 0;
+}
+
+.card__remove-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?
+       /* @embed */
+       background: url(../images/clear.png) no-repeat scroll 10px center 
#FFFFFF;
+       /* @embed */
+       background-image: -webkit-linear-gradient(transparent, transparent), 
url(../images/clear.svg);
+       /* @embed */
+       background-image: linear-gradient(transparent, transparent), 
url(../images/clear.svg);
+       background-size: 15px;
+       padding: 5px 10px 5px 32px;
+       cursor: pointer;
+       clear: both;
+       border-top: 1px solid #dddddd;
+}
+
+.card__reference-number {
+       .mw-ui-item;
+       .mw-ui-one-fifth;
+       background-color: #FFFFFF;
+       padding: 0;
+       text-align: center;
+       color: #565656;
+       font-size: large;
+}
+
+.card__reference-content {
+       .mw-ui-item;
+       .mw-ui-four-fifths;
+       color: #565656;
+       font-size: large;
+       padding: 4px;
+       padding-bottom: 15px;
+}
diff --git a/modules/translation/ext.cx.translation.js 
b/modules/translation/ext.cx.translation.js
index c79d303..76f2ee3 100644
--- a/modules/translation/ext.cx.translation.js
+++ b/modules/translation/ext.cx.translation.js
@@ -135,6 +135,12 @@
                // Adapt the links
                $section.adaptLinks( mw.cx.targetLanguage );
                $section.find( 'img' ).adaptImage( mw.cx.targetLanguage );
+               $section.on( 'click', '[typeof="mw:Extension/ref"]', function 
() {
+                       var $reference = $( this );
+                       mw.hook( 'mw.cx.select.reference' ).fire(
+                               $reference.text(), $reference.data( 'mw' ), 
$reference
+                       );
+               } );
                // Trigger input event so that the alignemnt is right.
                $section.on( 'input', keepAlignment )
                        .trigger( 'input' );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iec4f2d0d79497fe1019482444c00a6e9f3c513e4
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: Divec <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to