|
1 | 1 | 'use strict';
|
2 | 2 |
|
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 | + }; |
9 | 12 |
|
10 | 13 | this.configure = function (options) {
|
11 |
| - angular.extend(configuration, options); |
| 14 | + extendDeep(configuration, options); |
12 | 15 | };
|
13 | 16 |
|
14 | 17 | this.$get = function ($window) {
|
15 | 18 | var JSONEditor = $window.JSONEditor;
|
16 |
| - angular.extend(JSONEditor, configuration); |
| 19 | + extendDeep(JSONEditor, configuration); |
17 | 20 | return $window.JSONEditor;
|
18 | 21 | };
|
19 | 22 |
|
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) { |
21 | 40 |
|
22 | 41 | return {
|
23 | 42 | restrict: 'E',
|
@@ -81,13 +100,11 @@ angular.module('angular-json-editor', []).constant('JsonEditorConfig', {
|
81 | 100 | throw new Error('json-editor: could not resolve schema data.');
|
82 | 101 | }
|
83 | 102 |
|
84 |
| - angular.extend(JsonEditorConfig, { |
| 103 | + scope.editor = new JSONEditor(element[0], { |
85 | 104 | startval: startVal,
|
86 | 105 | schema: schema
|
87 | 106 | });
|
88 | 107 |
|
89 |
| - scope.editor = new JSONEditor(element[0], JsonEditorConfig); |
90 |
| - |
91 | 108 | var editor = scope.editor;
|
92 | 109 |
|
93 | 110 | editor.on('ready', function () {
|
|
0 commit comments