Move token view to match
Change-Id: I24ae6d8b40509d976be7ff222b983aae5b66fe1e
diff --git a/dev/js/spec/matchSpec.js b/dev/js/spec/matchSpec.js
index 8df6e86..4553d97 100644
--- a/dev/js/spec/matchSpec.js
+++ b/dev/js/spec/matchSpec.js
@@ -94,6 +94,7 @@
" </span>" +
" </span>" +
"</span>" +
+ "<mark>" +
"<span title=\"cnx/l:deutlich\">" +
" <span title=\"cnx/p:A\">" +
" <span title=\"cnx/syn:@PREMOD\">" +
@@ -107,6 +108,7 @@
" </span>" +
" </span>" +
"</span>" +
+ "</mark>" +
"<span title=\"cnx/l:fähig\">" +
" <span title=\"cnx/l:leistung\">" +
" <span title=\"cnx/p:A\">" +
@@ -485,8 +487,11 @@
expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
expect(tr.children[2].firstChild.nodeValue).toBe('meist');
+ expect(tr.children[2].classList.contains('mark')).toBeFalsy();
expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
+ expect(tr.children[3].classList.contains('mark')).toBeTruthy();
expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
+ expect(tr.children[4].classList.contains('mark')).toBeFalsy();
// first row
tr = e.children[1].children[0];
diff --git a/dev/js/src/match/table.js b/dev/js/src/match/table.js
index 969de77..1544637 100644
--- a/dev/js/src/match/table.js
+++ b/dev/js/src/match/table.js
@@ -33,12 +33,14 @@
this._pos = 0;
this._token = [];
+ this._mark = [];
+ this._markE = undefined;
this._info = [];
this._foundry = {};
this._layer = {};
// Parse the snippet
- this._parse(html.childNodes);
+ this._parse(html.childNodes, false);
html.innerHTML = '';
return this;
@@ -58,6 +60,19 @@
return this._pos;
},
+
+ /**
+ * Move the viewport to the match
+ */
+ toMark : function () {
+ if (this._markE === undefined)
+ return;
+ this._markE.scrollIntoView({
+ inline: "start",
+ block: "nearest"
+ });
+ },
+
/**
* Get the token in the snippet
* At a given position.
@@ -85,7 +100,7 @@
// Parse the snippet
- _parse : function (children) {
+ _parse : function (children, mark) {
// Get all children
for (var i in children) {
@@ -101,7 +116,13 @@
// Element with title
if (c.nodeType === 1) {
- if (c.getAttribute("title") &&
+ var newMark = mark;
+
+ if (c.tagName === 'MARK') {
+ newMark = true;
+ }
+
+ else if (c.getAttribute("title") &&
_TermRE.exec(c.getAttribute("title"))) {
// Fill position with info
@@ -141,14 +162,16 @@
// depth search
if (c.hasChildNodes())
- this._parse(c.childNodes);
+ this._parse(c.childNodes, newMark);
}
// Leaf node
// store string on position and go to next string
else if (c.nodeType === 3) {
- if (c.nodeValue.match(/[a-z0-9]/i))
+ if (c.nodeValue.match(/[a-z0-9]/i)) {
+ this._mark[this._pos] = mark ? true : false;
this._token[this._pos++] = c.nodeValue;
+ };
};
};
@@ -221,7 +244,13 @@
// Add tokens
for (var i in this._token) {
- tr.addCell('th', undefined, this.getToken(i));
+ var c = tr.addCell('th', undefined, this.getToken(i));
+ if (this._mark[i]) {
+ c.classList.add('mark');
+ if (this._markE === undefined) {
+ this._markE = c;
+ };
+ };
};
var tbody = table.addE('tbody');
@@ -255,6 +284,10 @@
key,
value
);
+
+ if (this._mark[v]) {
+ cell.classList.add('mark');
+ };
};
};
};
diff --git a/dev/js/src/view/match/tokentable.js b/dev/js/src/view/match/tokentable.js
index f0d2fd2..2ac361d 100644
--- a/dev/js/src/view/match/tokentable.js
+++ b/dev/js/src/view/match/tokentable.js
@@ -27,29 +27,36 @@
// Append default table
var matchtable = d.createElement('div');
matchtable.classList.add('matchtable', 'loading');
+ this._show = matchtable;
+ return matchtable;
+ },
- var that = this;
-
+ /**
+ * Do after embedding
+ */
+ afterEmbed : function () {
// TODO:
// Create try-catch-exception-handling
-
- // Create the table asynchronous
- this.getData(undefined, function (table) {
-
- // Load data
- matchtable.classList.remove('loading');
-
- if (table !== null) {
- matchtable.appendChild(table.element());
- };
- });
// TODO:
// Loading should have a timeout on view-level
// matchtable.classList.remove('loading');
-
- this._show = matchtable;
- return matchtable;
+
+ // var that = this;
+ var matchtable = this._show;
+
+ // Create the table asynchronous
+ this.getData(undefined, function (table) {
+
+ if (table !== null) {
+ matchtable.appendChild(table.element());
+ table.toMark();
+ };
+
+ });
+
+ // Load data
+ matchtable.classList.remove('loading');
},