Support blur on string values in virtual corpora
Change-Id: I809b9d5c7b9d04a4ab0ce2835d2f0fdd461e5454
diff --git a/dev/js/src/vc.js b/dev/js/src/vc.js
index d6a26f2..4772115 100644
--- a/dev/js/src/vc.js
+++ b/dev/js/src/vc.js
@@ -243,8 +243,9 @@
* Get the element associated with the virtual collection
*/
element : function () {
- if (this._element !== undefined)
- return this._element;
+ if (this._element !== undefined) {
+ return this._element;
+ };
this._element = document.createElement('div');
this._element.setAttribute('class', 'vc');
@@ -270,18 +271,18 @@
* as a creation date limit criterion.
*/
makePersistant : function () {
-// this.root().wrapOnRoot('and');
+ // this.root().wrapOnRoot('and');
var todayStr = KorAP._vcDatePicker.today();
var doc = docClass.create();
var root = this.root();
if (root.ldType() === 'docGroup' &&
- root.operation === 'and') {
- root.append(cond);
+ root.operation === 'and') {
+ root.append(cond);
}
else {
- root.wrapOnRoot('and');
- root.append(doc);
+ root.wrapOnRoot('and');
+ root.append(doc);
};
doc.key("creationDate");
diff --git a/dev/js/src/vc/stringval.js b/dev/js/src/vc/stringval.js
index 595057a..1cebde4 100644
--- a/dev/js/src/vc/stringval.js
+++ b/dev/js/src/vc/stringval.js
@@ -87,11 +87,14 @@
/**
* Store the string value.
* This method should be overwritten.
- * The method receives the the value and the regex.
+ * The method receives the value and the regex.
*/
store : function (v,r) {},
+ /**
+ * Put focus on element
+ */
focus : function () {
this._element.children[0].focus();
},
@@ -127,26 +130,47 @@
);
re.addEventListener(
'click',
- function (e) {
+ function (ev) {
this.toggleRegex();
- e.halt();
+ // ev.halt();
}.bind(this),
true
);
re.appendChild(document.createTextNode('RE'));
- e.addEventListener(
+ // If the focus is not on the text field anymore,
+ // delegate focus to
+ this._input.addEventListener(
'blur',
- function (e) {
- this.store(this.value(), this.regex());
- e.halt();
+ function (ev) {
+ if (!this._inField) {
+ this.value(this._input.value);
+ this.store(this.value(), this.regex());
+ };
+ ev.halt();
+ }.bind(this)
+ );
+
+ // Workaround to check the click is in the field
+ e.addEventListener(
+ 'mousedown',
+ function (ev) {
+ this._inField = true;
+ }.bind(this)
+ );
+
+ e.addEventListener(
+ 'mouseup',
+ function (ev) {
+ this._inField = false;
+ this._input.focus();
}.bind(this)
);
this._input.addEventListener(
'keypress',
- function (e) {
- if (e.keyCode == 13) {
+ function (ev) {
+ if (ev.keyCode == 13) {
this.value(this._input.value);
this.store(this.value(), this.regex());
return false;