Santhosh has uploaded a new change for review.

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

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/editor/ext.cx.editor.js
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
9 files changed, 180 insertions(+), 4 deletions(-)


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

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 ac07130..37fc74b 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -39,5 +39,7 @@
        "cx-tools-dictionary-title": "Definition",
        "cx-tools-link-title": "Link",
        "cx-tools-link-add": "Add link",
-       "cx-tools-link-remove": "Remove link"
+       "cx-tools-link-remove": "Remove link",
+       "cx-tools-reference-title": "Reference",
+       "cx-tools-reference-remove": "Remove reference"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index f38a1f8..eae49d7 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -41,5 +41,7 @@
        "cx-tools-dictionary-title": "Title of definition tool 
card.\n{{Identical|Definition}}",
        "cx-tools-link-title": "Title of link tool card.\n{{Identical|Link}}",
        "cx-tools-link-add": "Text shown in link tool card. Clicking on it adds 
the link in the cursor position.\n{{Identical|Add link}}",
-       "cx-tools-link-remove": "Text shown in link tool card. Clicking on it 
removes the link in the context.\n{{Identical|Remove link}}"
+       "cx-tools-link-remove": "Text shown in link tool card. Clicking on it 
removes the link in the context.\n{{Identical|Remove link}}",
+       "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/editor/ext.cx.editor.js b/modules/editor/ext.cx.editor.js
index 8876c23..7aa3207 100644
--- a/modules/editor/ext.cx.editor.js
+++ b/modules/editor/ext.cx.editor.js
@@ -75,7 +75,7 @@
        CXSectionEditor.prototype.wysiwygEditor = function () {
                var editorOptions;
 
-               if ( !MediumEditor ) {
+               if ( !window.MediumEditor ) {
                        return;
                }
                editorOptions = {
diff --git a/modules/source/ext.cx.source.js b/modules/source/ext.cx.source.js
index 5b14dbc..d02718a 100644
--- a/modules/source/ext.cx.source.js
+++ b/modules/source/ext.cx.source.js
@@ -113,7 +113,9 @@
                this.$content.find( 'a' ).bind( 'click', function () {
                        var $link = $( this );
                        // avoid all reference links
-                       if ( !$link.parent().hasClass( 'reference' ) ) {
+                       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
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 033ab8b..cd36430 100644
--- a/modules/translation/ext.cx.translation.js
+++ b/modules/translation/ext.cx.translation.js
@@ -130,6 +130,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: newchange
Gerrit-Change-Id: Iec4f2d0d79497fe1019482444c00a6e9f3c513e4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>

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

Reply via email to