Skip to content

Commit a09bbc2

Browse files
committed
Removed JsonEditorConfig
Added deep merge to JSONEditorProvider.configure #8
1 parent 0306c49 commit a09bbc2

File tree

6 files changed

+48
-19
lines changed

6 files changed

+48
-19
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ The object you pass to configure will be merged with the JSONEditor object.
5555
sceditor: {
5656
style: 'sce/development/jquery.sceditor.default.css'
5757
}
58+
},
59+
defaults: {
60+
options: {
61+
iconlib: 'bootstrap3',
62+
theme: 'bootstrap3'
63+
}
5864
}
5965
});
6066
});

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-json-editor",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"authors": [
55
"Rodik Hanukaev <[email protected]>",
66
"Topaz Bar <[email protected]>"

demo/app.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
'use strict';
22

3-
angular.module('demoApp', ['angular-json-editor']).config(function (JsonEditorConfig) {
4-
5-
// angular-json-editor configuration
6-
JsonEditorConfig.iconlib = 'bootstrap3';
7-
JsonEditorConfig.theme = 'bootstrap3';
3+
angular.module('demoApp', ['angular-json-editor']).config(function (JSONEditorProvider) {
4+
// these are set by default, but we set this for demonstration purposes
5+
JSONEditorProvider.configure({
6+
defaults: {
7+
options: {
8+
iconlib: 'bootstrap3',
9+
theme: 'bootstrap3'
10+
}
11+
}
12+
});
813

914
}).controller('SyncAppController', function ($scope) {
1015

demo/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<meta name="author" content="Rodik">
77
<title>angular-json-editor Demo</title>
88

9+
<!-- Include the relevant css for the configured theme -->
910
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
1011
</head>
1112
<body ng-app="demoApp">

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-json-editor",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"repository": {
55
"type": "git",
66
"url": "git://github.com/rodikh/angular-json-editor.git"

src/angular-json-editor.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
11
'use strict';
22

3-
angular.module('angular-json-editor', []).constant('JsonEditorConfig', {
4-
iconlib: 'bootstrap3',
5-
theme: 'bootstrap3'
6-
7-
}).provider('JSONEditor', function () {
8-
var configuration = {};
3+
angular.module('angular-json-editor', []).provider('JSONEditor', function () {
4+
var configuration = {
5+
defaults: {
6+
options: {
7+
iconlib: 'bootstrap3',
8+
theme: 'bootstrap3'
9+
}
10+
}
11+
};
912

1013
this.configure = function (options) {
11-
angular.extend(configuration, options);
14+
extendDeep(configuration, options);
1215
};
1316

1417
this.$get = function ($window) {
1518
var JSONEditor = $window.JSONEditor;
16-
angular.extend(JSONEditor, configuration);
19+
extendDeep(JSONEditor, configuration);
1720
return $window.JSONEditor;
1821
};
1922

20-
}).directive('jsonEditor', ['$q', 'JsonEditorConfig', 'JSONEditor', function ($q, JsonEditorConfig, JSONEditor) {
23+
function extendDeep(dst) {
24+
angular.forEach(arguments, function (obj) {
25+
if (obj !== dst) {
26+
angular.forEach(obj, function (value, key) {
27+
if (dst[key] && dst[key].constructor && dst[key].constructor === Object) {
28+
extendDeep(dst[key], value);
29+
} else {
30+
dst[key] = value;
31+
}
32+
});
33+
}
34+
});
35+
return dst;
36+
}
37+
38+
39+
}).directive('jsonEditor', ['$q', 'JSONEditor', function ($q, JSONEditor) {
2140

2241
return {
2342
restrict: 'E',
@@ -81,13 +100,11 @@ angular.module('angular-json-editor', []).constant('JsonEditorConfig', {
81100
throw new Error('json-editor: could not resolve schema data.');
82101
}
83102

84-
angular.extend(JsonEditorConfig, {
103+
scope.editor = new JSONEditor(element[0], {
85104
startval: startVal,
86105
schema: schema
87106
});
88107

89-
scope.editor = new JSONEditor(element[0], JsonEditorConfig);
90-
91108
var editor = scope.editor;
92109

93110
editor.on('ready', function () {

0 commit comments

Comments
 (0)