Add dynamic loading of javascript configurations (closes #173)

Change-Id: Icfb6082aee88930eca2361196b8d91ff5a796172
diff --git a/dev/js/src/init.js b/dev/js/src/init.js
index 1e9a805..24c2348 100644
--- a/dev/js/src/init.js
+++ b/dev/js/src/init.js
@@ -15,6 +15,7 @@
  * - obj.alignment() // toggle
  */
 
+
 "use strict";
 define([
   'match',
@@ -95,21 +96,46 @@
     gt.addEventListener('click', function(){
       tourClass.gTstartSearch().start();
     });
-    
+
     KorAP.tourshowR = function(){
       tourClass.gTshowResults().start();
     };
   };
 
+
+  addHintM = function(scripte, file){
+    KorAP.annotationHelper = KorAP.annotationHelper || { '-' : [] };
+    let scriptEl = scripte;
+    scriptEl.setAttribute("type", "text/javascript");
+    scriptEl.setAttribute("async", "async");
+    scriptEl.setAttribute("defer", "defer");
+    scriptEl.setAttribute("src", "require.js");
+    scriptEl.setAttribute("data-main", file);
+    document.getElementsByTagName("head")[0].appendChild(scriptEl);
+  };
+
   domReady(function (event) {
-      
+
     var obj = {};
 
     // What should be visible in the beginning?
     var show = KorAP.session.get('show') || {};
-    
+
     KorAP.Panel = KorAP.Panel || {}
 
+    var scriptElement =document.createElement("script")
+    fetch("kalamar.conf.js", { method: "HEAD" })
+      .then(response => {
+         if (response.ok) {
+          addHintM(scriptElement, "kalamar.conf.js");
+         } else {
+          addHintM(scriptElement, "default.js");
+         }
+     })
+     .catch(error => {
+         KorAP.log(0, "No kalamar.conf.js or default.js file");
+      });
+
     /**
      * Release notifications
      */
@@ -270,9 +296,8 @@
       sb.insertBefore(resultPanel.element(), sb.firstChild);
     };
 
-    
     // There is a koralQuery
-    if (KorAP.koralQuery !== undefined) {    
+    if (KorAP.koralQuery !== undefined) {
 
       // Add KoralQuery view to result panel
       if (resultInfo !== null) {
@@ -406,13 +431,12 @@
         d.getElementById('qsubmit').classList.add("loading");
       });
     };
- 
-    
+
     //Starts the guided tour at the next page
     if(KorAP.session.get("tour")){
       tourClass.gTshowResults().start();
     }
-    
+
     /**
      * Init hint helper
      * has to be final because of
@@ -420,13 +444,12 @@
      */
     // Todo: Pass an element, so this works with
     // tutorial pages as well!
+    scriptElement.onload = function(){
     if (obj.hint === undefined)
       obj.hint = hintClass.create();
-
-    // Add the hinthelper to the KorAP object to make it manipulatable globally
-    KorAP.Hint = obj.hint;
-
-
+      // Add the hinthelper to the KorAP object to make it manipulatable globally
+      KorAP.Hint = obj.hint;
+    };
     /**
      * Add query panel
      */