Introduced alert information to hint helper
diff --git a/dev/demo/hint.html b/dev/demo/hint.html
index 7d93d73..38c4a99 100644
--- a/dev/demo/hint.html
+++ b/dev/demo/hint.html
@@ -14,10 +14,13 @@
placeholder="Find ..."
name="q"
id="q-field"
+ value="mbfhjgfghfhgfhfghfghnhvrthrjvztrhhrnvnthvft"
autofocus="autofocus" />
<button type="submit"><span>Go</span></button>
</div>
</form>
</header>
+
+ <a onclick="demoAlert(14, 'This is a warning')">Alert at 14</a>
</body>
</html>
diff --git a/dev/demo/hintdemo.js b/dev/demo/hintdemo.js
index fabf0c2..fd80b43 100644
--- a/dev/demo/hintdemo.js
+++ b/dev/demo/hintdemo.js
@@ -5,9 +5,16 @@
}
});
+var hint = undefined;
+
require(['hint','hint/array','lib/domReady'], function (hintClass, hintArray, domReady) {
KorAP.hintArray = hintArray;
domReady(function() {
- hintClass.create();
+ hint = hintClass.create();
});
});
+
+function demoAlert (pos, msg) {
+ if (hint !== undefined)
+ hint.charAlert(pos, msg);
+}
diff --git a/dev/js/spec/hintSpec.js b/dev/js/spec/hintSpec.js
index 6cfd218..554b61d 100644
--- a/dev/js/spec/hintSpec.js
+++ b/dev/js/spec/hintSpec.js
@@ -7,16 +7,16 @@
"initKeyboardEvent" : "initKeyEvent";
keyboardEvent[initMethod](
type,
- true, // bubbles
- true, // cancelable
- window, // viewArg: should be window
- false, // ctrlKeyArg
- false, // altKeyArg
- false, // shiftKeyArg
- false, // metaKeyArg
+ true, // bubbles
+ true, // cancelable
+ window, // viewArg: should be window
+ false, // ctrlKeyArg
+ false, // altKeyArg
+ false, // shiftKeyArg
+ false, // metaKeyArg
keyCode, // keyCodeArg : unsigned long the virtual key code, else 0
- 0 // charCodeArgs : unsigned long the Unicode character
- // associated with the depressed key, else 0
+ 0 // charCodeArgs : unsigned long the Unicode character
+ // associated with the depressed key, else 0
);
element.dispatchEvent(keyboardEvent);
};
diff --git a/dev/js/src/hint.js b/dev/js/src/hint.js
index 1db2fd0..4f55d0f 100644
--- a/dev/js/src/hint.js
+++ b/dev/js/src/hint.js
@@ -4,6 +4,12 @@
*
* @author Nils Diewald
*/
+/*
+ * 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
+ * TODO: Embed only one single menu (not multiple)
+ */
define([
'hint/input',
'hint/menu',
@@ -24,7 +30,7 @@
"(?:[-_a-zA-Z0-9]+?)=" + // Layer
"(?:"+
"(?:[^:=\/ ]+?):|" + // Key
- "(?:[^-=\/ ]+?)-" + // Node
+ "(?:[^-=\/ ]+?)-" + // Node
")?" +
")?" +
")$";
@@ -106,10 +112,27 @@
return this;
},
+
+ /**
+ * Return the input field attached to the hint helper.
+ */
inputField : function () {
return this._inputField;
},
+
+ /**
+ * Altert at a specific character position.
+ */
+ charAlert : function (charPos, msg) {
+ this._inputField.moveto(charPos);
+ var c = this._inputField.container();
+ c.classList.add('active');
+ var error = c.appendChild(document.createElement('div'));
+ error.classList.add('alert', 'hint');
+ error.appendChild(document.createTextNode(msg));
+ },
+
/**
* Return hint menu and probably init based on an action
*/
@@ -148,7 +171,9 @@
/**
- * Show the menu
+ * Show the menu.
+ * Currently this means that multiple menus may be loaded
+ * but not shown.
*/
show : function (ifContext) {
@@ -164,8 +189,8 @@
c.appendChild(menu.element());
menu.show();
menu.focus();
- // Focus on input field
- // this.inputField.element.focus();
+ // Focus on input field
+ // this.inputField.element.focus();
};
}
};
diff --git a/dev/js/src/hint/input.js b/dev/js/src/hint/input.js
index c12d26a..6e02793 100644
--- a/dev/js/src/hint/input.js
+++ b/dev/js/src/hint/input.js
@@ -1,4 +1,8 @@
// Input field for queries
+/*
+ * TODO: Support allert for query problems.
+ */
+
define({
/**
@@ -7,38 +11,7 @@
create : function (element) {
return Object.create(this)._init(element);
},
-
- // Initialize new input field
- _init : function (element) {
- this._element = element;
- // Create mirror for searchField
- if ((this._mirror = document.getElementById("searchMirror")) === null) {
- this._mirror = document.createElement("div");
- this._mirror.setAttribute("id", "searchMirror");
- this._mirror.appendChild(document.createElement("span"));
- this._container = this._mirror.appendChild(document.createElement("div"));
- this._mirror.style.height = "0px";
- document.getElementsByTagName("body")[0].appendChild(this._mirror);
- };
-
- // Update position of the mirror
- var that = this;
- var repos = function () {
- that.reposition();
- };
- window.addEventListener('resize', repos);
- this._element.addEventListener('onfocus', repos);
- that.reposition();
-
- return this;
- },
-
- // Get the right position
- _rightPos : function () {
- var box = this._mirror.firstChild.getBoundingClientRect();
- return box.right - box.left;
- },
/**
* Get the mirrored input field.
@@ -50,8 +23,9 @@
/**
* Get the container element.
- * This contains the mirror and
- * the hint helper.
+ * This contains the hint helper / menus
+ * and probably an
+ * error message.
*/
container : function () {
return this._container;
@@ -66,6 +40,7 @@
return this._element;
},
+
/**
* Get the value of the input field
* the hint helper is attached to.
@@ -81,8 +56,10 @@
update : function () {
this._mirror.firstChild.textContent = this._split()[0];
this._container.style.left = this._rightPos() + 'px';
+ return this;
},
+
/**
* Insert text into the mirror.
* This is a prefix of the input field's
@@ -94,9 +71,21 @@
s.value = splittedText[0] + text + splittedText[1];
s.selectionStart = (splittedText[0] + text).length;
s.selectionEnd = s.selectionStart;
+
+ // Maybe update?
this._mirror.firstChild.textContent = splittedText[0] + text;
+ return this;
},
-
+
+ /**
+ * Move hinthelper to given character position
+ */
+ moveto : function (charpos) {
+ this._element.selectionStart = charpos;
+ this._element.selectionEnd = charpos;
+ this._element.focus();
+ return this.update();
+ },
/**
* Reposition the input mirror directly
@@ -124,6 +113,7 @@
mirrorStyle.fontFamily = inputStyle.getPropertyValue("font-family");
},
+
/**
* Get the context, which is the input
* field's value bounded to the
@@ -133,14 +123,49 @@
return this._split()[0];
},
+
+ // Initialize new input field
+ _init : function (element) {
+ this._element = element;
+
+ // Create mirror for searchField
+ // This is important for positioning
+ if ((this._mirror = document.getElementById("searchMirror")) === null) {
+ this._mirror = document.createElement("div");
+ this._mirror.setAttribute("id", "searchMirror");
+ this._mirror.appendChild(document.createElement("span"));
+ this._container = this._mirror.appendChild(document.createElement("div"));
+ this._mirror.style.height = "0px";
+ document.getElementsByTagName("body")[0].appendChild(this._mirror);
+ };
+
+ // Update position of the mirror
+ window.addEventListener('resize', this.reposition.bind(this));
+ this._element.addEventListener('onfocus', this.reposition.bind(this));
+ this.reposition();
+ return this;
+ },
+
+ // Get the right position
+ _rightPos : function () {
+ var box = this._mirror.firstChild.getBoundingClientRect();
+ return box.right - box.left;
+ },
+
+
/*
* Return two substrings,
- * splitted at the current cursor position.
+ * splitted at a given position
+ * or at the current cursor position.
*/
- _split : function () {
+ _split : function (start) {
var s = this._element;
var value = s.value;
- var start = s.selectionStart;
+
+ // Get start from cursor position
+ if (arguments.length === 0)
+ start = s.selectionStart;
+
return new Array(
value.substring(0, start),
value.substring(start, value.length)
diff --git a/dev/js/src/hint/item.js b/dev/js/src/hint/item.js
index b9a1bc8..7d97334 100644
--- a/dev/js/src/hint/item.js
+++ b/dev/js/src/hint/item.js
@@ -52,8 +52,7 @@
// Update input field
var input = h.inputField();
- input.insert(this._action);
- input.update();
+ input.insert(this._action).update();
h.active = false;
diff --git a/dev/js/src/menu.js b/dev/js/src/menu.js
index 4d9df49..e8028ea 100644
--- a/dev/js/src/menu.js
+++ b/dev/js/src/menu.js
@@ -8,6 +8,7 @@
* TODO: Show the slider briefly on move (whenever screen is called).
* TODO: Ignore alt+ and strg+ key strokes.
* TODO: Should scroll to a chosen value after prefixing, if the chosen value is live
+ * Add a "title" to a menu that is not scrollable.
*/
define([
'menu/item',
diff --git a/dev/scss/base.scss b/dev/scss/base.scss
index 2fe143d..cbdc377 100644
--- a/dev/scss/base.scss
+++ b/dev/scss/base.scss
@@ -18,6 +18,17 @@
@include box-sizing-box;
}
+/*
+html {
+// @include box-sizing-box;
+ box-sizing: border-box;
+}
+
+*, *:before, *:after {
+ box-sizing: inherit;
+}
+*/
+
g > text {
fill: $dark-grey;
}
diff --git a/dev/scss/header/hint.scss b/dev/scss/header/hint.scss
index 7e15d18..a50ffbf 100644
--- a/dev/scss/header/hint.scss
+++ b/dev/scss/header/hint.scss
@@ -27,6 +27,38 @@
}
}
+div.alert.hint {
+ position: relative;
+ background-color: rgba(254,26,0,.9); // from alertify
+ color: $nearly-white;
+ padding: $item-padding;
+ margin-top: 5px;
+ box-shadow: $choose-box-shadow;
+ border: {
+ radius: $standard-border-radius;
+ top-left-radius: 0;
+ }
+}
+
+div.hint.alert::before {
+ position: absolute;
+ content: "";
+ display: block;
+ top: -8px;
+ left: 0px;
+ width: 0;
+ white-space: normal;
+ border: {
+ width: 0 8px 8px 0;
+ style: solid;
+ color: rgba(254,26,0,.9) transparent; // from alertify
+ }
+}
+
+
+
+
+
#searchMirror {
position: absolute;
left: 0;
diff --git a/dev/scss/util.scss b/dev/scss/util.scss
index b129e2e..a33644a 100644
--- a/dev/scss/util.scss
+++ b/dev/scss/util.scss
@@ -182,6 +182,7 @@
/**
* Mixing for correct box sizing (probably not necessary)
+ * DEPRECATED
*/
@mixin box-sizing-box() {
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */