Skip to content

Commit

Permalink
added sloppy object functionality
Browse files Browse the repository at this point in the history
added todo's
added minimal classes
  • Loading branch information
PhilipReasa committed Aug 26, 2013
1 parent 5e7f13d commit fad236b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
32 changes: 11 additions & 21 deletions collapse.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
// modified from JSONviewer
// jsonview.com

// 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() {
// Click handler for collapsing and expanding objects and arrays
function collapse(evt) {
var collapser = evt.target;
// Click handler for collapsing and expanding objects and arrays
function collapse(evt) {
var collapser = evt.target;

var target = collapser.parentNode.getElementsByClassName('collapsible');
var target = collapser.parentNode.getElementsByClassName('collapsible');

if ( ! target.length ) {
if ( ! target.length ) {
return;
}

target = target[0];

if ( target.style.display == 'none' ) {
var ellipsis = target.parentNode.getElementsByClassName('ellipsis')[0];
target.parentNode.removeChild(ellipsis);
target.style.display = '';
collapser.innerHTML = '-';
} else {
target.style.display = 'none';

var ellipsis = document.createElement('span');
ellipsis.className = 'ellipsis';
ellipsis.innerHTML = ' … ';
target.parentNode.insertBefore(ellipsis, target);
collapser.innerHTML = '+';
}
}
}

function addCollapser(item) {
function addCollapser(item) {
// This mainly filters out the root object (which shouldn't be collapsible)
if ( item.nodeName != 'LI' ) {
return;
Expand All @@ -42,10 +33,9 @@ document.addEventListener('DOMContentLoaded', function() {
collapser.innerHTML = '-';
collapser.addEventListener('click', collapse, false);
item.insertBefore(collapser, item.firstChild);
}
}

var items = document.getElementsByClassName('collapsible');
for( var i = 0; i < items.length; i++) {
var items = document.getElementsByClassName('collapsible');
for( var i = 0; i < items.length; i++) {
addCollapser(items[i].parentNode);
}
}, false);
}
21 changes: 11 additions & 10 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function ContentItem(data, caller) {
closingQ = data.indexOf("\"", openingQ + 1),
openingP = data.indexOf("("),
closingP = data.indexOf(")");

//TODO: make sure that (, ) dont appear inside quotes

//http://www.php.net/manual/en/language.types.intro.php
//check primitive scalar types
if (data.substring(0, 4) == "bool") {
Expand Down Expand Up @@ -42,9 +43,9 @@ function ContentItem(data, caller) {
this.compound = true;
this.extraInfo.push("Number of Elements: " + data.substring(6, closingP));
} else if (data.substring(0, 6) == "object") {
this.type = "object { ";
this.type = "object";
this.compound = true;
this.html = data.substring(8, data.length);
this.html = data.substring(6, data.length);
//TODO: Don't think this is complete
}

Expand Down Expand Up @@ -75,28 +76,28 @@ ContentItem.prototype.printOpening = function () {
switch(this.type) {
case "object":
if(this.node.parent.content.compound) {toPrint += '<li>';}
toPrint += "<ul class='obj collapible'>"
toPrint += "<ul class='obj collapsible'>" + this.html;
break;
case "array":
if(this.node.parent.content.compound) {toPrint += '<li>';}
toPrint += "<ul class='array collapible'>" + this.html + "[" + this.extraInfo[0] + "]";
toPrint += "<ul class='array collapsible'>" + this.html + "[" + this.extraInfo[0] + "]";
break;
case "integer":
case "float":
toPrint += "<span class='type-number'>" + this.html + "</span>";
toPrint += "<span class='num'>" + this.html + "</span>";
break;
case "bool":
toPrint += "<span class='type-boolean'>" + this.html + "</span>";
toPrint += "<span class='bool'>" + this.html + "</span>";
break;
case "string":
toPrint += "<span class='type-string'>" + this.html + "</span>";
toPrint += "<span class='string'>" + this.html + "</span>";
break;
case "NULL":
toPrint += "<span class='type-bull'>" + this.html + "</span>";
toPrint += "<span class='null'>" + this.html + "</span>";
break;
case "key":
if(this.node.parent.content.compound) {toPrint += '<li>';}
toPrint += "<span class='property'>" + this.html + "</span>";
toPrint += "<span class='prop'>" + this.html + "</span>";

break;
default:
Expand Down
1 change: 1 addition & 0 deletions textParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function generateTheTree(dump, parent) {
}

function whereDoesLevelClose(dump, i) {
//TODO: make sure {, } dont appear inside quotes
i ++;
var numOfOParens = 0;
while(i < dump.length) {
Expand Down

0 comments on commit fad236b

Please sign in to comment.