Integrated hint alerts in the main frame
diff --git a/dev/js/src/hint.js b/dev/js/src/hint.js
index 4f55d0f..455312d 100644
--- a/dev/js/src/hint.js
+++ b/dev/js/src/hint.js
@@ -14,10 +14,12 @@
'hint/input',
'hint/menu',
'hint/contextanalyzer',
+ 'hint/alert',
'util'
], function (inputClass,
- menuClass,
- analyzerClass) {
+ menuClass,
+ analyzerClass,
+ alertClass) {
"use strict";
/**
@@ -52,7 +54,7 @@
// Some variables
// _firstTry : true,
- active : false,
+ // active : false,
/**
* Create new hint helper.
@@ -66,29 +68,27 @@
param = param || {};
// Holds all menus per prefix context
- this._menu = {};
+ this._menu = {};
+ this._alert = alertClass.create();
+ this._active = false;
// Get input field
var qfield = param["inputField"] || document.getElementById("q-field");
if (!qfield)
return null;
+ // Create input field
this._inputField = inputClass.create(qfield);
var inputFieldElement = this._inputField.element();
- var that = this;
+ var c = this._inputField.container();
- // Add event listener for key pressed down
- inputFieldElement.addEventListener(
- "keydown", function (e) {
- var code = _codeFromEvent(e);
- if (code === 40) {
- that.show(false);
- e.halt();
- };
- }, false
- );
+ // create alert
+ c.appendChild(this._alert.element());
+
+
+ var that = this;
this._inputField.container().addEventListener('click', function (e) {
if (!this.classList.contains('active')) {
@@ -96,14 +96,22 @@
};
});
- var _up = function (e) {
- var input = that._inputField;
- input.update();
+ var _down = function (e) {
+ var code = _codeFromEvent(e);
+ if (code === 40) {
+ this.show(false);
+ e.halt();
+ };
};
// Move infobox
- inputFieldElement.addEventListener("keyup", _up);
- inputFieldElement.addEventListener("click", _up);
+ inputFieldElement.addEventListener("keyup", this.update.bind(this));
+ inputFieldElement.addEventListener("click", this.update.bind(this));
+
+ // Add event listener for key pressed down
+ inputFieldElement.addEventListener(
+ "keydown", _down.bind(this), false
+ );
// Set Analyzer for context
this._analyzer = analyzerClass.create(
@@ -124,15 +132,37 @@
/**
* Altert at a specific character position.
*/
- charAlert : function (charPos, msg) {
+ alert : function (charPos, msg) {
+
+ if (arguments.length === 0)
+ return this._alert;
+
+ // Do not alert if already alerted!
+ if (this._alert.active)
+ return false;
+
+ // Move to the correct position
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));
+
+ // Set container to active (aka hide the hint helper button)
+
+ this._alert.show(msg);
+ this.active(true);
+ return true;
},
+ _unshowAlert : function () {
+ this._alert.unshow();
+ this.active(false);
+ },
+
+ update : function () {
+ this._inputField.update();
+ if (this._alert.unshow())
+ this.active(false);
+ },
+
+
/**
* Return hint menu and probably init based on an action
*/
@@ -169,6 +199,21 @@
return this.menu(context);
},
+ active : function (bool) {
+ if (arguments.length === 1) {
+ var c = this._inputField.container();
+ if (bool && !this._active) {
+ c.classList.add('active');
+ this._active = true;
+ }
+ else {
+ c.classList.remove('active');
+ this._active = false;
+ }
+ };
+ return this._active;
+ },
+
/**
* Show the menu.
@@ -178,20 +223,30 @@
show : function (ifContext) {
// Menu is already active
- if (this.active)
- return;
+ if (this.active()) {
+
+ // Alert is not active
+ if (!this._alert.unshow())
+ return;
+ };
// Get the menu
var menu;
if (menu = this.contextMenu(ifContext)) {
var c = this._inputField.container();
- c.classList.add('active');
+ this.active(true);
+ // c.classList.add('active');
c.appendChild(menu.element());
menu.show();
menu.focus();
// Focus on input field
// this.inputField.element.focus();
};
+ },
+
+ unshow : function () {
+ this.active(false);
+ this.inputField().element().focus();
}
};
});