Move token view to match

Change-Id: I24ae6d8b40509d976be7ff222b983aae5b66fe1e
diff --git a/dev/demo/matchdemo.js b/dev/demo/matchdemo.js
index 3c4bf0e..f7fd779 100644
--- a/dev/demo/matchdemo.js
+++ b/dev/demo/matchdemo.js
@@ -49,6 +49,395 @@
   "  </span>" +
   "</span>";
 
+  snippet = "<span class=\"context-left\"></span>" +
+  "<span class=\"match\">"+
+  " <span title=\"corenlp\/p:KOUI\">"+
+  "  <span title=\"marmot\/p:KOUI\">"+
+  "   <span title=\"opennlp\/p:KOUI\">"+
+  "    <span title=\"tt\/l:um\">"+
+  "     <span title=\"tt\/l:um\">"+
+  "      <span title=\"tt\/p:APPR\">"+
+  "      <span title=\"tt\/p:KOUI\">Um</span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>"+
+  "  " +
+  " <span title=\"corenlp\/p:ART\">"+
+  "  <span title=\"marmot\/m:case:acc\">"+
+  "   <span title=\"marmot\/m:gender:masc\">"+
+  "    <span title=\"marmot\/m:number:pl\">"+
+  "     <span title=\"marmot\/p:ART\">"+
+  "      <span title=\"opennlp\/p:ART\">"+
+  "       <span title=\"tt\/l:die\">" +
+  "       <span title=\"tt\/p:ART\">die</span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:APPR\">"+
+  "  <span title=\"marmot\/p:APPR\">"+
+  "   <span title=\"opennlp\/p:APPR\">"+
+  "    <span title=\"tt\/l:von\">"+
+  "    <span title=\"tt\/p:APPR\">von</span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:PPOSAT\">"+
+  "  <span title=\"marmot\/m:case:dat\">"+
+  "   <span title=\"marmot\/m:gender:masc\">"+
+  "    <span title=\"marmot\/m:number:sg\">"+
+  "     <span title=\"marmot\/p:PPOSAT\">"+
+  "      <span title=\"opennlp\/p:PPOSAT\">"+
+  "       <span title=\"tt\/l:sein\">"+
+  "       <span title=\"tt\/p:PPOSAT\">seinem</span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:NN\">"+
+  "  <span title=\"marmot\/m:case:dat\">"+
+  "   <span title=\"marmot\/m:gender:masc\">"+
+  "    <span title=\"marmot\/m:number:sg\">"+
+  "     <span title=\"marmot\/p:NN\">"+
+  "      <span title=\"opennlp\/p:NN\">"+
+  "       <span title=\"tt\/l:Großvater\">"+
+  "       <span title=\"tt\/p:NN\">Großvater</span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:ADJA\">" +
+  "  <span title=\"marmot\/m:case:acc\">" +
+  "   <span title=\"marmot\/m:degree:pos\">" +
+  "    <span title=\"marmot\/m:gender:fem\">" +
+  "     <span title=\"marmot\/m:number:sg\">" +
+  "      <span title=\"marmot\/p:ADJA\">" +
+  "       <span title=\"opennlp\/p:ADJA\">" +
+  "        <span title=\"tt\/l:gepflanzt\">" +
+  "        <span title=\"tt\/p:ADJA\">gepflanzte</span>" +
+  "        </span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:NN\">" +
+  "  <span title=\"marmot\/m:case:acc\">" +
+  "   <span title=\"marmot\/m:gender:fem\">" +
+  "    <span title=\"marmot\/m:number:sg\">" +
+  "     <span title=\"marmot\/p:NN\">" +
+  "      <span title=\"opennlp\/p:NN\">" +
+  "       <span title=\"tt\/l:Esche\">" +
+  "       <span title=\"tt\/p:NN\">Esche</span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:VAFIN\">" +
+  "  <span title=\"marmot\/m:mood:ind\">" +
+  "   <span title=\"marmot\/m:number:sg\">" +
+  "    <span title=\"marmot\/m:person:3\">" +
+  "     <span title=\"marmot\/m:tense:pres\">" +
+  "      <span title=\"marmot\/p:VAFIN\">" +
+  "       <span title=\"opennlp\/p:VAFIN\">" +
+  "        <span title=\"tt\/l:haben\">" +
+  "        <span title=\"tt\/p:VAFIN\">hat</span>" +
+  "        </span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:NE\">" +
+  "  <span title=\"marmot\/m:case:nom\">" +
+  "   <span title=\"marmot\/m:gender:*\">" +
+  "    <span title=\"marmot\/m:number:sg\">" +
+  "     <span title=\"marmot\/p:NE\">" +
+  "      <span title=\"opennlp\/p:NE\">" +
+  "       <span title=\"tt\/l:Behrens\">" +
+  "       <span title=\"tt\/p:NE\">Behrens</span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:APPR\">" +
+  "  <span title=\"marmot\/p:APPR\">" +
+  "   <span title=\"opennlp\/p:APPR\">" +
+  "    <span title=\"tt\/l:bei\">" +
+  "    <span title=\"tt\/p:APPR\">bei</span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:ART\">" +
+  "  <span title=\"marmot\/m:case:dat\">" +
+  "   <span title=\"marmot\/m:gender:fem\">" +
+  "    <span title=\"marmot\/m:number:sg\">" +
+  "     <span title=\"marmot\/p:ART\">" +
+  "      <span title=\"opennlp\/p:ART\">" +
+  "       <span title=\"tt\/l:die\">" +
+  "       <span title=\"tt\/p:ART\">der</span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:NN\">" +
+  "  <span title=\"marmot\/m:case:dat\">" +
+  "   <span title=\"marmot\/m:gender:fem\">" +
+  "    <span title=\"marmot\/m:number:sg\">" +
+  "     <span title=\"marmot\/p:NN\">" +
+  "      <span title=\"opennlp\/p:NN\">" +
+  "       <span title=\"tt\/l:Vergrößerung\">" +
+  "       <span title=\"tt\/p:NN\">Vergrößerung</span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:ART\">" +
+  "  <span title=\"marmot\/m:case:gen\">" +
+  "   <span title=\"marmot\/m:gender:neut\">" +
+  "    <span title=\"marmot\/m:number:sg\">" +
+  "     <span title=\"marmot\/p:ART\">" +
+  "      <span title=\"opennlp\/p:ART\">" +
+  "       <span title=\"tt\/l:die\">" +
+  "       <span title=\"tt\/p:ART\">des</span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:NN\">" +
+  "  <span title=\"marmot\/m:case:gen\">" +
+  "   <span title=\"marmot\/m:gender:neut\">" +
+  "    <span title=\"marmot\/m:number:sg\">" +
+  "     <span title=\"marmot\/p:NN\">" +
+  "      <span title=\"opennlp\/p:NN\">" +
+  "       <span title=\"tt\/l:Laden\">" +
+  "       <span title=\"tt\/p:NN\">Ladens</span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:ADV\">" +
+  "  <span title=\"marmot\/p:ADV\">" +
+  "   <span title=\"opennlp\/p:ADV\">" +
+  "    <span title=\"tt\/l:einfach\">" +
+  "    <span title=\"tt\/p:ADJD\">einfach</span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:VVPP\">" +
+  "  <span title=\"marmot\/p:VVPP\">" +
+  "   <span title=\"opennlp\/p:VVPP\">" +
+  "    <span title=\"tt\/l:herumbauen\">" +
+  "    <span title=\"tt\/p:VVPP\">herumgebaut</span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  " : " +
+  " <span title=\"corenlp\/p:ADV\">" +
+  "  <span title=\"marmot\/p:ADV\">" +
+  "   <span title=\"opennlp\/p:ADV\">" +
+  "    <span title=\"tt\/l:nun\">" +
+  "    <span title=\"tt\/p:ADV\">Nun</span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:VVFIN\">" +
+  "  <span title=\"marmot\/m:mood:ind\">" +
+  "   <span title=\"marmot\/m:number:sg\">" +
+  "    <span title=\"marmot\/m:person:3\">" +
+  "     <span title=\"marmot\/m:tense:pres\">" +
+  "      <span title=\"marmot\/p:VVFIN\">" +
+  "       <span title=\"opennlp\/p:VVFIN\">" +
+  "        <span title=\"tt\/l:stehen\">" +
+  "        <span title=\"tt\/p:VVFIN\">steht</span>" +
+  "        </span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <mark>" +
+  "  <span title=\"corenlp\/p:ART\">" +
+  "   <span title=\"marmot\/m:case:nom\">" +
+  "    <span title=\"marmot\/m:gender:masc\">" +
+  "     <span title=\"marmot\/m:number:sg\">" +
+  "      <span title=\"marmot\/p:ART\">" +
+  "       <span title=\"opennlp\/p:ART\">" +
+  "        <span title=\"tt\/l:die\">" +
+  "        <span title=\"tt\/p:ART\">der</span>" +
+  "        </span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  "   " +
+  "  <span title=\"corenlp\/p:ADJA\">" +
+  "   <span title=\"marmot\/m:case:nom\">" +
+  "    <span title=\"marmot\/m:degree:pos\">" +
+  "     <span title=\"marmot\/m:gender:masc\">" +
+  "      <span title=\"marmot\/m:number:sg\">" +
+  "       <span title=\"marmot\/p:ADJA\">" +
+  "        <span title=\"opennlp\/p:ADJA\">" +
+  "         <span title=\"tt\/l:alt\">" +
+  "         <span title=\"tt\/p:ADJA\">alte</span>" +
+  "         </span>" +
+  "        </span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  "   " +
+  "  <span title=\"corenlp\/p:NN\">" +
+  "   <span title=\"marmot\/m:case:nom\">" +
+  "    <span title=\"marmot\/m:gender:masc\">" +
+  "     <span title=\"marmot\/m:number:sg\">" +
+  "      <span title=\"marmot\/p:NN\">" +
+  "       <span title=\"opennlp\/p:NN\">" +
+  "        <span title=\"tt\/l:Baum\">" +
+  "        <span title=\"tt\/p:NN\">Baum</span>" +
+  "        </span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  "  " +
+  " </mark> <span title=\"corenlp\/p:ADV\">" +
+  "  <span title=\"marmot\/p:ADV\">" +
+  "   <span title=\"opennlp\/p:ADV\">" +
+  "    <span title=\"tt\/l:mitten\">" +
+  "    <span title=\"tt\/p:ADV\">mitten</span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:APPR\">" +
+  "  <span title=\"marmot\/p:APPR\">" +
+  "   <span title=\"opennlp\/p:APPR\">" +
+  "    <span title=\"tt\/l:in\">" +
+  "    <span title=\"tt\/p:APPR\">in</span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:ART\">" +
+  "  <span title=\"marmot\/m:case:dat\">" +
+  "   <span title=\"marmot\/m:gender:fem\">" +
+  "    <span title=\"marmot\/m:number:sg\">" +
+  "     <span title=\"marmot\/p:ART\">" +
+  "      <span title=\"opennlp\/p:ART\">" +
+  "       <span title=\"tt\/l:die\">" +
+  "       <span title=\"tt\/p:ART\">der</span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"marmot\/p:TRUNC\">" +
+  "  <span title=\"opennlp\/p:TRUNC\">" +
+  "   <span title=\"tt\/l:Obst-\">" +
+  "   <span title=\"tt\/p:TRUNC\">Obst-</span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:KON\">" +
+  "  <span title=\"marmot\/p:KON\">" +
+  "   <span title=\"opennlp\/p:KON\">" +
+  "    <span title=\"tt\/l:und\">" +
+  "    <span title=\"tt\/p:KON\">und</span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  "  " +
+  " <span title=\"corenlp\/p:NN\">" +
+  "  <span title=\"marmot\/m:case:gen\">" +
+  "   <span title=\"marmot\/m:gender:fem\">" +
+  "    <span title=\"marmot\/m:number:sg\">" +
+  "     <span title=\"marmot\/p:NN\">" +
+  "      <span title=\"opennlp\/p:NN\">" +
+  "       <span title=\"tt\/l:Gemüseabteilung\">" +
+  "       <span title=\"tt\/p:NN\">Gemüseabteilung</span>" +
+  "       </span>" +
+  "      </span>" +
+  "     </span>" +
+  "    </span>" +
+  "   </span>" +
+  "  </span>" +
+  " </span>" +
+  " ." +
+  "</span>" +
+  "<span class=\"context-right\">" +
+  "</span>";
+
   var treeSnippet =
   "<span class=\"context-left\"></span>" +
   "<span class=\"match\">" +
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');      
     },
 
 
diff --git a/dev/scss/main/matchinfo.scss b/dev/scss/main/matchinfo.scss
index 0d257a3..1f56fb0 100644
--- a/dev/scss/main/matchinfo.scss
+++ b/dev/scss/main/matchinfo.scss
@@ -116,6 +116,9 @@
       text-align: center;
       &:nth-of-type(1), &:nth-of-type(2) {
 	                        text-align: left;
+                        }
+      &.mark {
+        background-color: $darkest-orange; // #f6a800;
       }
     }
   }
@@ -152,10 +155,15 @@
     white-space: nowrap;
     vertical-align: top;
     text-align: center;
-
+    &.mark {
+      background-color: $light-orange;
+    }
   }
   tr:nth-child(even) > td {
     background-color: $light-orange;
+    &.mark {
+      background-color: $middle-orange;
+    }
   }
 
   // table for key-value pairs