From 1933f1a6847bc0b1ace2f0074b5f73640a40d7dd Mon Sep 17 00:00:00 2001
From: PkSM3 <pokesam3@gmail.com>
Date: Tue, 4 Nov 2014 15:36:05 +0100
Subject: [PATCH] bugfix in specific-mouse-behaviour

---
 extras_explorerjs.js    |  4 +--
 tinawebJS/enviroment.js |  3 +-
 tinawebJS/main.js       | 12 ++++----
 tinawebJS/methods.js    | 61 +++++++++++++++++++++--------------------
 zearcher.sh             |  2 +-
 5 files changed, 42 insertions(+), 40 deletions(-)

diff --git a/extras_explorerjs.js b/extras_explorerjs.js
index 8bbab3c..ff42251 100755
--- a/extras_explorerjs.js
+++ b/extras_explorerjs.js
@@ -73,13 +73,13 @@ function clickInCountry( CC ) {
     $.doTimeout(20,function (){
 
         if(swclickActual=="social") {
-            MultipleSelection(results);
+            MultipleSelection(results , false); //false-> dont apply deselection algorithm
             return;
         }
 
         if(swclickActual=="semantic") {
             var oposresults = getNeighs2( results , bipartiteD2N );
-            MultipleSelection(oposresults);
+            MultipleSelection(oposresults , false);
             return;
         }
 
diff --git a/tinawebJS/enviroment.js b/tinawebJS/enviroment.js
index 517c06b..bd1c66b 100755
--- a/tinawebJS/enviroment.js
+++ b/tinawebJS/enviroment.js
@@ -583,11 +583,10 @@ function search(string) {
         coincd.push(results[i].id)
     }    
     $.doTimeout(30,function (){
-        MultipleSelection(coincd);
+        MultipleSelection(coincd , true);
         $("input#searchinput").val("");
         $("input#searchinput").autocomplete( "close" );
     });
-    
 }
 
 //============================ < / SEARCH > ============================//
diff --git a/tinawebJS/main.js b/tinawebJS/main.js
index 23393b0..8fe280b 100755
--- a/tinawebJS/main.js
+++ b/tinawebJS/main.js
@@ -342,7 +342,7 @@ function theListeners(){
                 	coincidences.push(matches[j].id)
                 }
                 $.doTimeout(30,function (){
-                	MultipleSelection(coincidences);
+                	MultipleSelection(coincidences , true);//true-> apply deselection algorithm
                     $("input#searchinput").val("");
                     $("input#searchinput").autocomplete( "close" );
                 });
@@ -357,7 +357,7 @@ function theListeners(){
             var exfnd = exactfind( $("#searchinput").val() )
 
 			$.doTimeout(30,function (){
-                	MultipleSelection(exfnd.id);
+                	MultipleSelection(exfnd.id , true);//true-> apply deselection algorithm
                     $("input#searchinput").val("");
                     $("input#searchinput").autocomplete( "close" );
             });     
@@ -494,10 +494,12 @@ function theListeners(){
                         }
                         cancelSelection(false);
                         cpCountTypes = Object.keys(countTypes);
-                        if(cpCountTypes.length==1)  MultipleSelection(Object.keys(dummyarray));
-                        else MultipleSelection(actualSel);
+                        if(cpCountTypes.length==1)
+                            MultipleSelection(Object.keys(dummyarray) , true);//true-> apply deselection algorithm
+                        else
+                            MultipleSelection(actualSel , true);//true-> apply deselection algorithm
 
-                    } else MultipleSelection(actualSel);
+                    } else MultipleSelection(actualSel , true);//true-> apply deselection algorithm
 
                     // //The most brilliant way of knowing if an array is empty in the world of JavaScript
                     i=0; for(var s in actualSel) { i++; break;}
diff --git a/tinawebJS/methods.js b/tinawebJS/methods.js
index 5bb92e8..19c7d54 100755
--- a/tinawebJS/methods.js
+++ b/tinawebJS/methods.js
@@ -504,7 +504,7 @@ function graphTagCloudElem(nodes) {
 	RefreshState(vars[1]);
 	swMacro=false;
 
-	MultipleSelection(ndsids);
+	MultipleSelection(ndsids , false);//false-> dont apply deselection algorithm
 
 	$.doTimeout(10,function (){
 		fa2enabled=true; partialGraph.startForceAtlas2();
@@ -1034,7 +1034,7 @@ function DrawAsSelectedNodes( nodeskeys ) {
     overNodes=true; 
 }
 
-function MultipleSelection(nodes){
+function MultipleSelection(nodes , desalg){
 
 	pr("IN MULTIPLE SELECTION: checkbox="+checkBox)
 
@@ -1050,32 +1050,35 @@ function MultipleSelection(nodes){
 
 	if(!checkBox) {
 		checkBox=true;
-
-        if(PAST=="--") {
-            pr("faire rien")
-        } else {
-            if(!is_empty(prevsels) && PAST==NOW ) {
-                var blacklist = {};
-                for(var i in ndsids) {
-                    ID = ndsids[i];
-                    if ( prevsels[ID] ) {
-                        delete prevsels[ID];
-                        blacklist[ID] = true;
-                    }
+        printStates();
+        pr("prevsels:")
+        pr(Object.keys(prevsels))
+        pr("ndsids:")
+        pr(ndsids)
+
+        if (desalg && !is_empty(prevsels) ) {
+            pr("DOING THE WEIRD ALGORITHM")
+            var blacklist = {};
+            for(var i in ndsids) {
+                ID = ndsids[i];
+                if ( prevsels[ID] ) {
+                    delete prevsels[ID];
+                    blacklist[ID] = true;
                 }
+            }
 
-                if(Object.keys(blacklist).length>0) {
-                    tmparr = Object.keys(prevsels);
-                    for (var i in ndsids) {
-                        ID = ndsids[i];
-                        if(isUndef(blacklist[ID])) {
-                            tmparr.push(ID)
-                        }
+            if(Object.keys(blacklist).length>0) {
+                tmparr = Object.keys(prevsels);
+                for (var i in ndsids) {
+                    ID = ndsids[i];
+                    if(isUndef(blacklist[ID])) {
+                        tmparr.push(ID)
                     }
-                    ndsids = tmparr;
                 }
+                ndsids = tmparr;
             }
-        }
+        } else pr("CASE NOT COVERED")
+        
 
         if (ndsids.length>0) {
     		for(var i in ndsids) {
@@ -1156,7 +1159,7 @@ function hoverNodeEffectWhileFA2(selectionRadius) {
             if(cursor_size==0 && !checkBox){
                 //Normal click on a node
                 $.doTimeout(30,function (){
-                    MultipleSelection(nodeID);
+                    MultipleSelection(nodeID , true);//true-> apply deselection algorithm
                 });
             }
             
@@ -1164,7 +1167,7 @@ function hoverNodeEffectWhileFA2(selectionRadius) {
                 //Normal click on a node, but we won't clean the previous selections
 			    selections[nodeID] = 1;
                 $.doTimeout(30,function (){
-                    MultipleSelection( Object.keys(selections) );
+                    MultipleSelection( Object.keys(selections) , true );//true-> apply deselection algorithm
                 });
             }
         }
@@ -1695,9 +1698,7 @@ function changeToMeso(iwannagraph) {
 
     fa2enabled=true; partialGraph.startForceAtlas2();
 
-    pr("inside multipleselection:")
-    printStates();
-    MultipleSelection(Object.keys(selections));
+    MultipleSelection(Object.keys(selections) , false);//false-> dont apply deselection algorithm
 
     $('.gradient').css({"background-size":"90px 90px"});
 }
@@ -1741,7 +1742,7 @@ function changeToMacro(iwannagraph) {
         if (!is_empty(selections))
         	$.doTimeout(10,function (){
         		chosenones=(PAST=="a"||PAST=="b")?selections:opossites;
-        		MultipleSelection(Object.keys(chosenones))
+        		MultipleSelection(Object.keys(chosenones) , false)//false-> dont apply deselection algorithm
         	});
 
     } else {
@@ -1775,7 +1776,7 @@ function changeToMacro(iwannagraph) {
         }
 
         if (!is_empty(selections))
-            MultipleSelection(Object.keys(selections));
+            MultipleSelection(Object.keys(selections) , false);//false-> dont apply deselection algorithm
     }
 
     $.doTimeout(30,function (){
diff --git a/zearcher.sh b/zearcher.sh
index f7b6adc..5b401d4 100755
--- a/zearcher.sh
+++ b/zearcher.sh
@@ -31,7 +31,7 @@ function test2 {
 	for f in $iter
 	do
 		filename=`echo $f | sed s/"\.\/"//g`
-		variable=`cat $filename | grep "fa2enabled"`
+		variable=`cat $filename | grep "MultipleSelection"`
 		if [[ "$variable" != "" ]]
 		then
 			echo $filename
-- 
2.21.0