Skip to content

Commit

Permalink
Fix bug when checking root jsonOnPath wont work
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxlufs committed May 8, 2015
1 parent d6958ad commit 3eb196c
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 53 deletions.
17 changes: 11 additions & 6 deletions dist/jsoneditor.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@

.jsoneditor {
color: #1A1A1A;
border: 1px solid #1bb9ec;
border: 1px solid #aaa;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
Expand Down Expand Up @@ -215,6 +215,11 @@
font-size: 10pt;
color: #1A1A1A;
}

.jsoneditor td:nth-child(2) {
text-align: center;
vertical-align: middle;
}
/* ContextMenu - main menu */

.jsoneditor-contextmenu {
Expand Down Expand Up @@ -452,8 +457,8 @@
-webkit-box-sizing: border-box;
box-sizing: border-box;
color: #1A1A1A;
background-color: #00384A;
border-bottom: 1px solid #1bb9ec;
background: linear-gradient(to bottom right, #080808, #494949);
border-bottom: 1px solid #aaa;
}

.jsoneditor .menu button {
Expand All @@ -462,8 +467,8 @@
margin: 2px;
padding: 0;
border-radius: 2px;
border: 1px solid #aec0f8;
background: #e3eaf6 url("img/jsoneditor-icons.png");
border: 1px solid #aaa;
background: #bbb url("img/jsoneditor-icons.png");
color: #4D4D4D;
opacity: 0.8;
font-family: arial, sans-serif;
Expand All @@ -472,7 +477,7 @@
}

.jsoneditor .menu button:hover {
background-color: #f0f2f5;
background-color: #ddd;
}

.jsoneditor .menu button:focus,
Expand Down
42 changes: 29 additions & 13 deletions dist/jsoneditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ return /******/ (function(modules) { // webpackBootstrap


if (node.dom.checkbox.checked) { // if checking the checkbox
console.log(node.jsonOnPath())
console.log(node.jsonOnPath());
this.checked = util.deepExtend(this.checked, node.jsonOnPath());
} else {
var path = node.path();
Expand Down Expand Up @@ -1695,19 +1695,35 @@ return /******/ (function(modules) { // webpackBootstrap
return a;
};

exports.deepExtend = function(destination, source) {
for (var property in source) {
if (source[property] && source[property].constructor &&
source[property].constructor === Object) {
destination[property] = destination[property] || {};
arguments.callee(destination[property], source[property]);
} else {
destination[property] = source[property];
exports.deepExtend = function deepExtend(destination, source) {
for (var property in source) {
if (source[property] && source[property].constructor &&
source[property].constructor === Object) {
destination[property] = destination[property] || {};
arguments.callee(destination[property], source[property]);
} else if (source[property] && source[property].constructor && source[property].constructor === Array) {
destination[property] = destination[property] || [];
arguments.callee(destination[property], source[property]);
} else {
destination[property] = source[property];
}
}
}
return destination;
return destination;
};

//var x = {
//data: [
//[null, null, 3]
//]
//};
//var y = {
//data: [
//[null, 2]
//]
//};
//exports.deepExtend(x, y);
//console.log(x);

/**
* delete a property in an object with a given path
* @param {Object} obj
Expand All @@ -1720,7 +1736,6 @@ return /******/ (function(modules) { // webpackBootstrap
var path = arguments[1];
// path

//console.log(path);
// when root is unchecked, set treemode.checked to {}
if (path.length === 0) return {};

Expand Down Expand Up @@ -2899,6 +2914,8 @@ return /******/ (function(modules) { // webpackBootstrap
root = [];
else if(typeof path[0] === "string")
root = {};
else if(typeof path[0] === "undefined") // check on root node
return this.getValue();

var curr = root;
var currKey,nextKey;
Expand All @@ -2915,7 +2932,6 @@ return /******/ (function(modules) { // webpackBootstrap
curr = curr[currKey];
}


return root;
};

Expand Down
2 changes: 1 addition & 1 deletion dist/jsoneditor.min.css

Large diffs are not rendered by default.

35 changes: 21 additions & 14 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
var outputJson = {};
var inputEditor = new JSONEditor(inputContainer, {
mode: "tree",
modes: ["tree", "code", "view", "form"], // menu
change: function() {},
error: function() {
console.log("error!")
Expand Down Expand Up @@ -54,8 +53,16 @@
"width": 800,
"height": 500,
"grid": {
header: {},
body: {}
header: {
title: "ZingGrid",
subTitle: "subtitle goes here",
menuBar: true
},
body: {
column: {
width: 50
}
}
},
};
inputEditor.set(json);
Expand All @@ -72,18 +79,18 @@


// House cleaning extra dummy dom elements
Array.prototype.forEach.call(
document.querySelectorAll('textarea'),
function(extraNode) {
extraNode.parentNode.removeChild(extraNode)
});
Array.prototype.forEach.call(
document.querySelectorAll('div[class^="zg-load-mask"]'),
function(extraNode) {
extraNode.parentNode.removeChild(extraNode)
});
//Array.prototype.forEach.call(
// document.querySelectorAll('textarea'),
// function(extraNode) {
// extraNode.parentNode.removeChild(extraNode)
// });
//Array.prototype.forEach.call(
// document.querySelectorAll('div[class^="zg-load-mask"]'),
// function(extraNode) {
// extraNode.parentNode.removeChild(extraNode)
// });

//zinggrid.render(outputJson);
zinggrid.render(outputJson);

});
})
Expand Down
7 changes: 6 additions & 1 deletion src/css/jsoneditor.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@

.jsoneditor {
color: #1A1A1A;
border: 1px solid #1bb9ec;
border: 1px solid #aaa;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
Expand Down Expand Up @@ -221,3 +221,8 @@
font-size: 10pt;
color: #1A1A1A;
}

.jsoneditor td:nth-child(2) {
text-align: center;
vertical-align: middle;
}
10 changes: 5 additions & 5 deletions src/css/menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
box-sizing: border-box;

color: #1A1A1A;
background-color: #00384A;
border-bottom: 1px solid #1bb9ec;
background: linear-gradient(to bottom right, #080808, #494949);
border-bottom: 1px solid #aaa;
}

.jsoneditor .menu button {
Expand All @@ -20,8 +20,8 @@
margin: 2px;
padding: 0;
border-radius: 2px;
border: 1px solid #aec0f8;
background: #e3eaf6 url('img/jsoneditor-icons.png');
border: 1px solid #aaa;
background: #bbb url('img/jsoneditor-icons.png');
color: #4D4D4D;
opacity: 0.8;

Expand All @@ -32,7 +32,7 @@
}

.jsoneditor .menu button:hover {
background-color: #f0f2f5;
background-color: #ddd;
}
.jsoneditor .menu button:focus,
.jsoneditor .menu button:active {
Expand Down
3 changes: 2 additions & 1 deletion src/js/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ Node.prototype.jsonOnPath = function () {
root = [];
else if(typeof path[0] === "string")
root = {};
else if(typeof path[0] === "undefined") // check on root node
return this.getValue();

var curr = root;
var currKey,nextKey;
Expand All @@ -105,7 +107,6 @@ Node.prototype.jsonOnPath = function () {
curr = curr[currKey];
}


return root;
};

Expand Down
2 changes: 1 addition & 1 deletion src/js/treemode.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ treemode.setChecked = function (node) {


if (node.dom.checkbox.checked) { // if checking the checkbox
console.log(node.jsonOnPath())
console.log(node.jsonOnPath());
this.checked = util.deepExtend(this.checked, node.jsonOnPath());
} else {
var path = node.path();
Expand Down
37 changes: 26 additions & 11 deletions src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,35 @@ exports.extend = function extend(a, b) {
return a;
};

exports.deepExtend = function(destination, source) {
for (var property in source) {
if (source[property] && source[property].constructor &&
source[property].constructor === Object) {
destination[property] = destination[property] || {};
arguments.callee(destination[property], source[property]);
} else {
destination[property] = source[property];
exports.deepExtend = function deepExtend(destination, source) {
for (var property in source) {
if (source[property] && source[property].constructor &&
source[property].constructor === Object) {
destination[property] = destination[property] || {};
arguments.callee(destination[property], source[property]);
} else if (source[property] && source[property].constructor && source[property].constructor === Array) {
destination[property] = destination[property] || [];
arguments.callee(destination[property], source[property]);
} else {
destination[property] = source[property];
}
}
}
return destination;
return destination;
};

//var x = {
//data: [
//[null, null, 3]
//]
//};
//var y = {
//data: [
//[null, 2]
//]
//};
//exports.deepExtend(x, y);
//console.log(x);

/**
* delete a property in an object with a given path
* @param {Object} obj
Expand All @@ -203,7 +219,6 @@ exports.deepDelete = function (obj /*, path*/ ) {
var path = arguments[1];
// path

//console.log(path);
// when root is unchecked, set treemode.checked to {}
if (path.length === 0) return {};

Expand Down

0 comments on commit 3eb196c

Please sign in to comment.