Modernize for;;-loops
Change-Id: Ic6f86af0d674cc6643fc9eef2aa7431cfdf514f2
diff --git a/dev/js/src/match/corpusByMatch.js b/dev/js/src/match/corpusByMatch.js
index 43048a3..92d219a 100644
--- a/dev/js/src/match/corpusByMatch.js
+++ b/dev/js/src/match/corpusByMatch.js
@@ -66,9 +66,10 @@
return;
};
- for (let doc of this._fragment.documents()) {
+
+ for (const doc of this._fragment.documents()) {
vc.addRequired(doc);
- console.log("Add " + doc.toQuery());
+ // console.log("Add " + doc.toQuery());
};
if (!vc.isOpen()) {
diff --git a/dev/js/src/match/meta.js b/dev/js/src/match/meta.js
index 78b1430..3cc7512 100644
--- a/dev/js/src/match/meta.js
+++ b/dev/js/src/match/meta.js
@@ -50,10 +50,8 @@
// Copy original array position to object
// before sorting by key title
let posInMetaArray = {};
- for (let i = 0; i < fields.length; i++) {
- posInMetaArray[fields[i]["key"]] = i;
+ fields.forEach((f,i) => posInMetaArray[f["key"]] = i);
- };
// TODO: Meta fields should be separated
// Sort all meta keys alphabetically
@@ -82,18 +80,17 @@
metaDD.setAttribute('data-type', field["type"]);
if(metaDescr instanceof Array){
- metaDD.classList.add("metakeyvalues");
- for (i = 0; i < metaDescr.length; i++){
-
+ metaDD.classList.add("metakeyvalues");
+ metaDescr.forEach(function(md) {
if (field["type"] === 'type:attachement') {
- let att = attClass.create(metaDescr[i]);
+ let att = attClass.create(md);
if (att)
metaDD.addE('div').appendChild(att.inline());
}
else {
- metaDD.addE('div').addT(metaDescr[i]);
+ metaDD.addE('div').addT(md);
}
- }
+ });
}
else{
if (field["type"] === 'type:attachement') {
diff --git a/dev/js/src/match/querycreator.js b/dev/js/src/match/querycreator.js
index fa4917b..f3c533f 100644
--- a/dev/js/src/match/querycreator.js
+++ b/dev/js/src/match/querycreator.js
@@ -229,9 +229,10 @@
// Is a key-value-cell
if (sib.classList.contains('matchkeyvalues')) {
- var divs = sib.getElementsByTagName('div');
- for (var j = 0; j < divs.length; j++) {
- var keyvaluepair = divs[j];
+
+ Array.from(
+ sib.getElementsByTagName('div')
+ ).forEach(function(keyvaluepair){
// Get annotation value from cell
var annotation = _getAnnotation(prefix, keyvaluepair);
@@ -242,7 +243,7 @@
this._addToToken(i, annotation);
keyvaluepair.classList.add('chosen');
};
- };
+ }, this);
}
// Normal cell
@@ -371,6 +372,8 @@
var str = '';
var distance = 0;
+ // This needs to take undefined tokens into account, therefore
+ // forEach() is not an option
for (var i = 0; i < this._query.length; i++) {
var token = this._query[i];
diff --git a/dev/js/src/match/table.js b/dev/js/src/match/table.js
index 9078780..92d4e5a 100644
--- a/dev/js/src/match/table.js
+++ b/dev/js/src/match/table.js
@@ -215,15 +215,17 @@
// There are multiple values to add
c.classList.add('matchkeyvalues');
- for (var n = 0; n < value.length; n++) {
- var e = c.addE('div');
- e.addT(value[n]);
- var anno = ah.getDesc(key, value[n]);
+ let e, anno;
+ value.forEach(function(v) {
+ e = c.addE('div');
+ e.addT(v);
+
+ anno = ah.getDesc(key, v);
if (anno)
e.setAttribute("title", anno);
- };
+ });
}
else {
@@ -272,29 +274,29 @@
var foundryList = Object.keys(this._foundry).sort();
- for (var f = 0; f < foundryList.length; f++) {
- var foundry = foundryList[f];
- var layerList =
+ let layerList, key, v, value, cell;
+
+ foundryList.forEach(function(foundry) {
+ let layerList =
Object.keys(this._foundry[foundry]).sort();
- for (var l = 0; l < layerList.length; l++) {
- var layer = layerList[l];
+ layerList.forEach(function(layer) {
+
tr = tbody.addE('tr');
tr.setAttribute('tabindex', 0);
tr.addCell = addCell;
-
tr.addCell('th', undefined, foundry);
tr.addCell('th', undefined, layer);
- var key = foundry + '/' + layer + '=';
+ key = foundry + '/' + layer + '=';
- for (var v = 0; v < this.length(); v++) {
+ for (v = 0; v < this.length(); v++) {
// Get the cell value
- var value = this.getValue(v, foundry, layer);
+ value = this.getValue(v, foundry, layer);
// Add cell to row
- var cell = tr.addCell(
+ cell = tr.addCell(
'td',
key,
value
@@ -304,8 +306,8 @@
cell.classList.add('mark');
};
};
- };
- };
+ }, this);
+ }, this);
// Add query creator
this._matchCreator = matchQueryCreator.create(this._element);
diff --git a/dev/js/src/match/treearc.js b/dev/js/src/match/treearc.js
index 2acda9b..e7d7ac3 100644
--- a/dev/js/src/match/treearc.js
+++ b/dev/js/src/match/treearc.js
@@ -99,7 +99,7 @@
_parse : function (parent, children, mark) {
// Iterate over all child nodes
- children.forEach(function(c) {
+ Array.from(children).forEach(function(c) {
// Element node
if (c.nodeType == 1) {
@@ -723,8 +723,7 @@
var stack = [];
// Iterate over all definitions
- for (var i = 0; i < list.length; i++) {
- var current = list[i];
+ list.forEach(function(current) {
// Check the stack order
var overlaps = 0;
@@ -766,7 +765,7 @@
stack.sort(function (a,b) {
b.overlaps - a.overlaps
});
- };
+ });
return stack;
};
diff --git a/dev/js/src/match/treehierarchy.js b/dev/js/src/match/treehierarchy.js
index 0a7bf49..9fc2480 100644
--- a/dev/js/src/match/treehierarchy.js
+++ b/dev/js/src/match/treehierarchy.js
@@ -287,14 +287,14 @@
if (v.class === "leaf") {
text.setAttribute('title', vLabel);
- var labelPart = vLabel.split(" ");
- var n = 0;
- for (var i = 0; i < labelPart.length; i++) {
- if (labelPart[i].length === 0)
- continue;
+ let n = 0;
+ let tspan;
+ vLabel.split(" ").forEach(function(p) {
+ if (p.length === 0)
+ return;
- var tspan = that._c('tspan');
- tspan.appendChild(d.createTextNode(labelPart[i]));
+ tspan = that._c('tspan');
+ tspan.appendChild(d.createTextNode(p));
if (n !== 0)
tspan.setAttribute('dy', LINEHEIGHT + 'pt');
else
@@ -302,7 +302,7 @@
tspan.setAttribute('x', v.x - v.width / 2);
y += LINEHEIGHT;
text.appendChild(tspan);
- };
+ });
y += LINEHEIGHT;