From b2968a2521311b3ffbbe69d02093fba176badd77 Mon Sep 17 00:00:00 2001
From: Matthias Konitzny <konitzny@ibr.cs.tu-bs.de>
Date: Fri, 17 Dec 2021 16:56:00 +0100
Subject: [PATCH] Added "mode" shortcode attribute to control graph behaviour

---
 config.js           |  1 +
 display/graph.js    |  5 ++++-
 knowledge-space.php | 21 +++++++++++++++++++--
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/config.js b/config.js
index 6ee5b97..42eee97 100644
--- a/config.js
+++ b/config.js
@@ -13,6 +13,7 @@ export const COLOR_PALETTE = [
 // Just renaming a variable which is given by the PHP script. This avoids errors in all other files.
 export const PLUGIN_PATH = ks_global.plugin_path;
 export var SPACE = ks_global.space_id;
+export const MODE = ks_global.mode;
 
 export function setSpace(space) {
     SPACE = space;
diff --git a/display/graph.js b/display/graph.js
index 78334e8..c1c9b79 100644
--- a/display/graph.js
+++ b/display/graph.js
@@ -9,6 +9,7 @@ import {
     CSS3DRenderer,
     CSS3DSprite,
 } from "three/examples/jsm/renderers/CSS3DRenderer.js";
+import { MODE } from "../config";
 
 /**
  * The main ForceGraph. Displays the graph and handles all connected events.
@@ -60,7 +61,9 @@ export default class Graph {
             .linkWidth((link) => this.getLinkWidth(link))
             .onNodeClick((node) => {
                 this.focusOnNode(node);
-                this.infoOverlay.updateInfoOverlay(node);
+                if (MODE === "default") {
+                    this.infoOverlay.updateInfoOverlay(node);
+                }
             })
             .onNodeHover((node) => {
                 this.onNodeHover(node);
diff --git a/knowledge-space.php b/knowledge-space.php
index fb88381..c9fc7b6 100644
--- a/knowledge-space.php
+++ b/knowledge-space.php
@@ -21,6 +21,14 @@ function ks_add_graph($atts = []): string
     return $div;
 }
 
+function parse_atts($atts)
+{
+    return shortcode_atts(array(
+        'space' => 'space',
+        'mode' => 'default'
+    ), $atts);
+}
+
 function ks_echo_graph($atts = []): void
 {
     echo ks_add_graph($atts);
@@ -28,7 +36,15 @@ function ks_echo_graph($atts = []): void
 
 function ks_localize($handle, $atts)
 {
-    $space_id = kg_get_space_id_from_atts($atts);
+    $params = parse_atts($atts);
+    if ($GLOBALS['build'] == 'debug'){
+        echo '<pre>';
+        echo "Shortcode attributes:<br>";
+        print_r($params);
+        echo '</pre>';
+    }
+
+    $space_id = kg_get_space_id_from_atts($atts); // TODO: Replace with $params
     $plugin_dir = plugin_dir_url(__FILE__);
     wp_localize_script(
         $handle,
@@ -36,7 +52,8 @@ function ks_localize($handle, $atts)
         array(
             'ajax_url' => admin_url('admin-ajax.php'),
             'space_id' => $space_id,
-            'plugin_path' => $plugin_dir
+            'plugin_path' => $plugin_dir,
+            'mode' => $params['mode']
         )
     );
 }
-- 
GitLab