Add dynamic loading of javascript configurations (closes #173)
Change-Id: Icfb6082aee88930eca2361196b8d91ff5a796172
diff --git a/dev/js/src/hint.js b/dev/js/src/hint.js
index e700b94..ee5e344 100644
--- a/dev/js/src/hint.js
+++ b/dev/js/src/hint.js
@@ -25,11 +25,15 @@
'hint/contextanalyzer',
'hint/alert',
'util'
-], function (inputClass,
+], function (inputClass,
menuClass,
analyzerClass,
alertClass) {
+ //needed for localization
+ const loc = KorAP.Locale;
+ loc.HINT_noAnnot = loc.HINT_noAnnot || 'The assistant can not be displayed.';
+
// Initialize hint array
/**
@@ -266,10 +270,13 @@
* @param {boolean} Boolean value to indicate if context
* is necessary (true) or if the main context should
* be shown if context fails.
- *
+ *
*/
show : function (ifContext) {
-
+ if(KorAP.annotationHelper["-"].length == 0){
+ this.alert(0,loc.HINT_noAnnot);
+ return;
+ }
// Remove the active object
this._unshow();
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
*/
diff --git a/dev/js/src/loc/de.js b/dev/js/src/loc/de.js
index c5f83cc..d01479b 100644
--- a/dev/js/src/loc/de.js
+++ b/dev/js/src/loc/de.js
@@ -103,5 +103,6 @@
// Pagination panel
loc.RANDOM_PAGE = 'Zufallsseite';
-
+
+ loc.HINT_noAnnot = 'Der Assistent kann nicht angezeigt werden.';
});