Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 38 additions & 25 deletions ng-jsoneditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
function _createEditor(options) {
var settings = angular.extend({}, defaults, options);
var theOptions = angular.extend({}, settings, {
change: function () {
onChange: function () {
if (typeof debounceTo !== 'undefined') {
$timeout.cancel(debounceTo);
}
Expand All @@ -36,8 +36,8 @@
error = err;
}

if (settings && settings.hasOwnProperty('change')) {
settings.change(error);
if (settings && settings.hasOwnProperty('onChange')) {
settings.onChange(error);
}
}
}, settings.timeout || 100);
Expand All @@ -49,29 +49,46 @@
var instance = new JSONEditor(element[0], theOptions);

if ($scope.ngJsoneditor instanceof Function) {
$timeout(function () { $scope.ngJsoneditor(instance);});
$timeout(function () {
$scope.ngJsoneditor(instance);
});
}

return instance;
}

$scope.$watch('options', function (newValue, oldValue) {
for (var k in newValue) {
if (newValue.hasOwnProperty(k)) {
var v = newValue[k];

if (newValue[k] !== oldValue[k]) {
if (k === 'mode') {
editor.setMode(v);
} else if (k === 'name') {
editor.setName(v);
} else { //other settings cannot be changed without re-creating the JsonEditor
editor = _createEditor(newValue);
$scope.updateJsonEditor();
return;
if (editor) {
for (var k in newValue) {
if (newValue.hasOwnProperty(k)) {
var v = newValue[k];

if (!oldValue || newValue[k] !== oldValue[k]) {
if (k === 'mode') {
editor.setMode(v);
} else if (k === 'name') {
editor.setName(v);
} else if (k === 'expanded') {
if (newValue[k]) {
editor.expandAll && editor.expandAll()
} else {
editor.collapseAll && editor.collapseAll()
}
} else { //other settings cannot be changed without re-creating the JsonEditor
editor = _createEditor(newValue);
$scope.updateJsonEditor();
return;
}
}
}
}
} else {
editor = _createEditor($scope.options);
if ($scope.options) {
editor.expandAll && editor.expandAll()
} else {
editor.collapseAll && editor.collapseAll()
}
}
}, true);

Expand All @@ -96,17 +113,13 @@
} else {
editor.set(ngModel.$viewValue || {});
}
}, $scope.options.timeout || 100);
}, ($scope.options && $scope.options.timeout) || 100);
};

editor = _createEditor($scope.options);

if ($scope.options.hasOwnProperty('expanded')) {
$timeout($scope.options.expanded ? function () {editor.expandAll()} : function () {editor.collapseAll()}, ($scope.options.timeout || 100) + 100);
}

ngModel.$render = $scope.updateJsonEditor;
$scope.$watch(function () { return ngModel.$modelValue; }, $scope.updateJsonEditor, true); //if someone changes ng-model from outside
$scope.$watch(function () {
return ngModel.$modelValue;
}, $scope.updateJsonEditor, true); //if someone changes ng-model from outside
}
};
}]);
Expand Down
2 changes: 1 addition & 1 deletion ng-jsoneditor.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
"type": "git",
"url": "git+https://github.com/angular-tools/ng-jsoneditor.git"
},
"version": "1.0.0"
"version": "1.0.1"
}