Skip to content

Commit 493e50e

Browse files
committed
added main property to package.json, included concatenated file in the dist so that it can be the main file
1 parent 8606dba commit 493e50e

File tree

4 files changed

+147
-8
lines changed

4 files changed

+147
-8
lines changed

dist/angular-json-editor.js

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
(function (window, angular) {
2+
'use strict';
3+
// Source: src/angular-json-editor.js
4+
5+
6+
angular.module('angular-json-editor', []).provider('JSONEditor', function () {
7+
var configuration = {
8+
defaults: {
9+
options: {
10+
iconlib: 'bootstrap3',
11+
theme: 'bootstrap3'
12+
}
13+
}
14+
};
15+
16+
this.configure = function (options) {
17+
extendDeep(configuration, options);
18+
};
19+
20+
this.$get = ['$window', function ($window) {
21+
var JSONEditor = $window.JSONEditor;
22+
extendDeep(JSONEditor, configuration);
23+
return $window.JSONEditor;
24+
}];
25+
26+
function extendDeep(dst) {
27+
angular.forEach(arguments, function (obj) {
28+
if (obj !== dst) {
29+
angular.forEach(obj, function (value, key) {
30+
if (dst[key] && dst[key].constructor && dst[key].constructor === Object) {
31+
extendDeep(dst[key], value);
32+
} else {
33+
dst[key] = value;
34+
}
35+
});
36+
}
37+
});
38+
return dst;
39+
}
40+
41+
}).directive('jsonEditor', ['$q', 'JSONEditor', function ($q, JSONEditor) {
42+
43+
return {
44+
restrict: 'E',
45+
transclude: true,
46+
scope: {
47+
schema: '=',
48+
startval: '=',
49+
buttonsController: '@',
50+
onChange: '&'
51+
},
52+
controller: ['$scope', '$attrs', '$controller', function ($scope, $attrs, $controller) {
53+
54+
var controller, controllerScope, controllerName = $attrs.buttonsController;
55+
if (angular.isString(controllerName) && controllerName !== '') {
56+
controllerScope = {
57+
$scope: $scope
58+
};
59+
60+
try {
61+
controller = $controller(controllerName, controllerScope);
62+
} catch (e) {
63+
// Any exceptions thrown will probably be because the controller specified does not exist
64+
throw new Error('json-editor: buttons-controller attribute must be a valid controller.');
65+
}
66+
}
67+
68+
}],
69+
link: function (scope, element, attrs, controller, transclude) {
70+
var valueToResolve,
71+
startValPromise = $q.when({}),
72+
schemaPromise = $q.when(null);
73+
74+
scope.isValid = false;
75+
76+
if (!angular.isString(attrs.schema)) {
77+
throw new Error('json-editor: schema attribute has to be defined.');
78+
}
79+
if (angular.isObject(scope.schema)) {
80+
schemaPromise = $q.when(scope.schema);
81+
}
82+
if (angular.isObject(scope.startval)) {
83+
// Support both $http (i.e. $q) and $resource promises, and also normal object.
84+
valueToResolve = scope.startval;
85+
if (angular.isDefined(valueToResolve.$promise)) {
86+
startValPromise = $q.when(valueToResolve.$promise);
87+
88+
} else {
89+
startValPromise = $q.when(valueToResolve);
90+
}
91+
}
92+
93+
// Wait for the start value and schema to resolve before building the editor.
94+
$q.all([schemaPromise, startValPromise]).then(function (result) {
95+
96+
// Support $http promise response with the 'data' property.
97+
var schema = result[0].data || result[0],
98+
startVal = result[1];
99+
if (schema === null) {
100+
throw new Error('json-editor: could not resolve schema data.');
101+
}
102+
103+
scope.editor = new JSONEditor(element[0], {
104+
startval: startVal,
105+
schema: schema
106+
});
107+
108+
var editor = scope.editor;
109+
110+
editor.on('ready', function () {
111+
scope.isValid = (editor.validate().length === 0);
112+
});
113+
114+
editor.on('change', function () {
115+
// Fire the onChange callback
116+
if (typeof scope.onChange === 'function') {
117+
scope.onChange({
118+
$editorValue: editor.getValue()
119+
});
120+
}
121+
scope.$apply(function () {
122+
scope.isValid = (editor.validate().length === 0);
123+
});
124+
});
125+
126+
// Transclude the buttons at the bottom.
127+
var buttons = transclude(scope, function (clone) {
128+
return clone;
129+
});
130+
131+
element.append(buttons);
132+
});
133+
}
134+
};
135+
136+
}]);
137+
138+
})(window, angular);

grunt/concat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = function (grunt) {
1818
}
1919
},
2020
src: ['src/**/*.js'],
21-
dest: 'build/angular-json-editor-concat.js',
21+
dest: 'dist/angular-json-editor.js',
2222
nonull: true
2323
}
2424
});

grunt/uglify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = function (grunt) {
2020
}
2121
},
2222
files: [{
23-
src: ['build/angular-json-editor-concat.js'],
23+
src: ['dist/angular-json-editor.js'],
2424
dest: 'dist/angular-json-editor.min.js'
2525
}]
2626
}

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
22
"name": "angular-json-editor",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"repository": {
55
"type": "git",
66
"url": "git://github.com/rodikh/angular-json-editor.git"
77
},
8+
"main": "dist/angular-json-editor.js",
89
"devDependencies": {
910
"grunt": "0.4.*",
1011
"grunt-contrib-jshint": "0.10.*",
11-
"grunt-jscs": "0.8.*",
12-
"grunt-contrib-uglify": "0.4.*",
13-
"grunt-contrib-concat": "0.4.*",
14-
"grunt-contrib-clean": "0.5.*",
15-
"grunt-contrib-connect": "0.7.*"
12+
"grunt-jscs": "1.1.*",
13+
"grunt-contrib-uglify": "0.7.*",
14+
"grunt-contrib-concat": "0.5.*",
15+
"grunt-contrib-clean": "0.6.*",
16+
"grunt-contrib-connect": "0.9.*"
1617
}
1718
}

0 commit comments

Comments
 (0)