diff --git a/README.md b/README.md
index d0a52f3..5e808b3 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
User friendly, visual JSON editor built as an AngularJS directive. Provides a basic GUI to edit JSON.
-**[Give it a try!](http://mb21.github.io/JSONedit)**
+**[Give it a try!](http://paridelpooya.github.io/JSONedit/)**
#### Use as Angular module
diff --git a/index.html b/index.html
index 9d98f02..293bdb8 100644
--- a/index.html
+++ b/index.html
@@ -18,13 +18,14 @@
JSONedit
-
+
JSON not well-formed!
+ btn
diff --git a/js/JSONedit.js b/js/JSONedit.js
index 1d08eff..8595733 100644
--- a/js/JSONedit.js
+++ b/js/JSONedit.js
@@ -6,7 +6,27 @@ function MainViewCtrl($scope, $filter) {
// example JSON
$scope.jsonData = {
- Name: "Joe", "Last Name": "Miller", Address: {Street: "Neverland 42"}, Hobbies: ["doing stuff", "dreaming"]
+ x:
+ {
+ x:
+ {
+ x:
+ {
+ x:
+ {
+ x:
+ {
+ x:[true,false,3,4,5]
+ }
+ }
+ }
+ }
+ },
+ Name: "Joe", "Last Name": "Miller", Address: { Street: "Neverland 42" }, Hobbies: ["doing stuff", "dreaming"]
+ };
+
+ $scope.showJsonString = function () {
+ alert($scope.jsonString);
};
$scope.$watch('jsonData', function(json) {
diff --git a/js/directives.js b/js/directives.js
index e52a7f6..7b07323 100644
--- a/js/directives.js
+++ b/js/directives.js
@@ -25,8 +25,12 @@ angular.module('JSONedit', ['ui.sortable'])
scope: {
child: '=',
type: '@',
- defaultCollapsed: '='
- },
+ expandedLevel: '=',
+ jsonAdd: '=',
+ jsonDelete: '=',
+ jsonChangeOrder: '=',
+ jsonChangeKey: '='
+ },
link: function(scope, element, attributes) {
var stringName = "Text";
var objectName = "Object";
@@ -38,10 +42,10 @@ angular.module('JSONedit', ['ui.sortable'])
scope.sortableOptions = {
axis: 'y'
};
- if (scope.$parent.defaultCollapsed === undefined) {
+ if (scope.$parent.expandedLevel === undefined) {
scope.collapsed = false;
} else {
- scope.collapsed = scope.defaultCollapsed;
+ scope.collapsed = scope.expandedLevel>0?false:true;
}
if (scope.collapsed) {
scope.chevron = "glyphicon-chevron-right";
@@ -155,8 +159,12 @@ angular.module('JSONedit', ['ui.sortable'])
console.error("object to add to was " + obj);
}
};
- scope.possibleNumber = function(val) {
- return isNumber(val) ? parseFloat(val) : val;
+
+ scope.possibleNumber = function (val,oldVal) {
+ if (typeof oldVal == "number")
+ return isNumber(val) ? parseFloat(val) : val;
+ else
+ return val;
};
//////
@@ -170,13 +178,13 @@ angular.module('JSONedit', ['ui.sortable'])
// recursion
var switchTemplate =
''
- + ' '
- + ' '
+ + ' '
+ + ' '
+ ''
+ ' '
+ ' '
+ ' '
+ + 'placeholder="Empty" ng-blur="child[key] = possibleNumber(val,child[key])"/>'
+ ' '
+ ' ';
@@ -185,9 +193,10 @@ angular.module('JSONedit', ['ui.sortable'])
''
+ '';
if (scope.type == "object"){
- // input key
- addItemTemplate += ' ';
+ // input key
+ addItemTemplate += ' ';
+
}
addItemTemplate +=
// value type dropdown
@@ -202,10 +211,11 @@ angular.module('JSONedit', ['ui.sortable'])
+ ' '
+ ''
// plus button
- + ' '
+ + ' '
+ ' '
+ '
';
+
// start template
if (scope.type == "object"){
var template = ' '
@@ -215,10 +225,10 @@ angular.module('JSONedit', ['ui.sortable'])
+ ''
// object key
+ ''
- + ' '
// delete button
- + ' '
+ + ' '
+ ' '
// object value
+ '' + switchTemplate + ' '
@@ -233,10 +243,10 @@ angular.module('JSONedit', ['ui.sortable'])
+ ''
+ '
'
// repeat
- + ''
+ + ' '
// delete button
- + ' '
- + ' '
+ + ' '
+ + ' '
+ '' + switchTemplate + ' '
+ ' '
// repeat end