Activate plugin registry

Change-Id: I1c9305b21081b8f754adedc49326a3cab578df29
diff --git a/Changes b/Changes
index 82ba6c3..7a5b276 100755
--- a/Changes
+++ b/Changes
@@ -1,8 +1,8 @@
-0.39 2020-06-25
+0.39 2020-06-30
         - Add information on secret file to Readme.
         - Change default API endpoint to korap.ids-mannheim.de.
-        - Add information on secret file to Readme.
         - Fix label for toggle plugins.
+        - Activate plugin registry.
 
         WARNING: If you relied on the former default API endpoint
           being http://localhost:9999/, this will break your
diff --git a/dev/demo/plugin-serverdemo.js b/dev/demo/plugin-serverdemo.js
index 096050f..52d6609 100644
--- a/dev/demo/plugin-serverdemo.js
+++ b/dev/demo/plugin-serverdemo.js
@@ -6,59 +6,41 @@
 });
 
 
+KorAP.Plugins = [{
+  'name' : 'Export',
+  'desc' : 'Exports Kalamar results',
+  // 'about' : 'https://localhost:5678/',
+  'embed' : [{
+    'panel' : 'result',
+    'title' : 'Export',
+    'classes' : ['export'],
+    'onClick' : {
+      'action' : 'addWidget',
+      'template' : 'http://localhost:3003/demo/plugin-client.html',
+    }
+  },{
+    'panel' : 'result',
+    'title' : 'Glemm',
+    'onClick' : {
+      'action' : 'toggle',
+      'state' : 'glemm',
+      'template' : 'http://localhost:3003/demo/plugin-client.html',
+    }
+  }]
+},{
+  'name' : 'Example New',
+  'desc' : 'Some content about cats',
+  // 'about' : 'https://localhost:5678/',
+  'embed' : [{
+    'panel' : 'match',
+    'title' : 'Translate',
+    'classes' : ['translate'],
+    'onClick' : {
+      'action' : 'addWidget',
+      'template' : 'http://localhost:3003/demo/plugin-client.html',
+    }
+  }]
+}]; 
 
 
-define(['app/en','match', 'panel/match', 'panel/result', 'plugin/server','pipe','lib/domReady','init'], function (lang, matchClass, matchPanelClass, resultPanelClass, pluginClass, pipeClass, domReady) {
-  domReady(function () {
- 
-    // Load Plugin Server first 
-    KorAP.Plugin = pluginClass.create();
-
-    // Add services container to head
-    document.head.appendChild(KorAP.Plugin.element());
-
-    // Add pipe form
-    KorAP.Pipe = pipeClass.create();
-    document.getElementById("searchform").appendChild(KorAP.Pipe.element());
-    
-    //Register result plugin
-    KorAP.Plugin.register({
-       'name' : 'Export',
-       'desc' : 'Exports Kalamar results',
-       // 'about' : 'https://localhost:5678/',
-       'embed' : [{
-         'panel' : 'result',
-         'title' : 'Export',
-         'classes' : ['export'],
-         'onClick' : {
-           'action' : 'addWidget',
-           'template' : 'http://localhost:3003/demo/plugin-client.html',
-         }
-       },{
-         'panel' : 'result',
-         'title' : 'Glemm',
-         'onClick' : {
-           'action' : 'toggle',
-           'state' : 'glemm',
-           'template' : 'http://localhost:3003/demo/plugin-client.html',
-         }
-       }]
-     }); 
-
-    // Register match plugin
-    KorAP.Plugin.register({
-      'name' : 'Example New',
-      'desc' : 'Some content about cats',
-      // 'about' : 'https://localhost:5678/',
-      'embed' : [{
-        'panel' : 'match',
-        'title' : 'Translate',
-        'classes' : ['translate'],
-        'onClick' : {
-          'action' : 'addWidget',
-          'template' : 'http://localhost:3003/demo/plugin-client.html',
-        }
-      }]
-    });
-  });
-});
+require(['app/en','init']);
diff --git a/dev/js/spec/pipeSpec.js b/dev/js/spec/pipeSpec.js
index 078d4b1..93bf172 100644
--- a/dev/js/spec/pipeSpec.js
+++ b/dev/js/spec/pipeSpec.js
@@ -93,6 +93,7 @@
       let p = pipeClass.create();
       let e = p.element();
       expect(e.tagName).toEqual("INPUT");
