// This used to use jQuery, but was rewritten in plan DOM for speed and to get rid of the jQuery dependency.
document.addEventListener('DOMContentLoaded', function() {
  "use strict";

  // Click handler for collapsing and expanding objects and arrays
  function collapse(evt) {
    var collapser = evt.target;

    while (collapser && (!collapser.classList || !collapser.classList.contains('collapser'))) {
      collapser = collapser.nextSibling;
    }
    if (!collapser || !collapser.classList || !collapser.classList.contains('collapser')) {
      return;
    }

    evt.stopPropagation();

    collapser.classList.toggle('collapsed');

    var collapsible = collapser;
    while (collapsible && (!collapsible.classList || !collapsible.classList.contains('collapsible'))) {
      collapsible = collapsible.nextSibling;
    }
    collapsible.classList.toggle('collapsed');
  }

  /*
   * Collapses the whole json using keyboard
   * TODO: Add a navigator support for each of the elements
   */
  function collapseAll(evt) {
    var inputList = document.getElementsByClassName('collapser');
    if (evt.keyCode === 37) {  // Collapses the json on left arrow key up
      for (var i = 0; i < inputList.length; i++) {
        inputList[i].nextElementSibling.classList.add('collapsed');
      }
    } else if (evt.keyCode === 39) { // Expands the json on right arrow key up
      for (var i = 0; i < inputList.length; i++) {
        inputList[i].nextElementSibling.classList.remove('collapsed');
      }
    } 
  }
  
  // collapse with event delegation
  document.addEventListener('click', collapse, false);
  document.addEventListener('keyup', collapseAll, false);
}, false);


@@ -1042,56 +1042,10 @@
 List
- = document.getElementsByClassName('collapser')
 ;
+%0A
 %0A   
@@ -1107,32 +1107,105 @@
 ft arrow key up%0A
+      inputList = document.querySelectorAll('.collapsible, .collapser');%0A
       for (var i
@@ -1239,32 +1239,36 @@
  i++) %7B%0A        
+if (
 inputList%5Bi%5D.nex
@@ -1264,34 +1264,65 @@
 List%5Bi%5D.
-nextElementSibling
+parentNode.id != 'json') %7B%0A          inputList%5Bi%5D
 .classLi
@@ -1334,32 +1334,42 @@
 d('collapsed');%0A
+        %7D%0A
       %7D%0A    %7D el
@@ -1435,24 +1435,83 @@
 rrow key up%0A
+      inputList = document.querySelectorAll('.collapsed');%0A
       for (v
@@ -1574,27 +1574,8 @@
 %5Bi%5D.
-nextElementSibling.
 clas
@@ -1618,16 +1618,13 @@
    %7D
- 
 %0A  %7D%0A
-  
 %0A  /
@@ -1780,9 +1780,8 @@
 false);%0A
-%0A

Clean up expand/collapse code.