From 3b46febd38f83bc6849cac0ec192e66fcc8b1db5 Mon Sep 17 00:00:00 2001
From: Christopher Pietsch <cpietsch@gmail.com>
Date: Sat, 24 Aug 2019 11:33:31 +0200
Subject: [PATCH] fixed deep hierarchical deselect on keywords

---
 js/tags.js  |  7 +++++--
 js/utils.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/js/tags.js b/js/tags.js
index 7bea397..d627aa9 100644
--- a/js/tags.js
+++ b/js/tags.js
@@ -254,10 +254,13 @@ function Tags() {
   tags.mouseclick = function (d) {
     lock = true;
 
-    console.log("clikc", d)
-
     if(filterWords.indexOf(d.key)>-1){
+      console.log(d.key, filterWords)
       _.remove(filterWords,function(d2){ return d2 == d.key; });
+      // if hierarchical keywords, could turn those into an array instead of strings
+      if(d.key.indexOf(":")){
+        filterWords = filterWords.filter(f => !f.startsWith(d.key))
+      }
     } else {
       filterWords.push(d.key);
     }
diff --git a/js/utils.js b/js/utils.js
index 0f37d83..13338d9 100644
--- a/js/utils.js
+++ b/js/utils.js
@@ -149,3 +149,60 @@ utils.simulateLargeDatasets = function(data){
 	Array.prototype.push.apply(data, _.clone(data, true).slice(0,1036))
 }
 
+
+
+
+if (!String.prototype.startsWith) {
+	(function() {
+		'use strict'; // needed to support `apply`/`call` with `undefined`/`null`
+		var defineProperty = (function() {
+			// IE 8 only supports `Object.defineProperty` on DOM elements
+			try {
+				var object = {};
+				var $defineProperty = Object.defineProperty;
+				var result = $defineProperty(object, object, object) && $defineProperty;
+			} catch(error) {}
+			return result;
+		}());
+		var toString = {}.toString;
+		var startsWith = function(search) {
+			if (this == null) {
+				throw TypeError();
+			}
+			var string = String(this);
+			if (search && toString.call(search) == '[object RegExp]') {
+				throw TypeError();
+			}
+			var stringLength = string.length;
+			var searchString = String(search);
+			var searchLength = searchString.length;
+			var position = arguments.length > 1 ? arguments[1] : undefined;
+			// `ToInteger`
+			var pos = position ? Number(position) : 0;
+			if (pos != pos) { // better `isNaN`
+				pos = 0;
+			}
+			var start = Math.min(Math.max(pos, 0), stringLength);
+			// Avoid the `indexOf` call if no match is possible
+			if (searchLength + start > stringLength) {
+				return false;
+			}
+			var index = -1;
+			while (++index < searchLength) {
+				if (string.charCodeAt(start + index) != searchString.charCodeAt(index)) {
+					return false;
+				}
+			}
+			return true;
+		};
+		if (defineProperty) {
+			defineProperty(String.prototype, 'startsWith', {
+				'value': startsWith,
+				'configurable': true,
+				'writable': true
+			});
+		} else {
+			String.prototype.startsWith = startsWith;
+		}
+	}());
+}
\ No newline at end of file
-- 
GitLab