Added string value helper for virtual collections
diff --git a/dev/js/spec/vcSpec.js b/dev/js/spec/vcSpec.js
index 792dc3e..e1ef441 100644
--- a/dev/js/spec/vcSpec.js
+++ b/dev/js/spec/vcSpec.js
@@ -9,6 +9,7 @@
var unspecifiedClass = require('vc/unspecified');
var operatorsClass = require('vc/operators');
var rewriteClass = require('vc/rewrite');
+ var stringValClass = require('vc/stringval');
// Helper method for building factories
buildFactory = function (objClass, defaults) {
@@ -1943,5 +1944,19 @@
expect(docKey.toString()).toEqual('...');
});
});
+
+ expect(
+ function() { menuItemClass.create([]) }
+ ).toThrow(new Error("Missing parameters"));
+
+
*/
+
+ describe('KorAP.stringValue', function () {
+ it('should be initializable', function () {
+ var sv = stringValClass.create();
+ expect(sv.regex()).toBe(false);
+ expect(sv.value()).toBe('');
+ });
+ });
});
diff --git a/dev/js/src/vc/doc.js b/dev/js/src/vc/doc.js
index a19430a..23cec07 100644
--- a/dev/js/src/vc/doc.js
+++ b/dev/js/src/vc/doc.js
@@ -5,8 +5,9 @@
define([
'vc/jsonld',
'vc/rewritelist',
+ 'vc/stringval',
'util'
-], function (jsonldClass, rewriteListClass) {
+], function (jsonldClass, rewriteListClass, stringValClass) {
/*
var fieldMenu = menuClass.create([
diff --git a/dev/js/src/vc/stringval.js b/dev/js/src/vc/stringval.js
new file mode 100644
index 0000000..e07b6a4
--- /dev/null
+++ b/dev/js/src/vc/stringval.js
@@ -0,0 +1,91 @@
+/**
+ * Add string values to the virtual collection
+ */
+define({
+ create : function () {
+ var regex = false;
+ var value = '';
+ if (arguments.length == 2) {
+ regex = arguments[1];
+ };
+ if (arguments.length > 1) {
+ value = arguments[0];
+ };
+ return Object.create(this)._init(value, regex);
+ },
+
+ _init : function (value, regex) {
+ this.element();
+ this.value(value);
+ this.regex(regex);
+ return this;
+ },
+
+ regex : function (bool) {
+ if (arguments.length === 1) {
+ if (bool) {
+ this._regex = true;
+ }
+ else {
+ this._regex = false;
+ };
+ this._update();
+ };
+ return this._regex;
+ },
+
+ toggleRegex : function () {
+ if (this._regex === false)
+ this.regex(true);
+ else
+ this.regex(false);
+ },
+
+ value : function (val) {
+ if (arguments.length === 1) {
+ this._value = val;
+ this._update();
+ };
+ return this._value;
+ },
+
+ _update : function () {
+ this._input.firstChild.data = this._value;
+ if (this._regex) {
+ this._element.classList.add('regex');
+ }
+ else {
+ this._element.classList.add('regex');
+ };
+ },
+
+ element : function () {
+ if (this._element !== undefined)
+ return this._element;
+
+ this._element = document.createElement('div');
+ var cl = this._element.classList;
+ cl.add('vc-value');
+ if (this.regex())
+ cl.add('regex');
+
+ this._input = this._element.appendChild(
+ document.createElement('input')
+ );
+ this._input.appendChild(
+ document.createTextNode(this.value())
+ );
+
+ this._element.appendChild(
+ document.createElement('div')
+ ).addEventListener('click', function (e) {
+ this.toggleRegex();
+ }.bind(this));
+
+ var go = this._element.appendChild(
+ document.createElement('span')
+ );
+
+ return this._element;
+ }
+});