Modernize VC scripts
Change-Id: I260af56726ba75a56857a5af97c373432d69a910
diff --git a/dev/js/spec/vcSpec.js b/dev/js/spec/vcSpec.js
index ce8f48f..f30498e 100644
--- a/dev/js/spec/vcSpec.js
+++ b/dev/js/spec/vcSpec.js
@@ -105,7 +105,7 @@
]
});
- describe('KorAP.Doc', function () {
+ describe('KorAP.VC.Doc', function () {
// Create example factories
var stringFactory = buildFactory(docClass, {
"key" : "author",
@@ -385,7 +385,7 @@
});
- describe('KorAP.DocGroup', function () {
+ describe('KorAP.VC.DocGroup', function () {
// Create example factories
var docFactory = buildFactory(
docClass,
@@ -595,7 +595,7 @@
});
});
- describe('KorAP.DocGroupRef', function () {
+ describe('KorAP.VC.DocGroupRef', function () {
// Create example factories
var docRefFactory = buildFactory(
docGroupRefClass,
@@ -657,7 +657,7 @@
});
- describe('KorAP.UnspecifiedDoc', function () {
+ describe('KorAP.VC.UnspecifiedDoc', function () {
it('should be initializable', function () {
var doc = unspecifiedClass.create();
var docElement = doc.element();
@@ -803,7 +803,7 @@
});
});
- describe('KorAP.Doc element', function () {
+ describe('KorAP.VC.Doc element', function () {
it('should be initializable', function () {
var docElement = docClass.create(undefined, {
"@type" : "koral:doc",
@@ -973,7 +973,7 @@
});
});
- describe('KorAP.DocGroup element', function () {
+ describe('KorAP.VC.DocGroup element', function () {
it('should be initializable', function () {
var docGroup = docGroupClass.create(undefined, {
@@ -1087,7 +1087,7 @@
});
});
- describe('KorAP.DocGroupRef element', function () {
+ describe('KorAP.VC.DocGroupRef element', function () {
it('should be initializable', function () {
var docGroupRef = docGroupRefClass.create(undefined, {
"@type" : "koral:docGroupRef",
@@ -1130,7 +1130,7 @@
});
- describe('KorAP.VirtualCorpus', function () {
+ describe('KorAP.VC.VirtualCorpus', function () {
var simpleGroupFactory = buildFactory(docGroupClass, {
"@type" : "koral:docGroup",
"operation" : "operation:and",
@@ -1908,7 +1908,7 @@
});
- describe('KorAP.Operators', function () {
+ describe('KorAP.VC.Operators', function () {
it('should be initializable', function () {
var op = operatorsClass.create(true, false, false);
expect(op.and()).toBeTruthy();
@@ -1945,7 +1945,7 @@
});
});
- describe('KorAP._delete (event)', function () {
+ describe('KorAP.VC._delete (event)', function () {
var complexVCFactory = buildFactory(vcClass,{
"@type": 'koral:docGroup',
'operation' : 'operation:and',
@@ -2179,7 +2179,7 @@
});
});
- describe('KorAP._add (event)', function () {
+ describe('KorAP.VC._add (event)', function () {
var complexVCFactory = buildFactory(vcClass,{
"@type": 'koral:docGroup',
'operation' : 'operation:and',
@@ -2630,7 +2630,7 @@
});
- describe('KorAP.Rewrite', function () {
+ describe('KorAP.VC.Rewrite', function () {
it('should be initializable', function () {
var rewrite = rewriteClass.create({
"@type" : "koral:rewrite",
@@ -2741,7 +2741,7 @@
});
});
- describe('KorAP.stringValue', function () {
+ describe('KorAP.VC.stringValue', function () {
it('should be initializable', function () {
var sv = stringValClass.create();
expect(sv.regex()).toBe(false);
diff --git a/dev/js/src/vc.js b/dev/js/src/vc.js
index 764ed96..7bf0d34 100644
--- a/dev/js/src/vc.js
+++ b/dev/js/src/vc.js
@@ -43,6 +43,7 @@
and various field names with the prefix 'VC_'
*/
+"use strict";
define([
'vc/unspecified',
@@ -69,7 +70,6 @@
vcPanelClass,
corpStatVClass,
buttonGroupClass) {
- "use strict";
KorAP._validUnspecMatchRE = new RegExp(
"^(?:eq|ne|contains(?:not)?|excludes)$");
@@ -114,6 +114,7 @@
])
};
+
/**
* Virtual corpus
*/
@@ -126,12 +127,14 @@
return null;
},
+
// Initialize virtual corpus
_init : function(keyList) {
// Inject localized css styles
if (!KorAP._overrideStyles) {
- var sheet = KorAP.newStyleSheet();
+
+ const sheet = KorAP.newStyleSheet();
// Add css rule for OR operations
sheet.insertRule('.vc .docGroup[data-operation=or] > .doc::before,'
@@ -147,7 +150,7 @@
KorAP._overrideStyles = true;
};
- var l;
+ let l;
if (keyList) {
l = keyList.slice();
l.unshift(['referTo', 'ref']);
@@ -163,11 +166,12 @@
return this;
},
+
/**
* Create a new virtual corpus
*/
- create : function(keyList) {
- var obj = Object.create(this)._init(keyList);
+ create : function (keyList) {
+ const obj = Object.create(this)._init(keyList);
obj._root = unspecDocClass.create(obj);
return obj;
},
@@ -182,10 +186,12 @@
let obj;
if (json !== undefined) {
+
// Parse root document
if (json['@type'] == 'koral:doc') {
obj = docClass.create(this, json);
}
+
// parse root group
else if (json['@type'] == 'koral:docGroup') {
obj = docGroupClass.create(this, json);
@@ -218,11 +224,7 @@
// Check if the virtual corpus contains a rerite
wasRewritten : function (obj) {
- var obj;
- if (arguments.length === 1) {
- obj = arguments[0];
- }
- else {
+ if (arguments.length !== 1) {
obj = this._root;
};
@@ -239,7 +241,7 @@
return true;
};
};
-
+
return false;
},
@@ -248,22 +250,25 @@
* Clean the virtual document to unspecified doc.
*/
clean : function() {
- if (this._root.ldType() !== "non") {
- this._root.destroy();
- this.root(unspecDocClass.create(this));
+ const t = this;
+ if (t._root.ldType() !== "non") {
+ t._root.destroy();
+ t.root(unspecDocClass.create(t));
};
- //update for graying corpus statistic by deleting the first line of the vc builder
- this.update();
- return this;
+
+ // update for graying corpus statistic by deleting the first line of the vc builder
+ t.update();
+ return t;
},
+
/**
* Get or set the root object of the virtual corpus
*/
root : function(obj) {
if (arguments.length === 1) {
- var e = this.builder();
-
+ const e = this.builder();
+
if (e.firstChild !== null) {
// Object not yet set
@@ -283,6 +288,7 @@
this.update();
};
+
return this._root;
},
@@ -291,53 +297,57 @@
* Get the wrapper element associated with the vc
*/
builder : function () {
+ const t = this;
// Initialize if necessary
- if (this._builder !== undefined)
- return this._builder;
+ if (t._builder !== undefined)
+ return t._builder;
- this.element();
- return this._builder;
+ t.element();
+ return t._builder;
},
+
/**
* Get the element associated with the virtual corpus
*/
element : function() {
- if (this._element !== undefined) {
- return this._element;
- };
+ const t = this;
+ let e = t._element;
- this._element = document.createElement('div');
- this._element.classList.add('vc');
+ if (e !== undefined)
+ return e;
- this._builder = this._element.addE('div');
- this._builder.setAttribute('class', 'builder');
+ e = t._element = document.createElement('div');
+ e.classList.add('vc');
- var btn = buttonGroupClass.create(
+
+ t._builder = e.addE('div');
+ t._builder.setAttribute('class', 'builder');
+
+ const btn = buttonGroupClass.create(
['action','button-view']
);
- var that = this;
- btn.add(loc.MINIMIZE, {'cls':['button-icon','minimize']}, function () {
- that.minimize();
- });
- this._element.appendChild(btn.element());
-
-
+ btn.add(loc.MINIMIZE, {'cls':['button-icon','minimize']}, function () {
+ this.minimize();
+ }.bind(t));
+
+ e.appendChild(btn.element());
+
// Initialize root
- this._builder.appendChild(this._root.element());
+ t._builder.appendChild(t._root.element());
// Add panel to display corpus statistic, ...
- this.addVcInfPanel();
+ t.addVcInfPanel();
//Adds EventListener for corpus changes
- this._element.addEventListener('vcChange', function (e) {
- that.checkStatActive(e.detail);
- }, false);
+ t._element.addEventListener('vcChange', function (e) {
+ this.checkStatActive(e.detail);
+ }.bind(t), false);
- return this._element;
+ return e;
},
@@ -350,6 +360,7 @@
return this._element.classList.contains('active');
},
+
/**
* Open the VC view
*/
@@ -375,17 +386,21 @@
*/
update : function() {
this._root.update();
- if (KorAP.vc){
- var vcchevent = new CustomEvent('vcChange', {'detail':this});
- this.element().dispatchEvent(vcchevent);
+ if (KorAP.vc) {
+ this.element().dispatchEvent(
+ new CustomEvent('vcChange', {'detail':this})
+ );
};
return this;
},
+
+
/**
* Make the vc persistant by injecting the current timestamp as a
* creation date limit criterion.
* THIS IS CURRENTLY NOT USED
*/
+ /*
makePersistant : function() {
// this.root().wrapOnRoot('and');
var todayStr = KorAP._vcDatePicker.today();
@@ -404,13 +419,12 @@
doc.matchop("leq");
doc.value(todayStr);
- /*
- * { "@type" : "koral:doc", "key" : "creationDate", "type" :
- * "type:date", "match" : "match:leq", "value" : todayStr }
- * this.root().append(cond);
- */
+ // { "@type" : "koral:doc", "key" : "creationDate", "type" :
+ // "type:date", "match" : "match:leq", "value" : todayStr }
+ // this.root().append(cond);
this.update();
},
+ */
// Get the reference name
@@ -426,13 +440,13 @@
}
},
+
// Add "and" constraint to VC
addRequired : function (doc) {
+ const root = this.root();
+ const ldType = root.ldType();
+ const parent = root.parent();
- let root = this.root();
- let ldType = root.ldType();
-
- let parent = root.parent();
if (ldType === 'non') {
parent.root(doc);
}
@@ -444,7 +458,7 @@
(ldType === 'docGroup' &&
root.operation() === 'or'
)) {
- let group = require('vc/docgroup').create(
+ const group = require('vc/docgroup').create(
parent
);
group.operation("and");
@@ -469,17 +483,19 @@
this.update();
},
+
/**
* Get the generated json string
*/
- toJson : function() {
+ toJson : function () {
return this._root.toJson();
},
+
/**
* Get the generated query string
*/
- toQuery : function() {
+ toQuery : function () {
return this._root.toQuery();
},
@@ -487,11 +503,10 @@
/**
* Add panel to display virtual corpus information
*/
- addVcInfPanel : function() {
- var dv = this._element.addE('div');
- //Create panel
+ addVcInfPanel : function () {
+ // Create panel
this.panel = vcPanelClass.create(this);
- dv.appendChild(this.panel.element());
+ this._element.addE('div').appendChild(this.panel.element());
},
@@ -499,10 +514,10 @@
* Checks if corpus statistic has to be disabled,
* and to be updated after clicking at the "reload-button"
*/
- checkStatActive : function(){
- if(this.panel !== undefined && this.panel.statView !==undefined){
+ checkStatActive : function (){
+ if (this.panel !== undefined && this.panel.statView !== undefined){
this.panel.statView.checkStatActive();
- }
+ };
}
};
});
diff --git a/dev/js/src/vc/chooseitem.js b/dev/js/src/vc/chooseitem.js
index 9f6fc06..039764c 100644
--- a/dev/js/src/vc/chooseitem.js
+++ b/dev/js/src/vc/chooseitem.js
@@ -1,6 +1,8 @@
+"use strict";
+
define(['menu/item', 'util'], function (itemClass) {
- var loc = KorAP.Locale;
+ const loc = KorAP.Locale;
return {
@@ -17,21 +19,25 @@
._init(params);
},
+
// Initialize item object
_init : function (params) {
+ const t = this;
+
if (params[0] === undefined)
throw new Error("Missing parameters");
- this._id = params[0];
- this._name = params[1];
- this._desc = params[2];
+ t._id = params[0];
+ t._name = params[1];
+ t._desc = params[2];
- this._lcField = ' ' + this._name.toLowerCase();
- this._lcField += ' ' + this._desc.toLowerCase();
+ t._lcField = ' ' + t._name.toLowerCase();
+ t._lcField += ' ' + t._desc.toLowerCase();
return this;
},
+
/**
* Override click event by passing all clicks
* to the menu object.
@@ -44,6 +50,7 @@
e.halt();
},
+
/**
* Get the name of the item.
*/
@@ -51,6 +58,7 @@
return this._name;
},
+
/**
* Get the identifier of the item.
*/
@@ -58,6 +66,7 @@
return this._id;
},
+
/**
* Get the description of the item.
*/
@@ -65,25 +74,27 @@
return this._desc;
},
+
/**
* Get the HTML element associated with the item.
*/
element : function () {
+ const t = this;
// already defined
- if (this._element !== undefined)
- return this._element;
+ if (t._element !== undefined)
+ return t._element;
// Create list item
- var li = document.createElement("li");
- li.setAttribute("data-type", this._type);
- li.setAttribute("data-key", this._key);
+ const li = document.createElement("li");
+ li.setAttribute("data-type", t._type);
+ li.setAttribute("data-key", t._key);
// Connect action
- li["onclick"] = this.onclick.bind(this);
+ li["onclick"] = t.onclick.bind(t);
- li.addT(this._name);
- return this._element = li;
+ li.addT(t._name);
+ return t._element = li;
}
}
});
diff --git a/dev/js/src/vc/choosemenu.js b/dev/js/src/vc/choosemenu.js
index 90660b7..84adf00 100644
--- a/dev/js/src/vc/choosemenu.js
+++ b/dev/js/src/vc/choosemenu.js
@@ -2,6 +2,8 @@
* Menu showing all predefined virtual corpora.
* THIS IS EXPERIMENTAL AND MAY BE REMOVED!
*/
+"use strict";
+
define(['vc/menu', 'api'], function (menuClass, itemClass) {
return {
create : function (params) {
diff --git a/dev/js/src/vc/doc.js b/dev/js/src/vc/doc.js
index 8ea8364..fd4c318 100644
--- a/dev/js/src/vc/doc.js
+++ b/dev/js/src/vc/doc.js
@@ -1,6 +1,7 @@
/**
* A new document criterion
*/
+"use strict";
define([
'vc/jsonld',
@@ -29,6 +30,7 @@
// The object ... maybe not important
_obj : function () { return '???'; /*KorAP.Doc*/ },
+
/**
* Create a new document criterion
* by passing the parent object and a json construct.
@@ -36,10 +38,10 @@
create : function (parent, json) {
// Create the object, inheriting from Json-LD class
- var obj = Object(jsonldClass).
- create().
- upgradeTo(this).
- fromJson(json);
+ const obj = Object(jsonldClass).
+ create().
+ upgradeTo(this).
+ fromJson(json);
if (obj === undefined) {
console.log(json);
@@ -54,104 +56,106 @@
return obj;
},
+
/**
* Update the elements content.
*/
update : function () {
- if (this._element === undefined)
- return this.element();
+ const t = this;
+
+ if (t._element === undefined)
+ return t.element();
// Get element
- var e = this._element;
+ const e = t._element;
// Check if there is a change in the underlying data
- if (!this.__changed)
+ if (!t.__changed)
return e;
// Set ref - TODO: Cleanup!
- e.refTo = this;
+ e.refTo = t;
// Was rewritten
- if (this.rewrites() !== undefined) {
+ if (t.rewrites() !== undefined) {
e.classList.add("rewritten");
};
// Added key
- this._keyE = document.createElement('span');
- this._keyE.setAttribute('class', 'key');
+ const keyE = t._keyE = document.createElement('span');
+ keyE.setAttribute('class', 'key');
// Change key
- this._keyE.addEventListener('click', this._changeKey.bind(this));
+ keyE.addEventListener('click', t._changeKey.bind(t));
- if (this.key()) {
- var k = this.key();
+ if (t.key()) {
+ const k = t.key();
if (loc['VC_' + k] !== undefined)
k = loc['VC_' + k];
- this._keyE.addT(k);
+ keyE.addT(k);
};
// Added match operator
- this._matchopE = document.createElement('span');
- this._matchopE.setAttribute('data-type', this.type());
- this._matchopE.setAttribute('class', 'match');
- this._matchopE.addT(this.matchop());
+ const matchopE = t._matchopE = document.createElement('span');
+ matchopE.setAttribute('data-type', t.type());
+ matchopE.setAttribute('class', 'match');
+ matchopE.addT(t.matchop());
// Change matchop
- this._matchopE.addEventListener(
+ t._matchopE.addEventListener(
'click',
- this._changeMatchop.bind(this)
+ t._changeMatchop.bind(t)
);
// Added value operator
- this._valueE = document.createElement('span');
- this._valueE.setAttribute('data-type', this.type());
- this._valueE.setAttribute('class', 'value');
+ const valueE = t._valueE = document.createElement('span');
+ valueE.setAttribute('data-type', t.type());
+ valueE.setAttribute('class', 'value');
- if (this.value()) {
- this._valueE.addT(this.value());
+ if (t.value()) {
+ valueE.addT(t.value());
}
else {
- this._valueE.addT(loc.EMPTY);
- this._valueE.classList.add('unspecified');
+ valueE.addT(loc.EMPTY);
+ valueE.classList.add('unspecified');
};
// Change value
- this._valueE.addEventListener(
+ valueE.addEventListener(
'click',
- this._changeValue.bind(this)
+ t._changeValue.bind(t)
);
// Remove all element children
_removeChildren(e);
// Add spans
- e.appendChild(this._keyE);
- e.appendChild(this._matchopE);
- e.appendChild(this._valueE);
+ e.appendChild(keyE);
+ e.appendChild(matchopE);
+ e.appendChild(valueE);
- this.__changed = false;
+ t.__changed = false;
- if (this._rewrites !== undefined) {
- e.appendChild(this._rewrites.element());
+ if (t._rewrites !== undefined) {
+ e.appendChild(t._rewrites.element());
};
- if (this._parent !== undefined) {
+ if (t._parent !== undefined) {
// Set operators
- var op = this.operators(
+ // Append new operators
+ e.appendChild(t.operators(
true,
true,
true
- );
-
- // Append new operators
- e.appendChild(op.element());
+ ).element());
};
- if(KorAP.vc){
- var vcchevent = new CustomEvent('vcChange', {'detail':this});
- KorAP.vc.element().dispatchEvent(vcchevent);
+ if (KorAP.vc){
+ KorAP.vc.element().dispatchEvent(
+ new CustomEvent('vcChange', {'detail' : t})
+ );
}
return e;
@@ -162,48 +166,53 @@
* Get the associated element
*/
element : function () {
- if (this._element !== undefined)
- return this._element;
+ const t = this;
+ if (t._element !== undefined)
+ return t._element;
- this._element = document.createElement('div');
- this._element.setAttribute('class', 'doc');
-
- this.update();
- return this._element;
+ t._element = document.createElement('div');
+ t._element.setAttribute('class', 'doc');
+ t.update();
+ return t._element;
},
+
/**
* Wrap a new operation around the doc element
*/
wrap : function (op) {
- var parent = this.parent();
- var group = require('vc/docgroup').create(parent);
+ const parent = this.parent();
+ const group = require('vc/docgroup').create(parent);
group.operation(op);
group.append(this);
group.append();
return parent.replaceOperand(this, group).update();
},
+
replaceWith : function (op) {
- var p = this.parent();
+ const p = this.parent();
if (p.ldType() === 'docGroup') {
- p.replaceOperand(this,op);
+ p.replaceOperand(this, op);
}
else if (p.ldType() == null) {
p.root(op);
};
+
p.update();
this.destroy();
},
+
/**
* Deserialize from json
*/
fromJson : function (json) {
+ const t = this;
if (json === undefined)
- return this;
+ return t;
if (json["@type"] === undefined) {
KorAP.log(701, "JSON-LD group has no @type attribute");
@@ -216,20 +225,19 @@
return;
};
- var rewrite;
+ let rewrite;
// There is a defined key
if (json["key"] !== undefined &&
typeof json["key"] === 'string') {
// Set key
- this.key(json["key"]);
+ t.key(json["key"]);
// Set match operation
if (json["match"] !== undefined) {
if (typeof json["match"] === 'string') {
-
- this.matchop(json["match"]);
+ t.matchop(json["match"]);
}
else {
KorAP.log(802, errstr802);
@@ -241,7 +249,7 @@
if (json["type"] === undefined && KorAP._vcKeyMenu) {
// Check the VC list if the field is known
- var type = KorAP._vcKeyMenu.typeOf(this.key());
+ const type = KorAP._vcKeyMenu.typeOf(t.key());
if (type != undefined) {
json["type"] = "type:" + type;
};
@@ -251,69 +259,69 @@
if (json["type"] === undefined) {
// Check match type
- if (!KorAP._validUnspecMatchRE.test(this.matchop())) {
+ if (!KorAP._validUnspecMatchRE.test(t.matchop())) {
KorAP.log(802, errstr802);
// Rewrite method
- this.matchop('eq');
+ t.matchop('eq');
rewrite = 'modification';
};
// Set string value
- this.value(json["value"]);
+ t.value(json["value"]);
}
// Field is string type
else if (json["type"] == "type:string") {
- this.type("string");
+ t.type("string");
// Check match type
- if (!KorAP._validStringMatchRE.test(this.matchop())) {
+ if (!KorAP._validStringMatchRE.test(t.matchop())) {
KorAP.log(802, errstr802);
// Rewrite method
- this.matchop('eq');
+ t.matchop('eq');
rewrite = 'modification';
};
-
+
// Set string value
- this.value(json["value"]);
+ t.value(json["value"]);
}
// Field is specified
else if (json["type"] == "type:text") {
- this.type("text");
+ t.type("text");
// Check match type
- if (!KorAP._validTextMatchRE.test(this.matchop())) {
+ if (!KorAP._validTextMatchRE.test(t.matchop())) {
KorAP.log(802, errstr802);
// Rewrite method
- this.matchop('eq');
+ t.matchop('eq');
rewrite = 'modification';
};
// Set string value
- this.value(json["value"]);
+ t.value(json["value"]);
}
// Key is a date
else if (json["type"] === "type:date") {
- this.type("date");
+ t.type("date");
if (json["value"] !== undefined &&
KorAP._validDateRE.test(json["value"])) {
- if (!KorAP._validDateMatchRE.test(this.matchop())) {
+ if (!KorAP._validDateMatchRE.test(t.matchop())) {
KorAP.log(802, errstr802);
// Rewrite method
- this.matchop('eq');
+ t.matchop('eq');
rewrite = 'modification';
};
// Set value
- this.value(json["value"]);
+ t.value(json["value"]);
}
else {
KorAP.log(806, "Value is not a valid date string");
@@ -323,50 +331,51 @@
// Key is a regular expression
else if (json["type"] === "type:regex") {
- this.type("regex");
+ t.type("regex");
try {
// Try to create a regular expression
- var check = new RegExp(json["value"]);
+ let check = new RegExp(json["value"]);
- if (!KorAP._validStringMatchRE.test(this.matchop())) {
+ if (!KorAP._validStringMatchRE.test(t.matchop())) {
KorAP.log(802, errstr802);
// Rewrite method
- this.matchop('eq');
+ t.matchop('eq');
rewrite = 'modification';
};
- this.value(json["value"]);
+ t.value(json["value"]);
}
catch (e) {
KorAP.log(807, "Value is not a valid regular expression");
return;
};
- this.type("regex");
+ t.type("regex");
}
else {
- KorAP.log(804, errstr804 + ": " + this.type());
- throw new Error(errstr804 + ": " + this.type());
+ KorAP.log(804, errstr804 + ": " + t.type());
+ throw new Error(errstr804 + ": " + t.type());
};
};
// Rewrite coming from the server
if (json["rewrites"] !== undefined) {
- this.rewrite(json["rewrites"]);
+ t.rewrite(json["rewrites"]);
}
// Rewrite coming from Kalamar
else if (rewrite !== undefined) {
- this.rewrite(rewrite);
+ t.rewrite(rewrite);
};
- return this;
+ return t;
},
+
/**
* Get or set the key
*/
@@ -379,9 +388,10 @@
return this._key;
},
+
// Click on the key, show me the menu
_changeKey : function (e) {
- var menu = KorAP._vcKeyMenu;
+ const menu = KorAP._vcKeyMenu;
// Insert menu
this._element.insertBefore(
@@ -390,16 +400,18 @@
);
// Release event
- var that = this;
+ const that = this;
menu.released(function (key, type) {
if (type === 'ref') {
// KorAP._delete.bind(that);
- var ref = docGroupRefClass.create(that.parent());
- that.replaceWith(ref);
+ that.replaceWith(
+ docGroupRefClass.create(that.parent())
+ );
}
+
else {
- var doc = that.key(key).type(type);
+ const doc = that.key(key).type(type);
// This may not be compatible - then switch to default
doc.matchop(doc.matchop());
@@ -418,42 +430,45 @@
menu.focus();
},
+
/**
* Get or set the match operator
*/
matchop : function (match) {
+ const t = this;
if (arguments.length === 1) {
- var m = match.replace(/^match:/, '');
+ const m = match.replace(/^match:/, '');
if (
- (this._type == undefined) // && KorAP._validUnspecMatchRE.test(m))
+ (t._type == undefined) // && KorAP._validUnspecMatchRE.test(m))
||
(
- (this._type === 'string' || this._type === 'regex') &&
+ (t._type === 'string' || t._type === 'regex') &&
KorAP._validStringMatchRE.test(m)
)
||
- (this._type === 'text' && KorAP._validTextMatchRE.test(m))
+ (t._type === 'text' && KorAP._validTextMatchRE.test(m))
||
- (this._type === 'date' && KorAP._validDateMatchRE.test(m))
+ (t._type === 'date' && KorAP._validDateMatchRE.test(m))
) {
- this._matchop = m;
+ t._matchop = m;
}
else {
- this._matchop = "eq";
+ t._matchop = "eq";
};
- this._changed();
- return this
+ t._changed();
+ return t;
};
- return this._matchop || "eq";
+
+ return t._matchop || "eq";
},
// Click on the match operator, show me the menu
_changeMatchop : function (e) {
- var menu = KorAP._vcMatchopMenu[this.type()];
+ const menu = KorAP._vcMatchopMenu[this.type()];
if (menu === undefined) {
KorAP.log(0, "Unable to init menu for " + this.type());
@@ -467,7 +482,7 @@
);
// Release event
- var that = this;
+ const that = this;
menu.released(function (mo) {
that.matchop(mo).update();
this.hide();
@@ -495,29 +510,29 @@
* Get or set the value
*/
value : function (value) {
+ const t = this;
if (arguments.length === 1) {
- if (this._type === 'date' && !KorAP._validDateRE.test(value)) {
- delete this._value;
+ if (t._type === 'date' && !KorAP._validDateRE.test(value)) {
+ delete t._value;
}
else {
- this._value = value;
+ t._value = value;
};
- this._changed();
- return this;
+ t._changed();
+ return t;
};
- return this._value;
+ return t._value;
},
// Click on the match operator, show me the menu
_changeValue : function (e) {
- var v = this.value();
- var that = this;
+ const that = this;
// Show datepicker
if (this.type() === 'date') {
- var dp = KorAP._vcDatePicker;
- dp.fromString(v);
+ const dp = KorAP._vcDatePicker;
+ dp.fromString(this.value());
// Todo: change this
dp.onclick(function (selected) {
@@ -535,20 +550,18 @@
);
});
- // Get element of the date picker
- var dpElem = dp.show();
-
this._element.insertBefore(
- dpElem,
+ dp.show(), // Get element of the date picker
this._valueE
);
dp.input().focus();
}
+
else {
- var regex = this.type() === 'regex' ? true : false;
- var str = stringValClass.create(this.value(), regex);
- var strElem = str.element();
+ const regex = this.type() === 'regex' ? true : false;
+ const str = stringValClass.create(this.value(), regex);
+ const strElem = str.element();
str.store = function (value, regex) {
that.value(value);
@@ -578,6 +591,7 @@
return this._rewrites;
},
+
rewrite : function (value) {
if (typeof value === 'string') {
value = [{
@@ -589,6 +603,7 @@
this._rewrites = rewriteListClass.create(value);
},
+
// Mark the underlying data as being changed.
// This is important for rerendering the dom.
// This will also remove rewrite markers, when the data
@@ -599,8 +614,8 @@
if (this._rewrites === undefined)
return;
- delete this["_rewrites"];
-
+ delete this["_rewrites"];
+
if (this._element === undefined)
return;
@@ -609,28 +624,32 @@
toJson : function () {
- if (!this.matchop() || !this.key())
+ const t = this;
+
+ if (!t.matchop() || !t.key())
return {};
return {
- "@type" : "koral:" + this.ldType(),
- "key" : this.key(),
- "match" : "match:" + this.matchop(),
- "value" : this.value() || '',
- "type" : "type:" + this.type()
+ "@type" : "koral:" + t.ldType(),
+ "key" : t.key(),
+ "match" : "match:" + t.matchop(),
+ "value" : t.value() || '',
+ "type" : "type:" + t.type()
};
},
+
incomplete : function () {
return !(this.matchop() && this.key() && this.value());
},
+
toQuery : function () {
if (this.incomplete())
return "";
// Build doc string based on key
- var string = this.key() + ' ';
+ let string = this.key() + ' ';
// Add match operator
switch (this.matchop()) {
diff --git a/dev/js/src/vc/docgroup.js b/dev/js/src/vc/docgroup.js
index 47f3a96..1dbd5d7 100644
--- a/dev/js/src/vc/docgroup.js
+++ b/dev/js/src/vc/docgroup.js
@@ -4,6 +4,8 @@
/*
* TODO: Let the UPDATE event bubble up through parents!
*/
+"use strict";
+
define([
'vc/jsonld',
'vc/unspecified',
@@ -18,10 +20,11 @@
const _validGroupOpRE = new RegExp("^(?:and|or)$");
const docGroupClass = {
+
_ldType : "docGroup",
create : function (parent, json) {
- var obj = Object.create(jsonldClass).upgradeTo(this);
+ const obj = Object.create(jsonldClass).upgradeTo(this);
obj._operands = [];
obj.fromJson(json);
if (parent !== undefined)
@@ -29,22 +32,23 @@
return obj;
},
+
newAfter : function (obj) {
this._operands.forEach(function (op, i) {
if (op === obj) {
- var operand = unspecClass.create(this);
+ const operand = unspecClass.create(this);
this._operands.splice(i + 1, 0, operand);
return this.update();
};
}, this);
},
+
// The doc is already set in the group
_duplicate : function (operand) {
// TODO:
// Also check for duplicate docGroupRefs!
-
if (operand.ldType() !== 'doc')
return null;
@@ -62,6 +66,7 @@
return null;
},
+
append : function (operand) {
// Append unspecified object
@@ -88,7 +93,7 @@
// Be aware of cyclic structures!
operand.parent(this);
- var dupl = this._duplicate(operand);
+ const dupl = this._duplicate(operand);
if (dupl === null) {
this._operands.push(operand);
return operand;
@@ -101,10 +106,11 @@
case "koral:doc":
// Be aware of cyclic structures!
- var doc = docClass.create(this, operand);
+ const doc = docClass.create(this, operand);
if (doc === undefined)
return;
- var dupl = this._duplicate(doc);
+
+ const dupl = this._duplicate(doc);
if (dupl === null) {
this._operands.push(doc);
return doc;
@@ -112,15 +118,16 @@
return dupl;
case "koral:docGroup":
- // Be aware of cyclic structures!
- var docGroup = docGroupClass.create(this, operand);
+
+ // Be aware of cyclic structures!
+ const docGroup = docGroupClass.create(this, operand);
if (docGroup === undefined)
return;
// Flatten group
if (docGroup.operation() === this.operation()) {
docGroup.operands().forEach(function(op) {
- var dupl = this._duplicate(op);
+ const dupl = this._duplicate(op);
if (dupl === null) {
this._operands.push(op);
op.parent(this);
@@ -135,11 +142,10 @@
case "koral:docGroupRef":
- var docGroupRef = docGroupRefClass.create(this, operand);
+ const docGroupRef = docGroupRefClass.create(this, operand);
- if (docGroupRef === undefined) {
+ if (docGroupRef === undefined)
return
- };
// TODO:
// Currently this doesn't do anything meaningful,
@@ -161,25 +167,28 @@
};
},
+
update : function () {
+ const t = this;
+
// There is only one operand in group
- if (this._operands.length === 1) {
+ if (t._operands.length === 1) {
- var parent = this.parent();
- var op = this.getOperand(0);
+ const parent = t.parent();
+ const op = t.getOperand(0);
// This will prevent destruction of
// the operand
- this._operands = [];
+ t._operands = [];
// Parent is a group
if (parent.ldType() !== null)
- return parent.replaceOperand(this, op).update();
+ return parent.replaceOperand(t, op).update();
// Parent is vc
else {
- this.destroy();
+ t.destroy();
// Cyclic madness
parent.root(op);
op.parent(parent);
@@ -187,49 +196,54 @@
};
};
- if (this._element === undefined)
- return this;
+ if (t._element === undefined)
+ return t;
- var group = this._element;
- group.setAttribute('data-operation', this.operation());
+ const group = t._element;
+ group.setAttribute('data-operation', t.operation());
_removeChildren(group);
// Append operands
- this._operands.forEach(
+ t._operands.forEach(
op => group.appendChild(op.element())
);
// Set operators
- var op = this.operators(
- this.operation() == 'and' ? false : true,
- this.operation() == 'or' ? false : true,
+ var op = t.operators(
+ t.operation() == 'and' ? false : true,
+ t.operation() == 'or' ? false : true,
true
);
group.appendChild(op.element());
if (KorAP.vc) {
- var vcchevent = new CustomEvent('vcChange', {'detail':this});
- KorAP.vc.element().dispatchEvent(vcchevent);
+ KorAP.vc.element().dispatchEvent(
+ new CustomEvent('vcChange', {'detail' : t})
+ );
};
- return this;
+ return t;
},
+
element : function () {
- if (this._element !== undefined)
- return this._element;
+ const t = this;
- this._element = document.createElement('div');
- this._element.setAttribute('class', 'docGroup');
+ if (t._element !== undefined)
+ return t._element;
+
+ const e = t._element = document.createElement('div');
+ e.setAttribute('class', 'docGroup');
// Update the object - including optimization
- this.update();
+ t.update();
- return this._element;
+ return e;
},
+
operation : function (op) {
if (arguments.length === 1) {
if (_validGroupOpRE.test(op)) {
@@ -243,18 +257,22 @@
return this._op || 'and';
},
+
operands : function () {
return this._operands;
},
+
getOperand : function (index) {
return this._operands[index];
},
+
// Replace operand
replaceOperand : function (oldOp, newOp) {
- for (var i = 0; i < this._operands.length; i++) {
+ for (let i = 0; i < this._operands.length; i++) {
+
if (this._operands[i] === oldOp) {
// Just insert a doc or ...
@@ -270,18 +288,24 @@
// Flatten group
else {
- // Remove old group
+
+ // Remove old group
this._operands.splice(i, 1);
// Inject new operands
- newOp.operands().reverse().forEach(function(op) {
- this._operands.splice(i, 0, op);
- op.parent(this);
- }, this);
+ newOp.operands().reverse().forEach(
+ function(op) {
+ this._operands.splice(i, 0, op);
+ op.parent(this);
+ },
+ this
+ );
+
// Prevent destruction of operands
newOp._operands = [];
newOp.destroy();
};
+
oldOp.destroy();
return this;
}
@@ -289,9 +313,11 @@
return false;
},
+
// Delete operand from group
delOperand : function (obj) {
- for (var i = 0; i < this._operands.length; i++) {
+
+ for (let i = 0; i < this._operands.length; i++) {
if (this._operands[i] === obj) {
// Delete identified operand
@@ -308,8 +334,10 @@
return undefined;
},
+
// Deserialize from json
fromJson : function (json) {
+
if (json === undefined)
return this;
@@ -324,7 +352,7 @@
return;
};
- var operation = json["operation"];
+ const operation = json["operation"];
this.operation(operation.replace(/^operation:/,''));
@@ -340,12 +368,14 @@
return this;
},
+
toJson : function () {
- var opArray = new Array();
+ const opArray = new Array();
this._operands.forEach(function(op) {
if (op.ldType() !== 'non')
opArray.push(op.toJson());
});
+
return {
"@type" : "koral:" + this.ldType(),
"operation" : "operation:" + this.operation(),
@@ -353,6 +383,7 @@
};
},
+
toQuery : function (brackets) {
var list = this._operands
.filter(function (op) {
@@ -367,10 +398,11 @@
if (list.length === 1)
return list.join('');
else {
- var str = list.join(this.operation() === 'or' ? ' | ' : ' & ');
+ const str = list.join(this.operation() === 'or' ? ' | ' : ' & ');
return brackets ? '(' + str + ')' : str;
};
}
};
+
return docGroupClass;
});
diff --git a/dev/js/src/vc/docgroupref.js b/dev/js/src/vc/docgroupref.js
index e72385a..83ac244 100644
--- a/dev/js/src/vc/docgroupref.js
+++ b/dev/js/src/vc/docgroupref.js
@@ -25,18 +25,17 @@
* with a link to the parent object
*/
create : function (parent, json) {
- var obj = Object(jsonldClass)
- .create().
- upgradeTo(this)
- .fromJson(json);
-
- if (obj === undefined) {
+ const obj = Object(jsonldClass).
+ create().
+ upgradeTo(this).
+ fromJson(json);
+
+ if (obj === undefined)
console.log(json);
- };
if (parent !== undefined)
obj._parent = parent;
-
+
obj.__changed = true;
return obj;
},
@@ -46,43 +45,46 @@
* Update the element
*/
update : function () {
- if (this._element === undefined)
- return this.element();
+ const t = this;
- var e = this._element;
+ if (t._element === undefined)
+ return t.element();
+
+ const e = t._element;
// Check if there is a change in the underlying data
- if (!this.__changed)
+ if (!t.__changed)
return e;
// Set ref - TODO: Cleanup!
- e.refTo = this;
+ e.refTo = t;
// Was rewritten
- if (this.rewrites() !== undefined) {
+ if (t.rewrites() !== undefined) {
e.classList.add("rewritten");
};
- var refTitle = document.createElement('span');
+ const refTitle = document.createElement('span');
refTitle.classList.add('key','fixed', 'ref');
refTitle.addT('referTo');
// Added value operator
- this._refE = document.createElement('span');
- this._refE.setAttribute('data-type', "string");
- this._refE.setAttribute('class', 'value');
+ const refE = t._refE = document.createElement('span');
+ refE.setAttribute('data-type', "string");
+ refE.setAttribute('class', 'value');
+
if (this.ref()) {
- this._refE.addT(this.ref());
+ refE.addT(t.ref());
}
else {
- this._refE.addT(loc.EMPTY);
- this._refE.classList.add('unspecified');
+ refE.addT(loc.EMPTY);
+ refE.classList.add('unspecified');
};
// Change value
- this._refE.addEventListener(
+ refE.addEventListener(
'click',
- this._changeRef.bind(this)
+ t._changeRef.bind(t)
);
// Remove all element children
@@ -90,30 +92,30 @@
// Add spans
e.appendChild(refTitle);
- e.appendChild(this._refE);
+ e.appendChild(refE);
- this.__changed = false;
+ t.__changed = false;
- if (this._rewrites !== undefined) {
- e.appendChild(this._rewrites.element());
+ if (t._rewrites !== undefined) {
+ e.appendChild(t._rewrites.element());
};
- if (this._parent !== undefined) {
+ if (t._parent !== undefined) {
+
// Set operators
- var op = this.operators(
+ // Append new operators
+ e.appendChild(t.operators(
true,
true,
true
- );
-
- // Append new operators
- e.appendChild(op.element());
+ ).element());
};
- var vcchevent = new CustomEvent('vcChange', {'detail':this});
- KorAP.vc.element().dispatchEvent(vcchevent);
+ KorAP.vc.element().dispatchEvent(
+ new CustomEvent('vcChange', { 'detail' : t })
+ );
- return this.element();
+ return t.element();
},
@@ -121,12 +123,14 @@
* Get the associated element
*/
element : function () {
+
if (this._element !== undefined)
return this._element;
- this._element = document.createElement('div');
- this._element.setAttribute('class', 'doc groupref');
+
+ const e = this._element = document.createElement('div');
+ e.setAttribute('class', 'doc groupref');
this.update();
- return this._element;
+ return e;
},
@@ -145,10 +149,9 @@
// Click on the reference operator, show me the option
_changeRef : function (e) {
- var that = this;
-
- var str = stringValClass.create(this.ref(), false, false);
- var strElem = str.element();
+ const that = this;
+ const str = stringValClass.create(this.ref(), false, false);
+ const strElem = str.element();
str.store = function (ref, regex) {
that.ref(ref);
@@ -174,14 +177,15 @@
* This is copypasta from doc.js
*/
wrap : function (op) {
- var parent = this.parent();
- var group = require('vc/docgroup').create(parent);
+ const parent = this.parent();
+ const group = require('vc/docgroup').create(parent);
group.operation(op);
group.append(this);
group.append();
return parent.replaceOperand(this, group).update();
},
+
/**
* Deserialize from json
*/
@@ -210,6 +214,7 @@
return this;
},
+
/**
* Click on the unspecified object
*/
@@ -217,11 +222,13 @@
console.log("Do not support click on this");
},
+
// TODO: This is identical to doc.js
rewrites : function () {
return this._rewrites;
},
+
// TODO: This is identical to doc.js
rewrite : function (value) {
if (typeof value === 'string') {
@@ -245,7 +252,7 @@
if (this._rewrites === undefined)
return;
- delete this["_rewrites"];
+ delete this["_rewrites"];
if (this._element === undefined)
return;
@@ -253,13 +260,14 @@
this._element.classList.remove("rewritten");
},
+
toJson : function () {
if (!this.ref)
return {};
return {
"@type" : "koral:" + this.ldType(),
- "ref" : this.ref()
+ "ref" : this.ref()
};
},
@@ -268,6 +276,7 @@
return this.ref() ? false : true
},
+
toQuery : function () {
if (this.incomplete())
return "";
diff --git a/dev/js/src/vc/fragment.js b/dev/js/src/vc/fragment.js
index bf1905e..0f155ff 100644
--- a/dev/js/src/vc/fragment.js
+++ b/dev/js/src/vc/fragment.js
@@ -6,9 +6,9 @@
* @author Nils Diewald
*/
-define(['vc/doc', 'util'], function (docClass) {
+"use strict";
- "use strict";
+define(['vc/doc', 'util'], function (docClass) {
const loc = KorAP.Locale;
loc.NEW_CONSTRAINT = loc.NEW_CONSTRAINT || 'New Constraint';
@@ -29,7 +29,7 @@
const value = doc.addE('span');
value.setAttribute('class', 'value');
value.addT(op[1]);
-
+
return doc;
};
@@ -51,7 +51,7 @@
* Add document constraint to fragment
*/
add : function (key, value, type) {
- this._operands.forEach(function (op,i,arr) {
+ this._operands.forEach(function (op, i, arr) {
if (op[0] === key && op[1] === value) {
arr.splice(i,1);
}
@@ -94,14 +94,14 @@
};
// Initialize element
- this._element = document.createElement('div');
- this._element.classList.add('vc', 'fragment');
+ const e = this._element = document.createElement('div');
+ e.classList.add('vc', 'fragment');
// Prepend info text
- this._element.addE('span').addT(loc.NEW_CONSTRAINT + ':');
- this._frag = this._element.addE('div');
+ e.addE('span').addT(loc.NEW_CONSTRAINT + ':');
+ this._frag = e.addE('div');
- return this._element;
+ return e;
},
@@ -115,17 +115,13 @@
doc.key(item[0]);
doc.matchop("eq");
doc.value(item[1]);
- if (item[2] === "date") {
- doc.type("date");
- }
- else {
- doc.type("string");
- };
+ doc.type(item[2] === "date" ? "date" : "string");
return doc;
}
);
},
+
/**
* Update the whole object based on the underlying data structure
*/
diff --git a/dev/js/src/vc/item.js b/dev/js/src/vc/item.js
index f9267e8..59589d8 100644
--- a/dev/js/src/vc/item.js
+++ b/dev/js/src/vc/item.js
@@ -1,4 +1,6 @@
// Field menu item
+"use strict";
+
define(['menu/item', 'util'], function (itemClass) {
const loc = KorAP.Locale;
@@ -18,22 +20,26 @@
._init(params);
},
+
// Initialize item object
_init : function (params) {
+ const t = this;
+
if (params[0] === undefined)
throw new Error("Missing parameters");
- this._key = params[0];
- this._type = params[1];
+ t._key = params[0];
+ t._type = params[1];
- var k = this._key;
- this._name = loc["VC_" + k] ? loc["VC_" + k] : k;
+ const k = t._key;
+ t._name = loc["VC_" + k] ? loc["VC_" + k] : k;
- this._lcField = ' ' + this._name.toLowerCase();
+ t._lcField = ' ' + t._name.toLowerCase();
- return this;
+ return t;
},
+
/**
* Override click event by passing all clicks
* to the menu object.
@@ -46,6 +52,7 @@
e.halt();
},
+
/**
* Get the name of the item.
* This is a potential localized version
@@ -55,6 +62,7 @@
return this._name;
},
+
/**
* Get the type of the item.
*/
@@ -62,6 +70,7 @@
return this._type;
},
+
/**
* Get the key of the item.
*/
@@ -69,26 +78,29 @@
return this._key;
},
+
/**
* Get the HTML element associated with the item.
*/
element : function () {
+ const t = this;
// already defined
- if (this._element !== undefined)
- return this._element;
+ if (t._element !== undefined)
+ return t._element;
// Create list item
var li = document.createElement("li");
- if (this._type)
- li.setAttribute("data-type", this._type);
- li.setAttribute("data-key", this._key);
+ if (t._type)
+ li.setAttribute("data-type", t._type);
+
+ li.setAttribute("data-key", t._key);
// Connect action
- li["onclick"] = this.onclick.bind(this);
+ li["onclick"] = t.onclick.bind(t);
- li.addT(this._name);
- return this._element = li;
+ li.addT(t._name);
+ return t._element = li;
}
};
});
diff --git a/dev/js/src/vc/jsonld.js b/dev/js/src/vc/jsonld.js
index cfa0acc..fdee980 100644
--- a/dev/js/src/vc/jsonld.js
+++ b/dev/js/src/vc/jsonld.js
@@ -1,31 +1,38 @@
/**
* Abstract JsonLD criterion object
*/
+"use strict";
+
define(['vc/operators'], function (operatorsClass) {
+
return {
+
__changed : false,
create : function () {
return Object.create(this);
},
+
/**
* Upgrade this object to another object
* while private data stays intact
*/
upgradeTo : function (props) {
- for (var prop in props) {
+ for (let prop in props) {
this[prop] = props[prop];
};
return this;
},
+
ldType : function (type) {
if (arguments.length === 1)
this._ldType = type;
return this._ldType;
},
+
parent : function (obj) {
if (arguments.length === 1) {
this._parent = obj;
@@ -34,34 +41,35 @@
return this._parent;
},
+
// Destroy object - especially for
// acyclic structures!
// I'm paranoid!
destroy : function () {
-
- if (this._ops != undefined) {
- this._ops._parent = undefined;
- if (this._ops._element !== undefined) {
- this._ops._element.refTo = undefined;
+ const t = this;
+ if (t._ops != undefined) {
+ t._ops._parent = undefined;
+ if (t._ops._element !== undefined) {
+ t._ops._element.refTo = undefined;
};
- this._ops = undefined;
+ t._ops = undefined;
};
- if (this._element !== undefined)
- this._element = undefined;
+ if (t._element !== undefined)
+ t._element = undefined;
// In case of a group, destroy all operands
- if (this._operands !== undefined) {
- this._operands.forEach(i => i.destroy());
- this._operands = [];
+ if (t._operands !== undefined) {
+ t._operands.forEach(i => i.destroy());
+ t._operands = [];
};
},
// Wrap a new operation around the root group element
wrapOnRoot : function (op) {
- var parent = this.parent();
-
- var group = require('vc/docgroup').create(parent);
+ const parent = this.parent();
+ const group = require('vc/docgroup').create(parent);
+
if (arguments.length === 1)
group.operation(op);
else
@@ -76,17 +84,21 @@
return this.parent();
},
+
// Be aware! This may be cyclic
operators : function (and, or, del) {
if (arguments === 0)
return this._ops;
+
this._ops = operatorsClass.create(
and, or, del
);
+
this._ops.parent(this);
return this._ops;
},
+
toJson : function () {
return {
// Unspecified object
@@ -94,14 +106,17 @@
};
},
+
rewrites : function () {
return null;
},
+
incomplete : function () {
return false;
},
+
toQuery : function () {
return '';
}
diff --git a/dev/js/src/vc/menu.js b/dev/js/src/vc/menu.js
index f2f4b2f..40dbab0 100644
--- a/dev/js/src/vc/menu.js
+++ b/dev/js/src/vc/menu.js
@@ -1,22 +1,34 @@
/**
* Menu showing all key fields.
*/
-define(['menu', 'vc/item', 'vc/prefix'], function (menuClass, itemClass, prefixClass) {
+"use strict";
+
+define([
+ 'menu',
+ 'vc/item',
+ 'vc/prefix'
+], function (
+ menuClass,
+ itemClass,
+ prefixClass) {
return {
+
create : function (params) {
- var obj = Object.create(menuClass)
- .upgradeTo(this)
- ._init(params, {
- itemClass : itemClass,
- prefixClass : prefixClass
- });
+ const obj = Object.create(menuClass)
+ .upgradeTo(this)
+ ._init(params, {
+ itemClass : itemClass,
+ prefixClass : prefixClass
+ });
obj.limit(6);
// This is only domspecific
- obj.element().addEventListener('blur', function (e) {
- this.menu.hide();
- });
+ obj.element().addEventListener(
+ 'blur', function (e) {
+ this.menu.hide();
+ }
+ );
return obj;
},
@@ -38,6 +50,7 @@
this._cb(key, type);
},
+
/**
* Return a key type based on a key.
* This is a linear search, but should work okay for small
@@ -45,6 +58,7 @@
*/
typeOf : function (key) {
const found = this._items.find(i => i.key() === key);
+
if (found)
return found.type();
}
diff --git a/dev/js/src/vc/operators.js b/dev/js/src/vc/operators.js
index 306c371..928e943 100644
--- a/dev/js/src/vc/operators.js
+++ b/dev/js/src/vc/operators.js
@@ -1,21 +1,25 @@
/**
* Operators for criteria
*/
+"use strict";
+
define(['buttongroup'], function (buttonGroupClass) {
const loc = KorAP.Locale;
loc.DEL = loc.DEL || '×';
-
// Utility for analysing boolean values
function _bool (bool) {
- return (bool === undefined || bool === null || bool === false) ? false : true;
+ return (
+ bool === undefined ||
+ bool === null ||
+ bool === false) ? false : true;
};
// Add new unspecified document
function _add (obj, type) {
- var parent = obj.parent();
+ const parent = obj.parent();
if (obj.ldType() === 'docGroup') {
@@ -26,19 +30,24 @@
if (parent.ldType() !== null) {
return parent.newAfter(obj);
}
+
else {
// The group is on root - wrap
return obj.wrapOnRoot();
};
}
- else if (obj.ldType() === 'doc' || obj.ldType() === 'docGroupRef') {
+
+ else if (obj.ldType() === 'doc' ||
+ obj.ldType() === 'docGroupRef') {
if (parent.ldType() === null) {
return obj.wrapOnRoot(type);
}
+
else if (parent.operation() === type) {
return parent.newAfter(obj);
}
+
else {
return obj.wrap(type);
};
@@ -82,31 +91,34 @@
return op;
},
+
/*
- * Update the element
+ * Update the element
*/
update : function () {
+ const t = this;
// Clear button group
- this.clear();
+ t.clear();
- if (this._and === true) {
- this.add(loc.AND, {'cls':['and']}, KorAP._and);
+ if (t._and === true) {
+ t.add(loc.AND, {'cls':['and']}, KorAP._and);
};
// Add or button
- if (this._or === true) {
- this.add(loc.OR, {'cls':['or']}, KorAP._or);
+ if (t._or === true) {
+ t.add(loc.OR, {'cls':['or']}, KorAP._or);
};
// Add delete button
- if (this._del === true) {
- this.add(loc.DEL, {'cls':['delete']}, KorAP._delete);
+ if (t._del === true) {
+ t.add(loc.DEL, {'cls':['delete']}, KorAP._delete);
};
- return this.element();
+ return t.element();
},
+
// Be aware! This may be cyclic
// This is somehow redundant with bind, but relevant for ldTypes
parent : function (obj) {
@@ -116,21 +128,25 @@
// This is somehow duplicate - but it's not that relevant
this.bind(obj);
};
+
return this._parent;
},
+
and : function (bool) {
if (arguments.length === 1)
this._and = _bool(bool);
return this._and;
},
+
or : function (bool) {
if (arguments.length === 1)
this._or = _bool(bool);
return this._or;
},
+
del : function (bool) {
if (arguments.length === 1)
this._del = _bool(bool);
diff --git a/dev/js/src/vc/prefix.js b/dev/js/src/vc/prefix.js
index 5deefe4..32989bc 100644
--- a/dev/js/src/vc/prefix.js
+++ b/dev/js/src/vc/prefix.js
@@ -1,3 +1,5 @@
+"use strict";
+
define(['menu/prefix'], function (prefixClass) {
return {
@@ -9,6 +11,7 @@
upgradeTo(this)._init(params);
},
+
/**
* Override the prefix action.
*/
diff --git a/dev/js/src/vc/rewrite.js b/dev/js/src/vc/rewrite.js
index 150ee87..5af4b35 100644
--- a/dev/js/src/vc/rewrite.js
+++ b/dev/js/src/vc/rewrite.js
@@ -1,6 +1,8 @@
/**
* Implementation of rewrite objects.
*/
+"use strict";
+
define(['vc/jsonld', 'util'], function (jsonldClass) {
// injection, modification, and deletion should probably be enough
@@ -8,15 +10,16 @@
new RegExp("^(operation:)?(?:injec|inser|modifica|dele)tion|override$");
return {
+
// Construction method
create : function (json) {
- var obj = Object(jsonldClass).
- create().
- upgradeTo(this).
- fromJson(json);
- return obj;
+ return Object(jsonldClass).
+ create().
+ upgradeTo(this).
+ fromJson(json);
},
+
// Get or set source
src : function (string) {
if (arguments.length === 1)
@@ -24,6 +27,7 @@
return this._src;
},
+
// Get or set operation
operation : function (op) {
if (arguments.length === 1) {
@@ -38,6 +42,7 @@
return this._op || 'injection';
},
+
// Get or set scope
scope : function (attr) {
if (arguments.length === 1)
@@ -45,6 +50,7 @@
return this._scope;
},
+
// Serialize from Json
fromJson : function (json) {
if (json === undefined)
@@ -68,8 +74,7 @@
// Set operation
if (json["operation"] !== undefined) {
- var operation = json["operation"];
- this.operation(operation.replace(/^operation:/,''));
+ this.operation(json["operation"].replace(/^operation:/,''));
};
// Set scope
@@ -80,9 +85,10 @@
return this;
},
+
toString : function () {
- var str = '';
- var op = this.operation();
+ let str = '';
+ const op = this.operation();
str += op.charAt(0).toUpperCase() + op.slice(1);
str += ' of ' + (
this._scope === null ?
diff --git a/dev/js/src/vc/rewritelist.js b/dev/js/src/vc/rewritelist.js
index d6885c9..410c975 100644
--- a/dev/js/src/vc/rewritelist.js
+++ b/dev/js/src/vc/rewritelist.js
@@ -1,12 +1,14 @@
+"use strict";
+
define(['vc/jsonld', 'vc/rewrite','util'], function (jsonldClass, rewriteClass) {
return {
+
// Construction method
create : function (json) {
- var obj = Object(jsonldClass).
- create().
- upgradeTo(this).
- fromJson(json);
- return obj;
+ return Object(jsonldClass).
+ create().
+ upgradeTo(this).
+ fromJson(json);
},
@@ -24,10 +26,12 @@
return this;
},
+
length : function () {
return this._list.length;
},
+
/**
* Get element.
*/
@@ -35,19 +39,21 @@
if (this._element !== undefined)
return this._element;
- this._element = document.createElement('div');
- this._element.setAttribute('class', 'rewrite');
- var comments = [];
- this._list.forEach(function(rewrite) {
+ const e = this._element = document.createElement('div');
+ e.setAttribute('class', 'rewrite');
+
+ const comments = [];
+ let span, rewriteText;
+ this._list.forEach(function (rewrite) {
// This is a blind element
- var span = document.createElement('span');
+ span = document.createElement('span');
// Set class attribute
span.setAttribute('class', rewrite.operation());
// Append source information
- var rewriteText = rewrite.src();
+ rewriteText = rewrite.src();
// Append scope information
if (rewrite.scope() !== undefined) {
@@ -61,8 +67,10 @@
this._element.appendChild(span);
}, this);
- this._element.setAttribute("title", comments.join("\n"))
- return this._element;
+
+ e.setAttribute("title", comments.join("\n"))
+
+ return e;
}
};
});
diff --git a/dev/js/src/vc/statistic.js b/dev/js/src/vc/statistic.js
index 0c3c6ca..4dd5ab3 100644
--- a/dev/js/src/vc/statistic.js
+++ b/dev/js/src/vc/statistic.js
@@ -6,6 +6,8 @@
*
*/
+"use strict";
+
define([ 'util' ], function() {
return {
@@ -13,14 +15,15 @@
/**
* Create new statistic object
*/
- create : function(statistic) {
+ create : function (statistic) {
return Object.create(this)._init(statistic);
},
+
/**
* Initialize statistic object
*/
- _init : function(statistic) {
+ _init : function (statistic) {
if (statistic === undefined) {
throw new Error("Missing parameter");
} else {
@@ -29,10 +32,11 @@
}
},
+
/**
* Display statistic object as HTML Description List Element
*/
- element : function() {
+ element : function () {
// if this._element already exists return without doing something
if (this._element !== undefined) {
@@ -40,11 +44,13 @@
}
// create HTML Description List Element
- var statDL = document.createElement('dl');
+ const statDL = document.createElement('dl');
statDL.classList.add("flex");
- var statistic = this._statistic;
- Object.keys(statistic).forEach(function(k) {
+ const statistic = this._statistic;
+ let statSp, statDT, statDD;
+
+ Object.keys(statistic).forEach(function (k) {
statSp = statDL.addE('div')
statDT = statSp.addE('dt');
statDT.addT(k);
@@ -55,8 +61,7 @@
this._element = statDL;
return this._element;
- },
-
+ }
}
});
diff --git a/dev/js/src/vc/stringval.js b/dev/js/src/vc/stringval.js
index 8b05787..0705033 100644
--- a/dev/js/src/vc/stringval.js
+++ b/dev/js/src/vc/stringval.js
@@ -1,31 +1,34 @@
/**
* Add string values to the virtual corpus
*/
+"use strict";
+
define(['util'], {
/**
* Create new string value helper.
*/
create : function () {
- var regexOp = true;
- var regex = false;
- var value = '';
+ const a = arguments;
+ let regexOp = true,
+ regex = false,
+ value = '';
// Set value
- if (arguments.length >= 1) {
- if (arguments[0] !== undefined)
- value = arguments[0];
+ if (a.length >= 1) {
+ if (a[0] !== undefined)
+ value = a[0];
};
// Set regex
- if (arguments.length >= 2) {
- if (arguments[1] !== undefined)
- regex = arguments[1];
+ if (a.length >= 2) {
+ if (a[1] !== undefined)
+ regex = a[1];
};
// Set regexOp
- if (arguments.length >= 3) {
- regexOp = arguments[2];
+ if (a.length >= 3) {
+ regexOp = a[2];
if (regexOp === false) {
regex = false;
}
@@ -50,41 +53,31 @@
*/
regex : function (bool) {
if (arguments.length === 1) {
- if (bool) {
- this._regex = true;
- }
- else {
- this._regex = false;
- };
+ this._regex = bool ? true : false;
this._update();
};
return this._regex;
},
+
_regexOp : function (regexOp) {
if (arguments.length === 1) {
- if (regexOp) {
- this.__regexOp = true;
- }
- else {
- this.__regexOp = false;
- };
+ this.__regexOp = regexOp ? true : false;
this._update();
};
return this.__regexOp;
},
+
/**
* Toggle the regex, make it either true,
* if it is false, or make it false, if it is true.
*/
toggleRegex : function () {
- if (this._regex === false)
- this.regex(true);
- else
- this.regex(false);
+ this.regex(this._regex === false ? true : false);
},
+
/**
* Get or set the string value.
*/
@@ -97,6 +90,7 @@
return this._value;
},
+
// Update dom element
_update : function () {
if (this._element === undefined)
@@ -104,11 +98,13 @@
this._value = this._input.value;
+ const cl = this._element.classList;
+
if (this._regexOp() && this._regex) {
- this._element.classList.add('regex');
+ cl.add('regex');
}
else {
- this._element.classList.remove('regex');
+ cl.remove('regex');
};
},
@@ -120,6 +116,7 @@
*/
store : function (v,r) {},
+
/**
* Put focus on element
*/
@@ -127,6 +124,7 @@
this._element.children[0].focus();
},
+
/**
* Get the associated dom element.
*/
@@ -135,12 +133,11 @@
return this._element;
// Create element
- this._element = document.createElement('div');
- var e = this._element;
+ const e = this._element = document.createElement('div');
e.setAttribute('tabindex', 0);
e.style.outline = 0;
- var cl = e.classList;
+ const cl = e.classList;
cl.add('value');
if (this.regex() === true)
cl.add('regex');
@@ -154,10 +151,10 @@
// Add regex button
if (this._regexOp()) {
- var re = e.addE('div');
+ const re = e.addE('div');
re.addEventListener(
'click',
- function (ev) {
+ function () {
this.toggleRegex();
// ev.halt();
}.bind(this),
@@ -170,10 +167,11 @@
// delegate focus to
this._input.addEventListener(
'blur',
- function (ev) {
- if (!this._inField) {
- this.value(this._input.value);
- this.store(this.value(), this.regex());
+ function () {
+ const t = this;
+ if (!t._inField) {
+ t.value(t._input.value);
+ t.store(t.value(), t.regex());
};
ev.halt();
}.bind(this)
@@ -182,14 +180,14 @@
// Workaround to check the click is in the field
e.addEventListener(
'mousedown',
- function (ev) {
+ function () {
this._inField = true;
}.bind(this)
);
e.addEventListener(
'mouseup',
- function (ev) {
+ function () {
this._inField = false;
this._input.focus();
}.bind(this)
@@ -198,9 +196,10 @@
this._input.addEventListener(
'keypress',
function (ev) {
+ const t = this;
if (ev.keyCode == 13) {
- this.value(this._input.value);
- this.store(this.value(), this.regex());
+ t.value(t._input.value);
+ t.store(t.value(), t.regex());
return false;
};
}.bind(this)
diff --git a/dev/js/src/vc/unspecified.js b/dev/js/src/vc/unspecified.js
index 4ffe507..fe089a3 100644
--- a/dev/js/src/vc/unspecified.js
+++ b/dev/js/src/vc/unspecified.js
@@ -2,6 +2,8 @@
* An unspecified criterion in a virtual corpus.
* Inherits everything from jsonld
*/
+"use strict";
+
define([
'vc/jsonld',
'vc/doc',
@@ -10,7 +12,7 @@
], function (jsonldClass, docClass, docGroupRefClass) {
// Localize empty string
- var loc = KorAP.Locale;
+ const loc = KorAP.Locale;
loc.EMPTY = loc.EMPTY || '⋯';
return {
@@ -23,7 +25,7 @@
* with a link to the parent object
*/
create : function (parent) {
- var obj = Object.create(jsonldClass).
+ const obj = Object.create(jsonldClass).
upgradeTo(this);
if (parent !== undefined)
@@ -32,6 +34,7 @@
return obj;
},
+
/**
* Set the key; this will spawn a new doc
*/
@@ -41,8 +44,8 @@
if (this._parent === undefined)
return null;
- var newDoc;
- var keyType = KorAP._vcKeyMenu.typeOf(v);
+ let newDoc;
+ const keyType = KorAP._vcKeyMenu.typeOf(v);
// Set JSON-LD type
if (keyType && keyType === 'ref') {
@@ -73,39 +76,39 @@
* Update the element
*/
update : function () {
+ const t = this;
- if (this._element === undefined)
- return this.element();
+ if (t._element === undefined)
+ return t.element();
// Remove element content
- _removeChildren(this._element);
+ _removeChildren(t._element);
- var ellipsis = document.createElement('span');
+ const ellipsis = document.createElement('span');
ellipsis.addT(loc.EMPTY);
// Click on empty criterion
- ellipsis.addEventListener('click', this.onclick.bind(this));
+ ellipsis.addEventListener('click', t.onclick.bind(t));
- this._element.appendChild(ellipsis);
+ t._element.appendChild(ellipsis);
// Set ref - TODO: Cleanup!
- this._element.refTo = this;
+ t._element.refTo = t;
// Set operators
- if (this._parent !== undefined &&
- this.parent().ldType() !== null) {
- var op = this.operators(
- false,
- false,
- true
- );
-
- this._element.appendChild(
- op.element()
+ if (t._parent !== undefined &&
+ t.parent().ldType() !== null) {
+
+ t._element.appendChild(
+ t.operators(
+ false,
+ false,
+ true
+ ).element()
);
};
- return this.element();
+ return t.element();
},
@@ -113,12 +116,13 @@
* Get the associated element
*/
element : function () {
- if (this._element !== undefined)
- return this._element;
- this._element = document.createElement('div');
- this._element.setAttribute('class', 'doc unspecified');
- this.update();
- return this._element;
+ const t = this;
+ if (t._element !== undefined)
+ return t._element;
+ t._element = document.createElement('div');
+ t._element.setAttribute('class', 'doc unspecified');
+ t.update();
+ return t._element;
},
@@ -126,13 +130,14 @@
return true;
},
+
/**
* Click on the unspecified object
*/
onclick : function () {
// Get the key menu
- var menu = KorAP._vcKeyMenu;
+ const menu = KorAP._vcKeyMenu;
// Add key menu element at the correct position
this._element.insertBefore(
@@ -140,7 +145,7 @@
this._element.firstChild
);
- var that = this;
+ const that = this;
// Set released method
menu.released(function (key) {