Santhosh has uploaded a new change for review.

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

Change subject: Hide unrelated cards by checking intersection of trigger events
......................................................................

Hide unrelated cards by checking intersection of trigger events

Change-Id: Iabe9b5f10e41ed4425edcbc950c9c8d7e5796fdc
---
M modules/tools/ext.cx.tools.manager.js
1 file changed, 34 insertions(+), 0 deletions(-)


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

diff --git a/modules/tools/ext.cx.tools.manager.js 
b/modules/tools/ext.cx.tools.manager.js
index 680bc0f..79dcc03 100644
--- a/modules/tools/ext.cx.tools.manager.js
+++ b/modules/tools/ext.cx.tools.manager.js
@@ -118,6 +118,40 @@
                }
                tool.start.apply( tool, data );
                this.tools[ toolName ] = tool;
+               this.hideUnrelatedCards( toolName );
+       };
+
+       /**
+        * Find intersection of two arrays
+        * @param {Array} array1
+        * @param {Array} array2
+        * @reurn {Array} intersection array
+        */
+       function intersection( array1, array2 ) {
+               return array1.filter( function ( n ) {
+                       return array2.indexOf( n ) !== -1;
+               } );
+       }
+
+       /**
+        * Hide unrelated cards
+        * Find out cards not having trigger events intersecton and hide them.
+        * @param {string} currentToolName current tool name
+        */
+       CXToolManager.prototype.hideUnrelatedCards = function ( currentToolName 
) {
+               var currentToolEvents, toolEvents, toolName;
+               if ( this.tools[ currentToolName ] ) {
+                       currentToolEvents = this.tools[ currentToolName 
].getTriggerEvents();
+               }
+               for ( toolName in this.tools ) {
+                       if ( toolName === currentToolName ) {
+                               continue;
+                       }
+                       toolEvents = this.tools[ toolName ].getTriggerEvents();
+                       if ( intersection( currentToolEvents, toolEvents 
).length === 0 ) {
+                               this.hideCard( toolName );
+                       }
+               }
        };
 
        /**

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

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