Improve status codes and support HTML match responses

Change-Id: Ie11b68eb0836bb537a2869b87e78f3a695203e11
diff --git a/dev/js/src/init.js b/dev/js/src/init.js
index 478f87e..62d0800 100644
--- a/dev/js/src/init.js
+++ b/dev/js/src/init.js
@@ -141,39 +141,53 @@
     /**
      * Add actions to match entries
      */
-    var inactiveLi = d.querySelectorAll(
-      '#search > ol > li:not(.active)'
+    var li = d.querySelectorAll(
+      '#search > ol > li'
     );
     var matchCount = 0;
 
-    for (matchCount = 0; matchCount < inactiveLi.length; matchCount++) {
-      inactiveLi[matchCount].addEventListener('click', function (e) {
-        if (this._match !== undefined)
-          this._match.open();
-        else {
+    for (matchCount = 0; matchCount < li.length; matchCount++) {
+
+      let e = li[matchCount];
+
+      // Define class for active elements
+      if (e.classList.contains('active')) {
+        if (this._match === undefined) {
           // lazyLoad
-          matchClass.create(this).open();
+          matchClass.create(e).init();
         };
-        // This would prevent the sidebar to go back
-        // e.halt();
-      });
-      inactiveLi[matchCount].addEventListener('keydown', function (e) {
-        var code = _codeFromEvent(e);
-        
-        switch (code) {
-        case 32:
+      }
+
+      // Define class for inactive elements
+      else {
+        e.addEventListener('click', function (e) {
           if (this._match !== undefined)
-            this._match.toggle();
+            this._match.open();
           else {
             // lazyLoad
             matchClass.create(this).open();
           };
-          e.halt();
-          break;
-        };
-      });
+          // This would prevent the sidebar to go back
+          // e.halt();
+        });
+        e.addEventListener('keydown', function (e) {
+          var code = _codeFromEvent(e);
+          
+          switch (code) {
+          case 32:
+            if (this._match !== undefined)
+              this._match.toggle();
+            else {
+              // lazyLoad
+              matchClass.create(this).open();
+            };
+            e.halt();
+            break;
+          };
+        });
+      };
     };
-
+    
     // Add focus listener to aside
     var aside = d.getElementsByTagName('aside')[0];
 
diff --git a/dev/js/src/match.js b/dev/js/src/match.js
index 3c44656..f38a68a 100644
--- a/dev/js/src/match.js
+++ b/dev/js/src/match.js
@@ -137,6 +137,44 @@
       return this._avail.rels;
     },
 
+    /**
+     * Initialize match
+     */
+    init : function () {
+      if (this._initialized)
+        return this;
+
+      // Add actions unless it's already activated
+      var element = this._element;
+
+      // There is an element to open
+      if (element === undefined || element === null)
+        return undefined;
+      
+      // Add meta button
+      var refLine = element.querySelector("p.ref");
+
+      // No reference found
+      if (!refLine)
+        return undefined;
+
+      // Create panel
+      this.panel = matchPanelClass.create(this);
+
+      this._element.insertBefore(
+        this.panel.element(),
+        this._element.querySelector("p.ref")
+      );
+
+      // Insert before reference line
+      refLine.insertBefore(
+        this.panel.actions.element(),
+        refLine.firstChild
+      );
+
+      this._initialized = true;
+      return this;
+    },
 
     /**
      * Open match
@@ -157,14 +195,6 @@
       // Add active class to element
       element.classList.add('active');
 
-      // Already there
-      /*
-        if (element.classList.contains('action'))
-        return true;
-      */
-      if (this._initialized)
-        return true;
-      
       var btn = buttonGroupClass.create(
         ['action','button-view']
       );
@@ -174,29 +204,10 @@
         that.minimize();
       });
       element.appendChild(btn.element());
-
-      // Add meta button
-      var refLine = element.querySelector("p.ref");
-
-      // No reference found
-      if (!refLine)
-        return;
-
-      // Create panel
-      this.panel = matchPanelClass.create(this);
-
-      this._element.insertBefore(
-        this.panel.element(),
-        this._element.querySelector("p.ref")
-      );
-
-      // Insert before reference line
-      refLine.insertBefore(
-        this.panel.actions.element(),
-        refLine.firstChild
-      );
-
-      this._initialized = true;
+      
+      if (this.init() == undefined) {
+        return false;
+      };
       
       return true;
     },