angular-json-schema-form
Version:
Angular Publishable Directive Boilerplate
7 lines • 1.3 kB
JavaScript
/*!
* angular-json-schema-form
* https://github.com/mohsen1/angular-json-schema-form
* Version: 0.1.3 - 2015-07-13T22:20:46.480Z
* License: MIT
*/
;angular.module("mohsen1.schema-form",[]).directive("schemaForm",function(e,t){return{restrict:"A",replace:!1,require:"?ngModel",scope:{schema:"=schemaForm"},link:function(e,n,a,o){function r(){l&&(angular.element(s).html(""),l.destroy()),c.schema=e.schema,l=new JSONEditor(s,c),o&&(l.setValue(o.$modelValue),l.on("change",i))}function i(){e.$evalAsync(function(){var e=l.validate();o.$setViewValue(l.getValue()),o.$setValidity("schemaForm",0===e.length)})}if(angular.isObject(e.schema)){var s=window.document.createElement("div"),c=angular.extend(t.options,{schema:e.schema}),l=null;n.prepend(s),o?o.$render=r:r(),n&&n[0]instanceof HTMLElement&&n[0].addEventListener("keyup",function(e){e.target.blur(),e.target.focus(),i()},!0),e.$watch("schema",r)}}}}).provider("SchemaForm",function(){var e=angular.extend(JSONEditor.defaults.options,{disable_edit_json:!0,disable_properties:!0,no_additional_properties:!0,disable_collapse:!0});this.$get=function(){return{options:e}},this.setOptions=function(t){if(!angular.isObject(t))throw new Error("options should be an object.");angular.extend(e,t)},this.getOptions=function(){return e}});