/** * @license ng-prettyjson - v0.1.2 * (c) 2013 Julien VALERY https://github.com/darul75/ng-prettyjson * License: MIT **/ angular.module("ngPrettyJson",[]).directive("prettyJson",["ngPrettyJsonFunctions",function(a){"use strict";var b=angular.isDefined;return{restrict:"AE",scope:{json:"=",prettyJson:"="},replace:!0,template:'
',link:function(c,d,e){var f={},g="prettyjson",h=null;c.editActivated=!1,c.edition=e.edition;// prefer the "json" attribute over the "prettyJson" one. // the value on the scope might not be defined yet, so look at the markup. var i,j=b(e.json)?"json":"prettyJson",k=function(c){return b(c)?d.find("pre").html(a.syntaxHighlight(c)):d.empty()};i=c.$watch(j,function(a){// BACKWARDS COMPATIBILITY: // if newValue is an object, and we find a `json` property, // then stop watching on `exp`. angular.isObject(a)&&b(a.json)?(i(),c.$watch(j+".json",function(a){k(a),f=a},!0)):(k(a),f=a)},!0);var l=function(){try{c.currentValue=JSON.parse(h.getValue()),c.parsable=!0}catch(a){c.parsable=!1}// trigger update c.$apply(function(){})};c.edit=function(){c.editActivated?(h&&(document.getElementById(g).env=null),k(f)):(h=ace.edit(g),h.on("change",l),h.getSession().setMode("ace/mode/json")),c.editActivated=!c.editActivated},c.update=function(){c.$emit("json-updated",c.newValue)}}}}]).factory("ngPrettyJsonFunctions",function(){// cache some regular expressions var a={entities:/((&)|(<)|(>))/g,json:/"(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|(null))\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g},b=["&","<",">"],c=["number","string","key","boolean","null"],d=function(){var a=arguments.length-2;do a--;while(!arguments[a]);return a},e=function(a){var b;// the final two arguments are the length, and the entire string itself; // we don't care about those. if(arguments.length<7)throw new Error("markup() must be called from String.prototype.replace()");return b=d.apply(null,arguments),''+a+""},f=function(){var a;if(arguments.length<5)throw new Error("makeEntities() must be called from String.prototype.replace()");return a=d.apply(null,arguments),b[a-2]},g=function(b){return angular.isString(b)||(b=JSON.stringify(b,null,2)),angular.isDefined(b)?b.replace(a.entities,f).replace(a.json,e):void 0};return{syntaxHighlight:g,makeEntities:f,markup:e,rx:a}});