Release preparation, documentation, fixing vc bugs
diff --git a/dev/js/src/hint/contextanalyzer.js b/dev/js/src/hint/contextanalyzer.js
index bdbf885..fc01662 100644
--- a/dev/js/src/hint/contextanalyzer.js
+++ b/dev/js/src/hint/contextanalyzer.js
@@ -2,9 +2,15 @@
* Regex object for checking the context of the hint
*/
define({
+
+ /**
+ * Create analyzer based on regular expression.
+ */
create : function (regex) {
return Object.create(this)._init(regex);
},
+
+ // Initialize analyzer
_init : function (regex) {
try {
this._regex = new RegExp(regex);
@@ -15,6 +21,11 @@
};
return this;
},
+
+ /**
+ * Check a context based on the analyzer
+ * and return a valid context string.
+ */
test : function (text) {
if (!this._regex.exec(text))
return;
diff --git a/dev/js/src/hint/input.js b/dev/js/src/hint/input.js
index b1c6632..c12d26a 100644
--- a/dev/js/src/hint/input.js
+++ b/dev/js/src/hint/input.js
@@ -1,9 +1,14 @@
// Input field for queries
define({
+
+ /**
+ * Create a new input field.
+ */
create : function (element) {
return Object.create(this)._init(element);
},
-
+
+ // Initialize new input field
_init : function (element) {
this._element = element;
@@ -29,34 +34,62 @@
return this;
},
- rightPos : function () {
+ // Get the right position
+ _rightPos : function () {
var box = this._mirror.firstChild.getBoundingClientRect();
return box.right - box.left;
},
+ /**
+ * Get the mirrored input field.
+ */
mirror : function () {
return this._mirror;
},
+
+ /**
+ * Get the container element.
+ * This contains the mirror and
+ * the hint helper.
+ */
container : function () {
return this._container;
},
+
+ /**
+ * Get the input element the
+ * hint helper is attached to.
+ */
element : function () {
return this._element;
},
+ /**
+ * Get the value of the input field
+ * the hint helper is attached to.
+ */
value : function () {
return this._element.value;
},
+
+ /**
+ * Update the mirror content.
+ */
update : function () {
- this._mirror.firstChild.textContent = this.split()[0];
- this._container.style.left = this.rightPos() + 'px';
+ this._mirror.firstChild.textContent = this._split()[0];
+ this._container.style.left = this._rightPos() + 'px';
},
+ /**
+ * Insert text into the mirror.
+ * This is a prefix of the input field's
+ * value.
+ */
insert : function (text) {
- var splittedText = this.split();
+ var splittedText = this._split();
var s = this._element;
s.value = splittedText[0] + text + splittedText[1];
s.selectionStart = (splittedText[0] + text).length;
@@ -64,18 +97,11 @@
this._mirror.firstChild.textContent = splittedText[0] + text;
},
- // Return two substrings, splitted at current cursor position
- split : function () {
- var s = this._element;
- var value = s.value;
- var start = s.selectionStart;
- return new Array(
- value.substring(0, start),
- value.substring(start, value.length)
- );
- },
- // Position the input mirror directly below the input box
+ /**
+ * Reposition the input mirror directly
+ * below the input box.
+ */
reposition : function () {
var inputClientRect = this._element.getBoundingClientRect();
var inputStyle = window.getComputedStyle(this._element, null);
@@ -97,7 +123,27 @@
mirrorStyle.fontSize = inputStyle.getPropertyValue("font-size");
mirrorStyle.fontFamily = inputStyle.getPropertyValue("font-family");
},
+
+ /**
+ * Get the context, which is the input
+ * field's value bounded to the
+ * cursor position.
+ */
context : function () {
- return this.split()[0];
+ return this._split()[0];
+ },
+
+ /*
+ * Return two substrings,
+ * splitted at the current cursor position.
+ */
+ _split : function () {
+ var s = this._element;
+ var value = s.value;
+ var 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 4b879f8..b9a1bc8 100644
--- a/dev/js/src/hint/item.js
+++ b/dev/js/src/hint/item.js
@@ -3,12 +3,17 @@
*/
define(['menu/item'], function (itemClass) {
return {
+
+ /**
+ * Create new menu item object.
+ */
create : function (params) {
return Object.create(itemClass)
.upgradeTo(this)
._init(params);
},
+ // Initialize menu item object
_init : function (params) {
if (params[0] === undefined ||
params[1] === undefined)
@@ -26,13 +31,20 @@
return this;
},
+ /**
+ * Get or set the content of the item.
+ */
content : function (content) {
if (arguments.length === 1) {
this._content = content;
};
return this._content;
},
-
+
+ /**
+ * Override the click action
+ * of the menu item.
+ */
onclick : function (e) {
var m = this.menu();
var h = m.hint();
@@ -50,15 +62,32 @@
h.show(true);
},
+ /**
+ * The name of the menu entry.
+ */
name : function () {
return this._name;
},
+
+ /**
+ * The action (the string inserted on click)
+ * of the menu item.
+ */
action : function () {
return this._action;
},
+
+ /**
+ * The description of the menu item.
+ */
desc : function () {
return this._desc;
},
+
+ /**
+ * The associated dom element of the
+ * menu item.
+ */
element : function () {
// already defined
if (this._element !== undefined)
diff --git a/dev/js/src/hint/menu.js b/dev/js/src/hint/menu.js
index c579945..bf965d7 100644
--- a/dev/js/src/hint/menu.js
+++ b/dev/js/src/hint/menu.js
@@ -3,6 +3,10 @@
*/
define(['menu', 'hint/item', 'hint/prefix'], function (menuClass, itemClass, prefixClass) {
return {
+
+ /**
+ * Create new hint helper menu.
+ */
create : function (hint, context, params) {
var obj = Object.create(menuClass)
.upgradeTo(this)
@@ -25,10 +29,11 @@
return obj;
},
- // Todo: Is this necessary?
- context : function () {
- return this._context;
- },
+
+ /**
+ * The hint helper object,
+ * the menu is attached to.
+ */
hint : function () {
return this._hint;
}
diff --git a/dev/js/src/hint/prefix.js b/dev/js/src/hint/prefix.js
index 84f785a..7586617 100644
--- a/dev/js/src/hint/prefix.js
+++ b/dev/js/src/hint/prefix.js
@@ -1,8 +1,17 @@
define(['menu/prefix'], function (prefixClass) {
return {
+
+ /**
+ * Create prefix object for the hint helper menu.
+ */
create : function (params) {
- return Object.create(prefixClass).upgradeTo(this)._init(params);
+ return Object.create(prefixClass).
+ upgradeTo(this)._init(params);
},
+
+ /**
+ * Override the prefix action.
+ */
onclick : function () {
var m = this.menu();
var h = m.hint();