Santhosh has uploaded a new change for review.

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

Change subject: Links card: Remove link feature
......................................................................

Links card: Remove link feature

Change-Id: I2fcfc8ff12e06a685cff428feb191119d585e769
---
M Resources.php
M i18n/en.json
M i18n/qqq.json
M modules/tools/ext.cx.tools.js
A modules/tools/ext.cx.tools.link.js
A modules/tools/styles/ext.cx.tools.link.less
M modules/translation/ext.cx.translation.js
7 files changed, 118 insertions(+), 3 deletions(-)


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

diff --git a/Resources.php b/Resources.php
index a767996..2fe558b 100644
--- a/Resources.php
+++ b/Resources.php
@@ -108,6 +108,7 @@
                'ext.cx.tools.manager',
                'ext.cx.tools.dictionary',
                'ext.cx.tools.instructions',
+               'ext.cx.tools.link'
        ),
 ) + $resourcePaths;
 
@@ -148,6 +149,21 @@
        ),
 ) + $resourcePaths;
 
+$wgResourceModules['ext.cx.tools.link'] = array(
+       'scripts' => array(
+               'tools/ext.cx.tools.link.js',
+       ),
+       'styles' => array(
+               'tools/styles/ext.cx.tools.link.less',
+       ),
+       'messages' => array(
+               'cx-tools-link-remove',
+       ),
+       'dependencies' => array(
+               'ext.cx.tools.manager',
+       ),
+) + $resourcePaths;
+
 $wgResourceModules['ext.cx.progressbar'] = array(
        'scripts' => 'tools/ext.cx.progressbar.js',
        'styles' => array(
diff --git a/i18n/en.json b/i18n/en.json
index bd9d8cb..5803fb9 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -36,5 +36,6 @@
        "cx-tools-instructions-text6": "When you are happy with the result, 
press \"{{int:cx-publish-button}}\".",
        "cx-tools-searchbox-text": "Search for a word",
        "cx-tools-view-guidelines": "[$1 View translation guidelines]",
-       "cx-tools-dictionary-title": "Definition"
+       "cx-tools-dictionary-title": "Definition",
+       "cx-tools-link-remove": "Remove link"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 0571e0e..09109e7 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -39,5 +39,6 @@
        "cx-tools-searchbox-text": "Placeholder text for the searchbox on the 
translation tools column",
        "cx-tools-dictionary-title": "Used as the title for a card that shows 
dictinary definition.",
        "cx-tools-view-guidelines": "Parameters:\n* $1 - the URL pointing to 
the guidelines for translation in Wikipedia",
-       "cx-tools-dictionary-title": "Title of definition tool card"
+       "cx-tools-dictionary-title": "Title of definition tool card",
+       "cx-tools-link-remove": "Text shown in link tool card. Clicking on it 
removes the link in the context"
 }
diff --git a/modules/tools/ext.cx.tools.js b/modules/tools/ext.cx.tools.js
index 4f2f8ce..2efb8f0 100644
--- a/modules/tools/ext.cx.tools.js
+++ b/modules/tools/ext.cx.tools.js
@@ -28,6 +28,7 @@
                this.$searchBox.find( 'input' ).keypress( function ( event ) {
                        if ( event.which === 13 ) {
                                mw.hook( 'mw.cx.search.word' ).fire( $( this 
).val().trim().toLowerCase() );
+                               mw.hook( 'mw.cx.search.link'). fire( $( this 
).val().trim().toLowerCase() );
                        }
                } );
                mw.hook( 'mw.cx.tools.ready' ).fire();
diff --git a/modules/tools/ext.cx.tools.link.js 
b/modules/tools/ext.cx.tools.link.js
new file mode 100644
index 0000000..8fddfd6
--- /dev/null
+++ b/modules/tools/ext.cx.tools.link.js
@@ -0,0 +1,70 @@
+/**
+ * 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 LinkCard() {
+               this.$card = null;
+               this.$removeLink = null;
+               this.$link = null;
+       }
+
+       LinkCard.prototype.getCard = function () {
+
+               this.$card = $( '<div>' )
+                       .addClass( 'card link' );
+
+               this.$removeLink = $( '<div>' )
+                       .addClass( 'card__remove-link' )
+                       .text( mw.msg( 'cx-tools-link-remove' ) );
+
+               this.$card.append( this.$removeLink );
+               this.listen();
+               return this.$card;
+       };
+
+       LinkCard.prototype.removeLink = function () {
+               if ( this.$link ) {
+                       this.$link.after( this.$link.text() ).remove();
+                       this.$removeLink.hide();
+               }
+       };
+
+       LinkCard.prototype.listen = function () {
+               this.$removeLink.on( 'click', $.proxy( this.removeLink, this ) 
);
+       };
+
+       LinkCard.prototype.start = function ( link ) {
+               var word;
+               if ( typeof link === 'string' ) {
+                       word = link;
+               } else {
+                       this.$link = link;
+               }
+               if ( word === '' || !this.$link ) {
+                       this.stop();
+                       return;
+               }
+       };
+
+       LinkCard.prototype.stop = function () {
+               this.$card.remove();
+       };
+
+       LinkCard.prototype.getTriggerEvents = function () {
+               return [
+                       'mw.cx.select.link',
+                       'mw.cx.search.link'
+               ];
+       };
+
+       mw.cx.tools.link = LinkCard;
+}( jQuery, mediaWiki ) );
diff --git a/modules/tools/styles/ext.cx.tools.link.less 
b/modules/tools/styles/ext.cx.tools.link.less
new file mode 100644
index 0000000..a1a5e99
--- /dev/null
+++ b/modules/tools/styles/ext.cx.tools.link.less
@@ -0,0 +1,23 @@
+@import "../../base/styles/grid/agora-grid";
+
+.card__remove-link {
+       @vertical-margin: 10px;
+       @horizontal-margin: 15px;
+       .mw-ui-item;
+       .mw-ui-one-whole;
+       float: none; // XXX why would it be needed?
+       padding: @vertical-margin @horizontal-margin;
+       font-size: large;
+       line-height: 1.5em;
+       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: 20px;
+       padding: 0 10px 0 40px;
+       line-height: 2.5em;
+       cursor: pointer;
+}
diff --git a/modules/translation/ext.cx.translation.js 
b/modules/translation/ext.cx.translation.js
index c3c622a..cba2b96 100644
--- a/modules/translation/ext.cx.translation.js
+++ b/modules/translation/ext.cx.translation.js
@@ -75,7 +75,7 @@
                this.$container.append( $content );
                mw.hook( 'mw.cx.translation.change' ).fire();
                this.$title = this.$container.find( '.cx-column__title' );
-               
+
                mw.hook( 'mw.cx.translation.ready' ).fire();
        };
 
@@ -107,6 +107,9 @@
 
                this.calculateCompletion();
                mw.hook( 'mw.cx.translation.change' ).fire();
+               $section.find( 'a[rel="mw:WikiLink"]' ).on( 'click', function 
() {
+                       mw.hook( 'mw.cx.select.link' ).fire( $( this ) );
+               } );
        };
 
        // TODO This is a dummy completeness calculation.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2fcfc8ff12e06a685cff428feb191119d585e769
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