+      expect(e.getAttribute("type")).toEqual("text");
       p.append('service1');
       expect(e.getAttribute("value")).toEqual("service1");
       p.append('service2');
diff --git a/dev/js/src/init.js b/dev/js/src/init.js
index 62d0800..f9eaa13 100644
--- a/dev/js/src/init.js
+++ b/dev/js/src/init.js
@@ -28,6 +28,8 @@
   'panel/result',
   'panel/query',
   'tour/tours',
+  'plugin/server',
+  'pipe',
   'api',
   'mailToChiffre',
   'util',
@@ -43,7 +45,9 @@
              selectMenuClass,
              resultPanelClass,
              queryPanelClass,
-             tourClass) {
+             tourClass,
+             pluginClass,
+             pipeClass) {
 
   const d = document;
 
@@ -420,7 +424,34 @@
       sform.insertBefore(queryPanel.element(), vcView);
       KorAP.Panel['query'] = queryPanel;
     }
-    
+
+    /**
+     * Initialize Plugin registry.
+     */
+    let p = KorAP.Plugins;
+    if (p && p.length > 0) {
+      // Load Plugin Server first
+      KorAP.Plugin = pluginClass.create();
+
+      // Add services container to head
+      d.head.appendChild(KorAP.Plugin.element());
+
+      // Add pipe form
+      KorAP.Pipe = pipeClass.create();
+      d.getElementById("searchform").appendChild(KorAP.Pipe.element());
+
+      try {
+      
+        // Register all plugins
+        for (var i = 0; i < p.length; i++) {
+          KorAP.Plugin.register(p[i]);
+        }
+      }
+      catch (e) {
+        KorAP.log(0, e);
+      }
+    };
+
     return obj;
   });
   
diff --git a/dev/js/src/plugin/service.js b/dev/js/src/plugin/service.js
index be567be..3152f38 100644
--- a/dev/js/src/plugin/service.js
+++ b/dev/js/src/plugin/service.js
@@ -30,7 +30,13 @@
     load : function () {
       if (this._load)
         return this._load;
-      
+
+      if (window.location.protocol == 'https:' &&
+          this.src.toLowerCase().indexOf('https:') != 0) {
+        KorAP.log(0, "Service endpoint is insecure");
+        return;
+      };
+
       // Spawn new iframe
       let e = document.createElement('iframe');
       e.setAttribute('allowTransparency',"true");
diff --git a/dev/js/src/view.js b/dev/js/src/view.js
index fa830d6..d0a517c 100644
--- a/dev/js/src/view.js
+++ b/dev/js/src/view.js
@@ -53,8 +53,14 @@
         cl.add.apply(cl, this._classes);
 
       // TODO: The show may need to be wrapped in another DIV!
-      if (this.show !== undefined)
-        e.appendChild(this.show());
+      if (this.show !== undefined) {
+        let s = this.show();
+        if (s) {
+          e.appendChild(s);
+        } else {
+          return e
+        }
+      }
 
       this._shown = true;
 
diff --git a/dev/scss/header/header.scss b/dev/scss/header/header.scss
index 20f1e67..65e2483 100644
--- a/dev/scss/header/header.scss
+++ b/dev/scss/header/header.scss
@@ -159,3 +159,9 @@
   color: transparent;
   text-shadow: 0 0 0 white;
 }
+
+
+// Hide pipe
+input.pipe {
+  display: none;
+}
\ No newline at end of file
diff --git a/package.json b/package.json
index 6e451ba..97bed86 100755
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "name": "Kalamar",
   "description": "Mojolicious-based Frontend for KorAP",
   "license": "BSD-2-Clause",
-  "version": "0.39.0",
+  "version": "0.39.1",
   "pluginVersion": "0.2",
   "engines": {
     "node": ">=6.0.0"