Support default value for toggle embeddings

Change-Id: I2216bf73528deef0dc4d73f8cb5948655477e4a8
diff --git a/Changes b/Changes
index 6bcc53d..8f3d0cb 100755
--- a/Changes
+++ b/Changes
@@ -42,6 +42,7 @@
         - Support for inactive buttongroup items.
         - Support default values for state.
         - Introduce state manager (#119).
+        - Support default value for plugin toggle embeddings.
 
 0.42 2021-06-18
         - Added GitHub based CI for perl.
diff --git a/dev/js/spec/pluginSpec.js b/dev/js/spec/pluginSpec.js
index edffa59..973ad16 100644
--- a/dev/js/spec/pluginSpec.js
+++ b/dev/js/spec/pluginSpec.js
@@ -243,6 +243,72 @@
       KorAP.Panel["result"] = undefined;
     });
 
+    it('should accept valid registrations for toggle', function () {
+      let p = KorAP.Panel["result"] = panelClass.create();
+      
+      let manager = pluginServerClass.create();
+
+      manager.register({
+        name : 'Check',
+        embed : [{
+          panel : 'result',
+          title : 'Glemm',
+          onClick : {
+            template : 'about:blank',
+            action : 'toggle',
+            'default' : false
+          }
+        }]
+      });
+
+      let b = p.actions().element().firstChild;
+      expect(b.hasAttribute("data-icon")).toBeFalsy();
+      expect(b.hasAttribute("cls")).toBeFalsy();
+      expect(b.getAttribute("title")).toEqual("Glemm");
+      expect(b.firstChild.classList.contains('button-icon')).toBeTruthy();
+      expect(b.firstChild.classList.contains('check')).toBeTruthy();
+      expect(b.firstChild.classList.contains('checked')).toBeFalsy();
+
+      expect(p.element().querySelectorAll("iframe").length).toEqual(0);
+
+      b.click();
+
+      expect(b.getAttribute("title")).toEqual("Glemm");
+      expect(b.firstChild.classList.contains('button-icon')).toBeTruthy();
+      expect(b.firstChild.classList.contains('check')).toBeTruthy();
+      expect(b.firstChild.classList.contains('checked')).toBeTruthy();
+
+      // Check with true default
+      p = KorAP.Panel["result"] = panelClass.create();
+      
+      manager = pluginServerClass.create();
+
+      manager.register({
+        name : 'Check',
+        embed : [{
+          panel : 'result',
+          title : 'Glemm',
+          onClick : {
+            template : 'about:blank',
+            action : 'toggle',
+            'default' : true
+          }
+        }]
+      });
+
+      b = p.actions().element().firstChild;
+      expect(b.hasAttribute("data-icon")).toBeFalsy();
+      expect(b.hasAttribute("cls")).toBeFalsy();
+      expect(b.getAttribute("title")).toEqual("Glemm");
+      expect(b.firstChild.classList.contains('button-icon')).toBeTruthy();
+      expect(b.firstChild.classList.contains('check')).toBeTruthy();
+      expect(b.firstChild.classList.contains('checked')).toBeTruthy();
+
+      manager.destroy();
+      KorAP.Panel["result"] = undefined;
+    });
+
+    
     it('should alert on plugin info (1)', function () {
 
       let alertMsg;
diff --git a/dev/js/src/plugin/server.js b/dev/js/src/plugin/server.js
index 669708c..1fa0002 100644
--- a/dev/js/src/plugin/server.js
+++ b/dev/js/src/plugin/server.js
@@ -233,6 +233,10 @@
 
           let state = stateClass.create([true, false]);
 
+          if (onClick["default"] !== undefined) {
+            state.setIfNotYet(onClick["default"]);
+          };
+
           // TODO:
           //   Lazy registration (see above!)
           KorAP.Panel[panel].actions().addToggle(title, {'cls':["title"]}, state);