Minor modernizations of variable declarations
Change-Id: I4de35f057a5b7f5c01865a2be77c7508ad1b4eb5
diff --git a/dev/js/src/api.js b/dev/js/src/api.js
index 059e638..8eeedf4 100644
--- a/dev/js/src/api.js
+++ b/dev/js/src/api.js
@@ -1,34 +1,35 @@
define(['util'], function () {
- // TODO: https://github.com/honza/140medley/blob/master/140medley.js
- // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
- // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
- // r.addEventListener("progress", updateProgress, false);
- // http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
- // http://stackoverflow.com/questions/6112744/load-javascript-on-demand
+ "use strict";
+
+ // TODO:
+ // - https://github.com/honza/140medley/blob/master/140medley.js
+ // - https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
+ // - https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
+ // - r.addEventListener("progress", updateProgress, false);
+ // - http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
+ // - http://stackoverflow.com/questions/6112744/load-javascript-on-demand
KorAP.URL = KorAP.URL !== undefined ? KorAP.URL : '';
-
KorAP.API = KorAP.API || {};
+ const legacySigle = new RegExp('^([^_]+)_([^\\.]+)\\.(.+?)$');
+
/**
* Retrieve information about a match
*/
KorAP.API.getMatchInfo = function (match, param, cb) {
// match is a KorAP.Match object
- var url = KorAP.URL;
- url += '/corpus';
+ let url = KorAP.URL + '/corpus';
/*
url += '/' + match.corpusID;
url += '/' + match.docID;
url += '/' + match.textID;
*/
- var legacySigle = new RegExp('^([^_]+)_([^\\.]+)\\.(.+?)$');
-
// This is for legacy support
- var legacy = legacySigle.exec(match.textSigle);
- var docFragment = "";
+ const legacy = legacySigle.exec(match.textSigle);
+ let docFragment = "";
if (legacy !== null && legacy[0]) {
docFragment = legacy[1] + '/' + legacy[2] + '/' + legacy[3];
}
@@ -70,9 +71,7 @@
KorAP.API.getTextInfo = function (doc, param, cb) {
// doc is a KorAP.Match object
- var url = KorAP.URL;
- url += '/corpus';
- url += '/' + doc.textSigle;
+ let url = KorAP.URL + '/corpus' + '/' + doc.textSigle;
if (param['fields'] !== undefined) {
url += '?fields='; // TODO!
@@ -80,6 +79,7 @@
else {
url += '?fields=@all'; // TODO: Maybe '*'?
}
+
KorAP.API.getJSON(url, cb, "TextInfo: " + doc.textSigle);
};
@@ -91,24 +91,6 @@
KorAP.API.getJSON(KorAP.URL + '/collection', cb, "CorpusInfo");
};
-
- /**
- * Retrieve information about corpus statistic
- *
- * Development mode:
- * URL = http://localhost:8089/api
- *
- * collectionQuery has be changed to corpusQuery
- */
- /* KorAP.API.getCorpStat = function (collQu, cb){
- //development mode:
- var url = "http://localhost:8089/api/";
- url = url + "statistics";
- url = url + "?cq=";
- url = url + collQu;
- KorAP.API.getJSON(url, cb);
- };*/
-
/**
* Retrieve information about corpus statistic
@@ -121,20 +103,20 @@
* http://localhost:3000/corpus?cq=availability+%3D+%2FCC-BY.*%2F+%26+textClass+%3D+%22kultur%22
*/
KorAP.API.getCorpStat = function (cq, cb){
- var url = KorAP.URL;
- url += "/corpus?cq=" + encodeURIComponent(cq);
+ let url = KorAP.URL + "/corpus?cq=" + encodeURIComponent(cq);
KorAP.API.getJSON(url, cb, "CorpusInfo: " + cq);
};
+
/**
* General method to retrieve JSON information
*/
KorAP.API.getJSON = function (url, onload, title) {
- var req = new XMLHttpRequest();
+ const req = new XMLHttpRequest();
req.open("GET", url, true);
// Dispatch global "window" event
- var reqE = new CustomEvent('korapRequest', {
+ const reqE = new CustomEvent('korapRequest', {
bubbles : false,
detail: {
"url" : url,
@@ -156,7 +138,7 @@
*/
if (this.readyState == 4) {
- var json;
+ let json;
try {
json = JSON.parse(this.responseText);
}
@@ -166,11 +148,13 @@
onload(undefined);
return;
};
+
if (json !== undefined && json["errors"] !== undefined) {
json["errors"].forEach(
e => KorAP.log(e[0], e[1] || "Unknown")
);
}
+
else if (this.status !== 200) {
KorAP.log(this.status, this.statusText);
};
@@ -178,11 +162,13 @@
if (this.status === 200) {
onload(json);
}
+
else {
onload(undefined);
};
}
};
+
req.ontimeout = function () {
KorAP.log(0, 'Request Timeout');
};
diff --git a/dev/js/src/buttongroup.js b/dev/js/src/buttongroup.js
index 29453c3..7c8d8c6 100644
--- a/dev/js/src/buttongroup.js
+++ b/dev/js/src/buttongroup.js
@@ -11,8 +11,8 @@
// Initialize button group
_init : function (classes) {
- var e = document.createElement('div');
- var cl = e.classList;
+ const e = document.createElement('div');
+ const cl = e.classList;
if (classes) {
cl.add.apply(cl,classes);
};
@@ -51,7 +51,7 @@
*/
add : function (title, data, cb) {
- var b = this._element.addE('span');
+ const b = this._element.addE('span');
b.setAttribute('title',title);
if (data !== undefined) {
@@ -70,14 +70,14 @@
b.addE('span').addT(title);
- var that = this;
+ let that = this;
b.addEventListener('click', function (e) {
// Do not bubble
e.halt();
// Call callback
- var obj = that._bind || this;
+ let obj = that._bind || this;
obj.button = b;
cb.apply(obj, e)
});
@@ -92,13 +92,12 @@
* Returns the list object.
*/
addList : function (title, data, itemClass = defaultItemClass) {
- var list = treeMenuClass.create([], itemClass);
+ const list = treeMenuClass.create([], itemClass);
this.add(title, data, function (e) {
list.show();
list.button(this.button);
list.focus();
});
-
return list;
},
@@ -107,17 +106,20 @@
* The state has to be a state object.
*/
addToggle : function (title, data, state) {
- let b = this._element.addE('span');
+ const b = this._element.addE('span');
b.setAttribute('title',title);
if (data != undefined) {
if (data['cls'] !== undefined) {
- b.classList.add.apply(b.classList, data['cls']);
+ b.classList.add.apply(
+ b.classList,
+ data['cls']
+ );
};
};
// Set check marker
- let check = b.addE('span');
+ const check = b.addE('span');
check.classList.add("check", "button-icon");
check.addE('span');
diff --git a/dev/js/src/buttongroup/menu.js b/dev/js/src/buttongroup/menu.js
index bebaac4..3ee7ec3 100644
--- a/dev/js/src/buttongroup/menu.js
+++ b/dev/js/src/buttongroup/menu.js
@@ -16,12 +16,12 @@
* as an array of arrays.
*/
create : function (list, itemClass) {
- var obj = Object.create(menuClass)
- .upgradeTo(this)
- ._init(list, {itemClass : itemClass});
+ const obj = Object.create(menuClass)
+ .upgradeTo(this)
+ ._init(list, {itemClass : itemClass});
obj.limit(6);
- var e = obj.element();
+ const e = obj.element();
// This is only domspecific
e.addEventListener('blur', function (e) {
@@ -36,6 +36,7 @@
return obj;
},
+
/**
* The panel object of the menu.
*/
@@ -46,12 +47,12 @@
return this._panel;
},
+
// Attach menu to button
button : function (btn) {
this._button = btn;
- // this._attached = e;
this._repos(this._button);
this.slider().reInit();
@@ -70,7 +71,7 @@
window.addEventListener('scroll', this._onscroll);
},
-
+
// Overwrite onHide method
onHide : function () {
@@ -82,7 +83,7 @@
},
_repos : function (e) {
- var bounding = e.getBoundingClientRect();
+ const bounding = e.getBoundingClientRect();
this._element.style.left = bounding.left + "px";
this._element.style.top = (
bounding.top +