1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/*global angular */ ! function () {
"use strict";
var e = {
is: function (e, a) {
return Object.prototype.toString.call(e).slice(8, -1) === a
},
whatClass: function (e) {
return Object.prototype.toString.call(e).slice(8, -1)
},
forKeys: function (e, a) {
for (var n in e)
if (e.hasOwnProperty(n) && "function" != typeof e[n] && a(n, e[n])) break
}
};
angular.module("angular-json-tree", ["ajs.RecursiveDirectiveHelper"]).directive("jsonTree", [function () {
return {
restrict: "E",
scope: {
object: "=",
startExpanded: "&?",
rootName: "&?"
},
template: '<json-node key="rootName() || \'\'" value="object" start-expanded="startExpanded()"></json-node>'
}
}]).directive("jsonNode", ["ajsRecursiveDirectiveHelper", function (a) {
return {
restrict: "E",
scope: {
key: "=",
value: "=",
startExpanded: "&?"
},
compile: function (e) {
return a.compile(e, this)
},
template: ' <span style="padding-left:0px" class= "key col-md-1" ng-class="{\'hidden\' : key==\'\' && key!=\'0\'}" ng-click="toggleExpanded()">{{key}}</span> <span class="leaf-value col-md-11" ng-if="!isExpandable">{{value}}</span> <span class="branch-preview" ng-if="isExpandable" ng-show="!isExpanded" ng-click="toggleExpanded()">{{preview}}</span> <ul class="branch-value" ng-if="isExpandable" > <li ng-repeat="(subkey,subval) in value"> <json-node key="subkey" class="col-md-12" value="subval"></json-node> </li> </ul>',
pre: function (a, n, s) {
if (n.addClass(e.whatClass(a.value).toLowerCase()), e.is(a.value, "Object") || e.is(a.value, "Array")) {
a.isExpandable = !0, n.addClass("expandable");
var t = e.is(a.value, "Array");
a.preview = t ? "[ " : "{ ", e.forKeys(a.value, function (e, n) {
t ? a.preview += n + ", " : a.preview += e + ": " + n + ", "
}), a.preview = a.preview.substring(0, a.preview.length - (a.preview.length > 2 ? 2 : 0)) + (t ? " ]" : " }"), a.startExpanded && a.startExpanded() && (a.shouldRender = !0, n.addClass("expanded")), a.isExpanded = a.startExpanded ? a.startExpanded() : !1, a.toggleExpanded = function () {
a.isExpanded = !a.isExpanded, a.isExpanded ? n.addClass("expanded") : n.removeClass("expanded"), a.shouldRender = !0
}
} else a.isExpandable = !1, n.addClass("not-expandable")
}
}
}]), angular.module("ajs.RecursiveDirectiveHelper", []).factory("ajsRecursiveDirectiveHelper", ["$compile", function (e) {
return {
compile: function (a, n) {
angular.isFunction(n) && (n = {
post: n
});
var s, t = a.contents().remove();
return {
pre: n && n.pre ? n.pre : null,
post: function (a, r) {
s || (s = e(t)), s(a, function (e) {
r.append(e)
}), n && n.post && n.post.apply(null, arguments)
}
}
}
}
}])
}();
|