diff --git a/README.md b/README.md index a506643..0428869 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,16 @@ Finally, add the directive to your html: http://jsfiddle.net/angulartools/sd3at5ek/ +## Local Demo + +Run `npm install` to install the local server, then `npm start` to start it. Then visit `http://localhost:1112/demo/` + ### Sample code ```javascript myAppModule.controller('MyController', [ '$scope', function($scope) { $scope.obj = {data: json, options: { mode: 'tree' }}; - + $scope.btnClick = function() { $scope.obj.options.mode = 'code'; //should switch you to code view } @@ -99,6 +103,10 @@ myAppModule.controller('MyController', [ '$scope', function($scope) { }]); ``` +### Development + +To minify the source file, run `npm install` to install the *uglify-js* module, then run `npm run minify` + ### Contributors - Sanchit Bhatnagar diff --git a/demo/index.html b/demo/index.html new file mode 100644 index 0000000..e153ef7 --- /dev/null +++ b/demo/index.html @@ -0,0 +1,55 @@ + + + + + + + ng-jsoneditor demo + + + + + + + +
+ + + + + +
{{pretty(obj.data)}}
+ + + + + + + + \ No newline at end of file diff --git a/ng-jsoneditor.js b/ng-jsoneditor.js index b11f9c7..aa5b48a 100644 --- a/ng-jsoneditor.js +++ b/ng-jsoneditor.js @@ -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); } diff --git a/ng-jsoneditor.min.js b/ng-jsoneditor.min.js index 68c29d4..1b5fcc0 100644 --- a/ng-jsoneditor.min.js +++ b/ng-jsoneditor.min.js @@ -1 +1 @@ -(function(){var module=angular.module("ng.jsoneditor",[]);module.constant("ngJsoneditorConfig",{});module.directive("ngJsoneditor",["ngJsoneditorConfig","$timeout",function(ngJsoneditorConfig,$timeout){var defaults=ngJsoneditorConfig||{};return{restrict:"A",require:"ngModel",scope:{options:"=",ngJsoneditor:"=",preferText:"="},link:function($scope,element,attrs,ngModel){var debounceTo,debounceFrom;var editor;var internalTrigger=false;if(!angular.isDefined(window.JSONEditor)){throw new Error("Please add the jsoneditor.js script first!")}function _createEditor(options){var settings=angular.extend({},defaults,options);var theOptions=angular.extend({},settings,{change:function(){if(typeof debounceTo!=="undefined"){$timeout.cancel(debounceTo)}debounceTo=$timeout(function(){if(editor){internalTrigger=true;var error=undefined;try{ngModel.$setViewValue($scope.preferText===true?editor.getText():editor.get());}catch(err){error=err;}if(settings&&settings.hasOwnProperty("change")){settings.change(error);}}},settings.timeout||100);}});element.html("");var instance=new JSONEditor(element[0],theOptions);if($scope.ngJsoneditor instanceof Function){$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{editor=_createEditor(newValue);$scope.updateJsonEditor();return}}}}},true);$scope.$on("$destroy",function(){});$scope.updateJsonEditor=function(newValue){if(internalTrigger){internalTrigger=false;return;}if(typeof debounceFrom!=="undefined"){$timeout.cancel(debounceFrom)}debounceFrom=$timeout(function(){if($scope.preferText===true&&!angular.isObject(ngModel.$viewValue)){editor.setText(ngModel.$viewValue||"{}")}else{editor.set(ngModel.$viewValue||{})}},$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)}}}])})(); +(function(){var module=angular.module("ng.jsoneditor",[]);module.constant("ngJsoneditorConfig",{});module.directive("ngJsoneditor",["ngJsoneditorConfig","$timeout",function(ngJsoneditorConfig,$timeout){var defaults=ngJsoneditorConfig||{};return{restrict:"A",require:"ngModel",scope:{options:"=",ngJsoneditor:"=",preferText:"="},link:function($scope,element,attrs,ngModel){var debounceTo,debounceFrom;var editor;var internalTrigger=false;if(!angular.isDefined(window.JSONEditor)){throw new Error("Please add the jsoneditor.js script first!")}function _createEditor(options){var settings=angular.extend({},defaults,options);var theOptions=angular.extend({},settings,{onChange:function(){if(typeof debounceTo!=="undefined"){$timeout.cancel(debounceTo)}debounceTo=$timeout(function(){if(editor){internalTrigger=true;var error=undefined;try{ngModel.$setViewValue($scope.preferText===true?editor.getText():editor.get())}catch(err){error=err}if(settings&&settings.hasOwnProperty("change")){settings.change(error)}}},settings.timeout||100)}});element.html("");var instance=new JSONEditor(element[0],theOptions);if($scope.ngJsoneditor instanceof Function){$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{editor=_createEditor(newValue);$scope.updateJsonEditor();return}}}}},true);$scope.$on("$destroy",function(){});$scope.updateJsonEditor=function(newValue){if(internalTrigger){internalTrigger=false;return}if(typeof debounceFrom!=="undefined"){$timeout.cancel(debounceFrom)}debounceFrom=$timeout(function(){if($scope.preferText===true&&!angular.isObject(ngModel.$viewValue)){editor.setText(ngModel.$viewValue||"{}")}else{editor.set(ngModel.$viewValue||{})}},$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)}}}])})(); \ No newline at end of file diff --git a/package.json b/package.json index 6d46229..490cb7f 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,15 @@ "peerDependencies": { "jsoneditor": "^5.5.6" }, + "scripts": { + "start": "http-server -a localhost -p 1112", + "minify": "uglifyjs ng-jsoneditor.js -o ng-jsoneditor.min.js" + }, "description": "Angular version of the insanely cool jsoneditor", - "devDependencies": {}, + "devDependencies": { + "http-server": "~0.8.0", + "uglify-js": "^3.0.27" + }, "directories": {}, "homepage": "https://github.com/angular-tools/ng-jsoneditor", "keywords": [