Remove multiple menus in hint
diff --git a/dev/demo/build.html b/dev/demo/build.html
index 9e577de..e68cfd8 100644
--- a/dev/demo/build.html
+++ b/dev/demo/build.html
@@ -96,7 +96,7 @@
<!--
<ul class="action right">
<li class="close" title="Close"><a href="#">Close hit<i class="fa fa-toggle-up"></i></a></li>
- <li class="open" title="Open in new tab"><a href="#WPD-WWW.03313-p102-103" target="_blank"><i class="fa fa-external-link-square"></i></a></li>
+ <li class="open" title="Open in new tab"><a href="#WPD-WWW.03313-p102-103" target="_blank" rel="noopener noreferrer"><i class="fa fa-external-link-square"></i></a></li>
<li onclick="showTable(this)" title="Annotations"><i class="fa fa-info-circle"></i></li>
</ul>
-->
@@ -114,7 +114,7 @@
<p class="ref"><strong>Fehlbezogenes Adjektiv</strong> by Joni2,Peterlustig,BWBot; published on 2005-03-28 as FFF.01460 (WPD)</p>
<ul class="action right">
<li class="close" title="Close"><a href="#"><i class="fa fa-toggle-up"></i></a></li>
- <li class="open" title="Open in new tab"><a href="#WPD-FFF.01460-p119-120" target="_blank"><i class="fa fa-external-link-square"></i></a></li>
+ <li class="open" title="Open in new tab"><a href="#WPD-FFF.01460-p119-120" target="_blank" rel="noopener noreferrer"><i class="fa fa-external-link-square"></i></a></li>
<li onclick="showTable(this)" title="Annotations"><i class="fa fa-info-circle"></i></li>
</ul>
</li>
@@ -132,7 +132,7 @@
<p class="ref"><strong>High Definition Television</strong> by ArtMechanic,TheK,Andreas -horn- Hornig; published on 2005-03-28 as HHH.06056 (WPD)</p>
<ul class="action right">
<li class="close" title="Close"><a href="#"><i class="fa fa-toggle-up"></i></a></li>
- <li class="open" title="Open in new tab"><a href="#WPD-HHH.06056-p2564-2565" target="_blank"><i class="fa fa-external-link-square"></i></a></li>
+ <li class="open" title="Open in new tab"><a href="#WPD-HHH.06056-p2564-2565" target="_blank" rel="noopener noreferrer"><i class="fa fa-external-link-square"></i></a></li>
<li onclick="showTable(this)" title="Annotations"><i class="fa fa-info-circle"></i></li>
</ul>
</li>
diff --git a/dev/js/spec/hintSpec.js b/dev/js/spec/hintSpec.js
index 0ebb0e4..667ac7a 100644
--- a/dev/js/spec/hintSpec.js
+++ b/dev/js/spec/hintSpec.js
@@ -223,56 +223,39 @@
expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(3);
-
+
// Hide the menu and focus on the input
hint.unshow();
-
- console.log('1: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
- console.log(hint.inputField().container().innerHTML);
-
- /*
-
-
-
- expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
- expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(3);
+
+ expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(1);
+ expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(0);
hint.unshow();
+
hint.inputField().insert(' hhhh');
+
// show with context
hint.show(false);
-
- console.log('2: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
- console.log(hint.inputField().container().innerHTML);
-
+
expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(2);
-
-
-
-
-
-
-
-
hint.unshow();
hint.inputField().insert(' aaaa/');
// show with context
hint.show(true);
- console.log(hint.inputField().container().outerHTML);
-
expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
-*/
});
-
+
xit('should remove all menus on escape');
});
+
+
describe('KorAP.HintMenuItem', function () {
it('should be initializable', function () {
expect(
@@ -495,7 +478,7 @@
it('should be initializable', function () {
var menu = menuClass.create(null, "cnx/", list);
expect(menu.element().nodeName).toEqual('UL');
- expect(menu.element().style.opacity).toEqual("0");
+ // expect(menu.element().style.opacity).toEqual("0");
menu.limit(8);
diff --git a/dev/js/src/hint.js b/dev/js/src/hint.js
index 8859c0a..c5c689c 100644
--- a/dev/js/src/hint.js
+++ b/dev/js/src/hint.js
@@ -5,6 +5,7 @@
* @author Nils Diewald
*/
/*
+ * TODO: Check for cnx/syn=
* TODO: List can be shown when prefix is like 'base/s=pcorenlp/'
* TODO: Sometimes the drop-down box down vanish when list is shown
* TODO: Create should expect an input text field
@@ -195,8 +196,9 @@
// Get context (aka left text)
var context = this._inputField.context();
- if (context === undefined || context.length === 0)
- return ifContext ? undefined : this.menu("-");
+ if (context === undefined || context.length === 0) {
+ return ifContext ? false : this.menu("-");
+ };
// Get context (aka left text matching regex)
context = this._analyzer.test(context);
@@ -239,8 +241,7 @@
/**
* Show the menu.
- * Currently this means that multiple menus may be loaded
- * but not shown.
+ * Remove all old menus.
*
* @param {boolean} Boolean value to indicate if context
* is necessary (true) or if the main context should
@@ -260,7 +261,7 @@
};
// This may already be hidden!
- this._active.hide();
+ // this._active.hide();
this.active(null);
// Alert is not active
@@ -283,26 +284,40 @@
menu.focus();
// Focus on input field
// this.inputField.element.focus();
+ }
+ else {
+ this._inputField.element().focus();
};
},
- // Show an object in the containerField
- // This will hide all other objects
- // Accepts menus as well as alerts
- show2 : function (obj) {
- var c = this._inputField.container();
-
- },
-
// This will get the context of the field
getContext : function () {},
/**
* Deactivate the current menu and focus on the input field.
*/
- unshow : function () {
+ unshow_old : function () {
this.active(null);
this.inputField().element().focus();
+ },
+
+ /**
+ * Deactivate the current menu and focus on the input field.
+ */
+ unshow : function () {
+ var c = this._inputField.container();
+
+ if (this.active() !== null) {
+ var act = this.active();
+
+ // This does not work for alert currently!
+ if (act._type !== 'alert') {
+ c.removeChild(this._active.element());
+ };
+ // this._active.hide();
+ this.active(null);
+ };
+ this._inputField.element().focus();
}
};
});
diff --git a/dev/js/src/hint/item.js b/dev/js/src/hint/item.js
index cfea816..66819c6 100644
--- a/dev/js/src/hint/item.js
+++ b/dev/js/src/hint/item.js
@@ -9,23 +9,23 @@
*/
create : function (params) {
return Object.create(itemClass)
- .upgradeTo(this)
- ._init(params);
+ .upgradeTo(this)
+ ._init(params);
},
// Initialize menu item object
_init : function (params) {
if (params[0] === undefined ||
- params[1] === undefined)
- throw new Error("Missing parameters");
+ params[1] === undefined)
+ throw new Error("Missing parameters");
this._name = params[0];
this._action = params[1];
this._lcField = ' ' + this._name.toLowerCase();
if (params.length > 2) {
- this._desc = params[2];
- this._lcField += " " + this._desc.toLowerCase();
+ this._desc = params[2];
+ this._lcField += " " + this._desc.toLowerCase();
};
return this;
@@ -36,7 +36,7 @@
*/
content : function (content) {
if (arguments.length === 1) {
- this._content = content;
+ this._content = content;
};
return this._content;
},
@@ -89,13 +89,13 @@
element : function () {
// already defined
if (this._element !== undefined)
- return this._element;
+ return this._element;
// Create list item
var li = document.createElement("li");
if (this.onclick !== undefined) {
- li["onclick"] = this.onclick.bind(this);
+ li["onclick"] = this.onclick.bind(this);
};
// Create title
@@ -106,10 +106,10 @@
// Create description
if (this._desc !== undefined) {
- var desc = document.createElement("span");
- desc.classList.add('desc');
- desc.appendChild(document.createTextNode(this._desc));
- li.appendChild(desc);
+ var desc = document.createElement("span");
+ desc.classList.add('desc');
+ desc.appendChild(document.createTextNode(this._desc));
+ li.appendChild(desc);
};
return this._element = li;
}