node-red-contrib-snap4city-user
Version:
Nodes for Snap4city project, targeted to standard user (no developer)
1,044 lines (1,027 loc) • 120 kB
JavaScript
/*! jQuery Fancytree Plugin - 2.26.0 - 2017-11-04T17:52:53Z
* https://github.com/mar10/fancytree
* Copyright (c) 2017 Martin Wendt; Licensed MIT
*/
(function (factory) {
if (typeof define === "function" && define.amd) {
// AMD. Register as an anonymous module.
define([
"jquery",
"jquery-ui/ui/widgets/mouse",
"jquery-ui/ui/widgets/draggable",
"jquery-ui/ui/widgets/droppable",
"jquery-ui/ui/effects/effect-blind",
"jquery-ui/ui/data",
"jquery-ui/ui/effect",
"jquery-ui/ui/focusable",
"jquery-ui/ui/keycode",
"jquery-ui/ui/position",
"jquery-ui/ui/scroll-parent",
"jquery-ui/ui/tabbable",
"jquery-ui/ui/unique-id",
"jquery-ui/ui/widget"
], factory);
} else if (typeof module === "object" && module.exports) {
// Node/CommonJS
module.exports = factory(require("jquery"));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
! function (a) {
"function" == typeof define && define.amd ? define(["jquery", "./jquery.fancytree.ui-deps"], a) : "object" == typeof module && module.exports ? (require("jquery.fancytree.ui-deps"), module.exports = a(require("jquery"))) : a(jQuery)
}(function (a) {
"use strict";
function b(b, c) {
b || (c = c ? ": " + c : "", a.error("Fancytree assertion failed" + c))
}
function c(a, b) {
var c, d, e = window.console ? window.console[a] : null;
if (e) try {
e.apply(window.console, b)
} catch (f) {
for (d = "", c = 0; c < b.length; c++) d += b[c];
e(d)
}
}
function d(a) {
return !(!a.tree || void 0 === a.statusNodeType)
}
function e(b, c, d, e) {
var f, g, h, i = a.map(a.trim(b).split("."), function (a) {
return parseInt(a, 10)
}),
j = a.map(Array.prototype.slice.call(arguments, 1), function (a) {
return parseInt(a, 10)
});
for (f = 0; f < j.length; f++)
if (g = i[f] || 0, h = j[f] || 0, g !== h) return g > h;
return !0
}
function f(a, b, c, d, e) {
var f = function () {
var c = b[a],
f = d[a],
g = b.ext[e],
h = function () {
return c.apply(b, arguments)
},
i = function (a) {
return c.apply(b, a)
};
return function () {
var a = b._local,
c = b._super,
d = b._superApply;
try {
return b._local = g, b._super = h, b._superApply = i, f.apply(b, arguments)
} finally {
b._local = a, b._super = c, b._superApply = d
}
}
}();
return f
}
function g(b, c, d, e) {
for (var g in d) "function" == typeof d[g] ? "function" == typeof b[g] ? b[g] = f(g, b, c, d, e) : "_" === g.charAt(0) ? b.ext[e][g] = f(g, b, c, d, e) : a.error("Could not override tree." + g + ". Use prefix '_' to create tree." + e + "._" + g) : "options" !== g && (b.ext[e][g] = d[g])
}
function h(b, c) {
return void 0 === b ? a.Deferred(function () {
this.resolve()
}).promise() : a.Deferred(function () {
this.resolveWith(b, c)
}).promise()
}
function i(b, c) {
return void 0 === b ? a.Deferred(function () {
this.reject()
}).promise() : a.Deferred(function () {
this.rejectWith(b, c)
}).promise()
}
function j(a, b) {
return function () {
a.resolveWith(b)
}
}
function k(b) {
var c = a.extend({}, b.data()),
d = c.json;
return delete c.fancytree, delete c.uiFancytree, d && (delete c.json, c = a.extend(c, d)), c
}
function l(a) {
return ("" + a).replace(v, function (a) {
return x[a]
})
}
function m(a) {
return a = a.toLowerCase(),
function (b) {
return b.title.toLowerCase().indexOf(a) >= 0
}
}
function n(a) {
var b = new RegExp("^" + a, "i");
return function (a) {
return b.test(a.title)
}
}
function o(c, d) {
var e, f, g, h;
for (this.parent = c, this.tree = c.tree, this.ul = null, this.li = null, this.statusNodeType = null, this._isLoading = !1, this._error = null, this.data = {}, e = 0, f = D.length; e < f; e++) g = D[e], this[g] = d[g];
null == this.unselectableIgnore && null == this.unselectableStatus || (this.unselectable = !0), d.hideCheckbox && a.error("'hideCheckbox' node option was removed in v2.23.0: use 'checkbox: false'"), d.data && a.extend(this.data, d.data);
for (g in d) E[g] || a.isFunction(d[g]) || G[g] || (this.data[g] = d[g]);
null == this.key ? this.tree.options.defaultKey ? (this.key = this.tree.options.defaultKey(this), b(this.key, "defaultKey() must return a unique key")) : this.key = "_" + s._nextNodeKey++ : this.key = "" + this.key, d.active && (b(null === this.tree.activeNode, "only one active node allowed"), this.tree.activeNode = this), d.selected && (this.tree.lastSelectedNode = this), h = d.children, h ? h.length ? this._setChildren(h) : this.children = this.lazy ? [] : null : this.children = null, this.tree._callHook("treeRegisterNode", this.tree, !0, this)
}
function p(b) {
this.widget = b, this.$div = b.element, this.options = b.options, this.options && (a.isFunction(this.options.lazyload) && !a.isFunction(this.options.lazyLoad) && (this.options.lazyLoad = function () {
return s.warn("The 'lazyload' event is deprecated since 2014-02-25. Use 'lazyLoad' (with uppercase L) instead."), b.options.lazyload.apply(this, arguments)
}), a.isFunction(this.options.loaderror) && a.error("The 'loaderror' event was renamed since 2014-07-03. Use 'loadError' (with uppercase E) instead."), void 0 !== this.options.fx && s.warn("The 'fx' option was replaced by 'toggleEffect' since 2014-11-30."), void 0 !== this.options.removeNode && a.error("The 'removeNode' event was replaced by 'modifyChild' since 2.20 (2016-09-10).")), this.ext = {}, this.data = k(this.$div), this._id = a.ui.fancytree._nextId++, this._ns = ".fancytree-" + this._id, this.activeNode = null, this.focusNode = null, this._hasFocus = null, this._tempCache = {}, this._lastMousedownNode = null, this._enableUpdate = !0, this.lastSelectedNode = null, this.systemFocusElement = null, this.lastQuicksearchTerm = "", this.lastQuicksearchTime = 0, this.statusClassPropName = "span", this.ariaPropName = "li", this.nodeContainerAttrName = "li", this.$div.find(">ul.fancytree-container").remove();
var c, d = {
tree: this
};
this.rootNode = new o(d, {
title: "root",
key: "root_" + this._id,
children: null,
expanded: !0
}), this.rootNode.parent = null, c = a("<ul>", {
"class": "ui-fancytree fancytree-container fancytree-plain"
}).appendTo(this.$div), this.$container = c, this.rootNode.ul = c[0], null == this.options.debugLevel && (this.options.debugLevel = s.debugLevel)
}
if (a.ui && a.ui.fancytree) return void a.ui.fancytree.warn("Fancytree: ignored duplicate include");
var q, r, s = null,
t = new RegExp(/\.|\//),
u = /[&<>"'\/]/g,
v = /[<>"'\/]/g,
w = "$recursive_request",
x = {
"&": "&",
"<": "<",
">": ">",
'"': """,
"'": "'",
"/": "/"
},
y = {
16: !0,
17: !0,
18: !0
},
z = {
8: "backspace",
9: "tab",
10: "return",
13: "return",
19: "pause",
20: "capslock",
27: "esc",
32: "space",
33: "pageup",
34: "pagedown",
35: "end",
36: "home",
37: "left",
38: "up",
39: "right",
40: "down",
45: "insert",
46: "del",
59: ";",
61: "=",
96: "0",
97: "1",
98: "2",
99: "3",
100: "4",
101: "5",
102: "6",
103: "7",
104: "8",
105: "9",
106: "*",
107: "+",
109: "-",
110: ".",
111: "/",
112: "f1",
113: "f2",
114: "f3",
115: "f4",
116: "f5",
117: "f6",
118: "f7",
119: "f8",
120: "f9",
121: "f10",
122: "f11",
123: "f12",
144: "numlock",
145: "scroll",
173: "-",
186: ";",
187: "=",
188: ",",
189: "-",
190: ".",
191: "/",
192: "`",
219: "[",
220: "\\",
221: "]",
222: "'"
},
A = {
0: "",
1: "left",
2: "middle",
3: "right"
},
B = "active expanded focus folder lazy radiogroup selected unselectable unselectableIgnore".split(" "),
C = {},
D = "checkbox expanded extraClasses folder icon key lazy radiogroup refKey selected statusNodeType title tooltip unselectable unselectableIgnore unselectableStatus".split(" "),
E = {},
F = {},
G = {
active: !0,
children: !0,
data: !0,
focus: !0
};
for (q = 0; q < B.length; q++) C[B[q]] = !0;
for (q = 0; q < D.length; q++) r = D[q], E[r] = !0, r !== r.toLowerCase() && (F[r.toLowerCase()] = r);
return b(a.ui, "Fancytree requires jQuery UI (http://jqueryui.com)"), o.prototype = {
_findDirectChild: function (a) {
var b, c, d = this.children;
if (d)
if ("string" == typeof a) {
for (b = 0, c = d.length; b < c; b++)
if (d[b].key === a) return d[b]
} else {
if ("number" == typeof a) return this.children[a];
if (a.parent === this) return a
} return null
},
_setChildren: function (a) {
b(a && (!this.children || 0 === this.children.length), "only init supported"), this.children = [];
for (var c = 0, d = a.length; c < d; c++) this.children.push(new o(this, a[c]))
},
addChildren: function (c, d) {
var e, f, g, h = this.getFirstChild(),
i = this.getLastChild(),
j = null,
k = [];
for (a.isPlainObject(c) && (c = [c]), this.children || (this.children = []), e = 0, f = c.length; e < f; e++) k.push(new o(this, c[e]));
if (j = k[0], null == d ? this.children = this.children.concat(k) : (d = this._findDirectChild(d), g = a.inArray(d, this.children), b(g >= 0, "insertBefore must be an existing child"), this.children.splice.apply(this.children, [g, 0].concat(k))), h && !d) {
for (e = 0, f = k.length; e < f; e++) k[e].render();
h !== this.getFirstChild() && h.renderStatus(), i !== this.getLastChild() && i.renderStatus()
} else(!this.parent || this.parent.ul || this.tr) && this.render();
return 3 === this.tree.options.selectMode && this.fixSelection3FromEndNodes(), this.triggerModifyChild("add", 1 === k.length ? k[0] : null), j
},
addClass: function (a) {
return this.toggleClass(a, !0)
},
addNode: function (a, c) {
switch (void 0 !== c && "over" !== c || (c = "child"), c) {
case "after":
return this.getParent().addChildren(a, this.getNextSibling());
case "before":
return this.getParent().addChildren(a, this);
case "firstChild":
var d = this.children ? this.children[0] : null;
return this.addChildren(a, d);
case "child":
case "over":
return this.addChildren(a)
}
b(!1, "Invalid mode: " + c)
},
addPagingNode: function (b, c) {
var d, e;
if (c = c || "child", b === !1) {
for (d = this.children.length - 1; d >= 0; d--) e = this.children[d], "paging" === e.statusNodeType && this.removeChild(e);
return void(this.partload = !1)
}
return b = a.extend({
title: this.tree.options.strings.moreData,
statusNodeType: "paging",
icon: !1
}, b), this.partload = !0, this.addNode(b, c)
},
appendSibling: function (a) {
return this.addNode(a, "after")
},
applyPatch: function (b) {
if (null === b) return this.remove(), h(this);
var c, d, e, f = {
children: !0,
expanded: !0,
parent: !0
};
for (c in b) e = b[c], f[c] || a.isFunction(e) || (E[c] ? this[c] = e : this.data[c] = e);
return b.hasOwnProperty("children") && (this.removeChildren(), b.children && this._setChildren(b.children)), this.isVisible() && (this.renderTitle(), this.renderStatus()), d = b.hasOwnProperty("expanded") ? this.setExpanded(b.expanded) : h(this)
},
collapseSiblings: function () {
return this.tree._callHook("nodeCollapseSiblings", this)
},
copyTo: function (a, b, c) {
return a.addNode(this.toDict(!0, c), b)
},
countChildren: function (a) {
var b, c, d, e = this.children;
if (!e) return 0;
if (d = e.length, a !== !1)
for (b = 0, c = d; b < c; b++) d += e[b].countChildren();
return d
},
debug: function (a) {
this.tree.options.debugLevel >= 2 && (Array.prototype.unshift.call(arguments, this.toString()), c("log", arguments))
},
discard: function () {
return this.warn("FancytreeNode.discard() is deprecated since 2014-02-16. Use .resetLazy() instead."), this.resetLazy()
},
discardMarkup: function (a) {
var b = a ? "nodeRemoveMarkup" : "nodeRemoveChildMarkup";
this.tree._callHook(b, this)
},
findAll: function (b) {
b = a.isFunction(b) ? b : m(b);
var c = [];
return this.visit(function (a) {
b(a) && c.push(a)
}), c
},
findFirst: function (b) {
b = a.isFunction(b) ? b : m(b);
var c = null;
return this.visit(function (a) {
if (b(a)) return c = a, !1
}), c
},
_changeSelectStatusAttrs: function (a) {
var c = !1,
d = this.tree.options,
e = s.evalOption("unselectable", this, this, d, !1),
f = s.evalOption("unselectableStatus", this, this, d, void 0);
switch (e && null != f && (a = f), a) {
case !1:
c = this.selected || this.partsel, this.selected = !1, this.partsel = !1;
break;
case !0:
c = !this.selected || !this.partsel, this.selected = !0, this.partsel = !0;
break;
case void 0:
c = this.selected || !this.partsel, this.selected = !1, this.partsel = !0;
break;
default:
b(!1, "invalid state: " + a)
}
return c && this.renderStatus(), c
},
fixSelection3AfterClick: function (a) {
var b = this.isSelected();
this.visit(function (a) {
a._changeSelectStatusAttrs(b)
}), this.fixSelection3FromEndNodes(a)
},
fixSelection3FromEndNodes: function (a) {
function c(a) {
var b, e, f, g, h, i, j, k, l, m = a.children;
if (m && m.length) {
for (i = !0, j = !1, b = 0, e = m.length; b < e; b++) f = m[b], g = c(f), k = s.evalOption("unselectableIgnore", f, f, d, !1), k || (g !== !1 && (j = !0), g !== !0 && (i = !1));
h = !!i || !!j && void 0
} else l = s.evalOption("unselectableStatus", a, a, d, void 0), h = null == l ? !!a.selected : !!l;
return a._changeSelectStatusAttrs(h), h
}
var d = this.tree.options;
b(3 === d.selectMode, "expected selectMode 3"), c(this), this.visitParents(function (a) {
var b, c, e, f, g, h, i = a.children,
j = !0,
k = !1;
for (b = 0, c = i.length; b < c; b++) e = i[b], g = s.evalOption("unselectableIgnore", e, e, d, !1), g || (h = s.evalOption("unselectableStatus", e, e, d, void 0), f = null == h ? !!e.selected : !!h, (f || e.partsel) && (k = !0), f || (j = !1));
f = !!j || !!k && void 0, a._changeSelectStatusAttrs(f)
})
},
fromDict: function (b) {
for (var c in b) E[c] ? this[c] = b[c] : "data" === c ? a.extend(this.data, b.data) : a.isFunction(b[c]) || G[c] || (this.data[c] = b[c]);
b.children && (this.removeChildren(), this.addChildren(b.children)), this.renderTitle()
},
getChildren: function () {
if (void 0 !== this.hasChildren()) return this.children
},
getFirstChild: function () {
return this.children ? this.children[0] : null
},
getIndex: function () {
return a.inArray(this, this.parent.children)
},
getIndexHier: function (b, c) {
b = b || ".";
var d, e = [];
return a.each(this.getParentList(!1, !0), function (a, b) {
d = "" + (b.getIndex() + 1), c && (d = ("0000000" + d).substr(-c)), e.push(d)
}), e.join(b)
},
getKeyPath: function (a) {
var b = [],
c = this.tree.options.keyPathSeparator;
return this.visitParents(function (a) {
a.parent && b.unshift(a.key)
}, !a), c + b.join(c)
},
getLastChild: function () {
return this.children ? this.children[this.children.length - 1] : null
},
getLevel: function () {
for (var a = 0, b = this.parent; b;) a++, b = b.parent;
return a
},
getNextSibling: function () {
if (this.parent) {
var a, b, c = this.parent.children;
for (a = 0, b = c.length - 1; a < b; a++)
if (c[a] === this) return c[a + 1]
}
return null
},
getParent: function () {
return this.parent
},
getParentList: function (a, b) {
for (var c = [], d = b ? this : this.parent; d;)(a || d.parent) && c.unshift(d), d = d.parent;
return c
},
getPrevSibling: function () {
if (this.parent) {
var a, b, c = this.parent.children;
for (a = 1, b = c.length; a < b; a++)
if (c[a] === this) return c[a - 1]
}
return null
},
getSelectedNodes: function (a) {
var b = [];
return this.visit(function (c) {
if (c.selected && (b.push(c), a === !0)) return "skip"
}), b
},
hasChildren: function () {
if (this.lazy) {
if (null == this.children) return;
if (0 === this.children.length) return !1;
if (1 === this.children.length && this.children[0].isStatusNode()) return;
return !0
}
return !(!this.children || !this.children.length)
},
hasFocus: function () {
return this.tree.hasFocus() && this.tree.focusNode === this
},
info: function (a) {
this.tree.options.debugLevel >= 1 && (Array.prototype.unshift.call(arguments, this.toString()), c("info", arguments))
},
isActive: function () {
return this.tree.activeNode === this
},
isChildOf: function (a) {
return this.parent && this.parent === a
},
isDescendantOf: function (b) {
if (!b || b.tree !== this.tree) return !1;
for (var c = this.parent; c;) {
if (c === b) return !0;
c === c.parent && a.error("Recursive parent link: " + c), c = c.parent
}
return !1
},
isExpanded: function () {
return !!this.expanded
},
isFirstSibling: function () {
var a = this.parent;
return !a || a.children[0] === this
},
isFolder: function () {
return !!this.folder
},
isLastSibling: function () {
var a = this.parent;
return !a || a.children[a.children.length - 1] === this
},
isLazy: function () {
return !!this.lazy
},
isLoaded: function () {
return !this.lazy || void 0 !== this.hasChildren()
},
isLoading: function () {
return !!this._isLoading
},
isRoot: function () {
return this.isRootNode()
},
isPartsel: function () {
return !this.selected && !!this.partsel
},
isPartload: function () {
return !!this.partload
},
isRootNode: function () {
return this.tree.rootNode === this
},
isSelected: function () {
return !!this.selected
},
isStatusNode: function () {
return !!this.statusNodeType
},
isPagingNode: function () {
return "paging" === this.statusNodeType
},
isTopLevel: function () {
return this.tree.rootNode === this.parent
},
isUndefined: function () {
return void 0 === this.hasChildren()
},
isVisible: function () {
var a, b, c = this.getParentList(!1, !1);
for (a = 0, b = c.length; a < b; a++)
if (!c[a].expanded) return !1;
return !0
},
lazyLoad: function (a) {
return this.warn("FancytreeNode.lazyLoad() is deprecated since 2014-02-16. Use .load() instead."), this.load(a)
},
load: function (a) {
var c, d, e = this,
f = this.isExpanded();
return b(this.isLazy(), "load() requires a lazy node"), a || this.isUndefined() ? (this.isLoaded() && this.resetLazy(), d = this.tree._triggerNodeEvent("lazyLoad", this), d === !1 ? h(this) : (b("boolean" != typeof d, "lazyLoad event must return source in data.result"), c = this.tree._callHook("nodeLoadChildren", this, d), f ? (this.expanded = !0, c.always(function () {
e.render()
})) : c.always(function () {
e.renderStatus()
}), c)) : h(this)
},
makeVisible: function (b) {
var c, d = this,
e = [],
f = new a.Deferred,
g = this.getParentList(!1, !1),
h = g.length,
i = !(b && b.noAnimation === !0),
j = !(b && b.scrollIntoView === !1);
for (c = h - 1; c >= 0; c--) e.push(g[c].setExpanded(!0, b));
return a.when.apply(a, e).done(function () {
j ? d.scrollIntoView(i).done(function () {
f.resolve()
}) : f.resolve()
}), f.promise()
},
moveTo: function (c, d, e) {
void 0 === d || "over" === d ? d = "child" : "firstChild" === d && (c.children && c.children.length ? (d = "before", c = c.children[0]) : d = "child");
var f, g = this.parent,
h = "child" === d ? c : c.parent;
if (this !== c) {
if (this.parent ? h.isDescendantOf(this) && a.error("Cannot move a node to its own descendant") : a.error("Cannot move system root"), h !== g && g.triggerModifyChild("remove", this), 1 === this.parent.children.length) {
if (this.parent === h) return;
this.parent.children = this.parent.lazy ? [] : null, this.parent.expanded = !1
} else f = a.inArray(this, this.parent.children), b(f >= 0, "invalid source parent"), this.parent.children.splice(f, 1);
if (this.parent = h, h.hasChildren()) switch (d) {
case "child":
h.children.push(this);
break;
case "before":
f = a.inArray(c, h.children), b(f >= 0, "invalid target parent"), h.children.splice(f, 0, this);
break;
case "after":
f = a.inArray(c, h.children), b(f >= 0, "invalid target parent"), h.children.splice(f + 1, 0, this);
break;
default:
a.error("Invalid mode " + d)
} else h.children = [this];
e && c.visit(e, !0), h === g ? h.triggerModifyChild("move", this) : h.triggerModifyChild("add", this), this.tree !== c.tree && (this.warn("Cross-tree moveTo is experimantal!"), this.visit(function (a) {
a.tree = c.tree
}, !0)), g.isDescendantOf(h) || g.render(), h.isDescendantOf(g) || h === g || h.render()
}
},
navigate: function (b, c) {
function d(d) {
if (d) {
try {
d.makeVisible({
scrollIntoView: !1
})
} catch (e) {}
return a(d.span).is(":visible") ? c === !1 ? d.setFocus() : d.setActive() : (d.debug("Navigate: skipping hidden node"), void d.navigate(b, c))
}
}
var e, f, g, i = !0,
j = a.ui.keyCode,
k = null;
switch (b) {
case j.BACKSPACE:
this.parent && this.parent.parent && (g = d(this.parent));
break;
case j.HOME:
this.tree.visit(function (b) {
if (a(b.span).is(":visible")) return g = d(b), !1
});
break;
case j.END:
this.tree.visit(function (b) {
a(b.span).is(":visible") && (g = b)
}), g && (g = d(g));
break;
case j.LEFT:
this.expanded ? (this.setExpanded(!1), g = d(this)) : this.parent && this.parent.parent && (g = d(this.parent));
break;
case j.RIGHT:
this.expanded || !this.children && !this.lazy ? this.children && this.children.length && (g = d(this.children[0])) : (this.setExpanded(), g = d(this));
break;
case j.UP:
for (k = this.getPrevSibling(); k && !a(k.span).is(":visible");) k = k.getPrevSibling();
for (; k && k.expanded && k.children && k.children.length;) k = k.children[k.children.length - 1];
!k && this.parent && this.parent.parent && (k = this.parent), g = d(k);
break;
case j.DOWN:
if (this.expanded && this.children && this.children.length) k = this.children[0];
else
for (f = this.getParentList(!1, !0), e = f.length - 1; e >= 0; e--) {
for (k = f[e].getNextSibling(); k && !a(k.span).is(":visible");) k = k.getNextSibling();
if (k) break
}
g = d(k);
break;
default:
i = !1
}
return g || h()
},
remove: function () {
return this.parent.removeChild(this)
},
removeChild: function (a) {
return this.tree._callHook("nodeRemoveChild", this, a)
},
removeChildren: function () {
return this.tree._callHook("nodeRemoveChildren", this)
},
removeClass: function (a) {
return this.toggleClass(a, !1)
},
render: function (a, b) {
return this.tree._callHook("nodeRender", this, a, b)
},
renderTitle: function () {
return this.tree._callHook("nodeRenderTitle", this)
},
renderStatus: function () {
return this.tree._callHook("nodeRenderStatus", this)
},
replaceWith: function (c) {
var d, e = this.parent,
f = a.inArray(this, e.children),
g = this;
return b(this.isPagingNode(), "replaceWith() currently requires a paging status node"), d = this.tree._callHook("nodeLoadChildren", this, c), d.done(function (a) {
var b = g.children;
for (q = 0; q < b.length; q++) b[q].parent = e;
e.children.splice.apply(e.children, [f + 1, 0].concat(b)), g.children = null, g.remove(), e.render()
}).fail(function () {
g.setExpanded()
}), d
},
resetLazy: function () {
this.removeChildren(), this.expanded = !1, this.lazy = !0, this.children = void 0, this.renderStatus()
},
scheduleAction: function (b, c) {
this.tree.timer && clearTimeout(this.tree.timer), this.tree.timer = null;
var d = this;
switch (b) {
case "cancel":
break;
case "expand":
this.tree.timer = setTimeout(function () {
d.tree.debug("setTimeout: trigger expand"), d.setExpanded(!0)
}, c);
break;
case "activate":
this.tree.timer = setTimeout(function () {
d.tree.debug("setTimeout: trigger activate"), d.setActive(!0)
}, c);
break;
default:
a.error("Invalid mode " + b)
}
},
scrollIntoView: function (c, e) {
void 0 !== e && d(e) && (this.warn("scrollIntoView() with 'topNode' option is deprecated since 2014-05-08. Use 'options.topNode' instead."), e = {
topNode: e
});
var f, g, i, j, k = a.extend({
effects: c === !0 ? {
duration: 200,
queue: !1
} : c,
scrollOfs: this.tree.options.scrollOfs,
scrollParent: this.tree.options.scrollParent || this.tree.$container,
topNode: null
}, e),
l = new a.Deferred,
m = this,
n = a(this.span).height(),
o = a(k.scrollParent),
p = k.scrollOfs.top || 0,
q = k.scrollOfs.bottom || 0,
r = o.height(),
s = o.scrollTop(),
t = o,
u = o[0] === window,
v = k.topNode || null,
w = null;
return a(this.span).is(":visible") ? (u ? (g = a(this.span).offset().top, f = v && v.span ? a(v.span).offset().top : 0, t = a("html,body")) : (b(o[0] !== document && o[0] !== document.body, "scrollParent should be a simple element or `window`, not document or body."), j = o.offset().top, g = a(this.span).offset().top - j + s, f = v ? a(v.span).offset().top - j + s : 0, i = Math.max(0, o.innerHeight() - o[0].clientHeight), r -= i), g < s + p ? w = g - p : g + n > s + r - q && (w = g + n - r + q, v && (b(v.isRootNode() || a(v.span).is(":visible"), "topNode must be visible"), f < w && (w = f - p))), null !== w ? k.effects ? (k.effects.complete = function () {
l.resolveWith(m)
}, t.stop(!0).animate({
scrollTop: w
}, k.effects)) : (t[0].scrollTop = w, l.resolveWith(this)) : l.resolveWith(this), l.promise()) : (this.warn("scrollIntoView(): node is invisible."), h())
},
setActive: function (a, b) {
return this.tree._callHook("nodeSetActive", this, a, b)
},
setExpanded: function (a, b) {
return this.tree._callHook("nodeSetExpanded", this, a, b)
},
setFocus: function (a) {
return this.tree._callHook("nodeSetFocus", this, a)
},
setSelected: function (a, b) {
return this.tree._callHook("nodeSetSelected", this, a, b)
},
setStatus: function (a, b, c) {
return this.tree._callHook("nodeSetStatus", this, a, b, c)
},
setTitle: function (a) {
this.title = a, this.renderTitle(), this.triggerModify("rename")
},
sortChildren: function (a, b) {
var c, d, e = this.children;
if (e) {
if (a = a || function (a, b) {
var c = a.title.toLowerCase(),
d = b.title.toLowerCase();
return c === d ? 0 : c > d ? 1 : -1
}, e.sort(a), b)
for (c = 0, d = e.length; c < d; c++) e[c].children && e[c].sortChildren(a, "$norender$");
"$norender$" !== b && this.render(), this.triggerModifyChild("sort")
}
},
toDict: function (b, c) {
var d, e, f, g = {},
h = this;
if (a.each(D, function (a, b) {
(h[b] || h[b] === !1) && (g[b] = h[b])
}), a.isEmptyObject(this.data) || (g.data = a.extend({}, this.data), a.isEmptyObject(g.data) && delete g.data), c && c(g, h), b && this.hasChildren())
for (g.children = [], d = 0, e = this.children.length; d < e; d++) f = this.children[d], f.isStatusNode() || g.children.push(f.toDict(!0, c));
return g
},
toggleClass: function (b, c) {
var d, e, f = /\S+/g,
g = b.match(f) || [],
h = 0,
i = !1,
j = this[this.tree.statusClassPropName],
k = " " + (this.extraClasses || "") + " ";
for (j && a(j).toggleClass(b, c); d = g[h++];)
if (e = k.indexOf(" " + d + " ") >= 0, c = void 0 === c ? !e : !!c) e || (k += d + " ", i = !0);
else
for (; k.indexOf(" " + d + " ") > -1;) k = k.replace(" " + d + " ", " ");
return this.extraClasses = a.trim(k), i
},
toggleExpanded: function () {
return this.tree._callHook("nodeToggleExpanded", this)
},
toggleSelected: function () {
return this.tree._callHook("nodeToggleSelected", this)
},
toString: function () {
return "<FancytreeNode(#" + this.key + ", '" + this.title + "')>"
},
triggerModifyChild: function (b, c, d) {
var e, f = this.tree.options.modifyChild;
f && (c && c.parent !== this && a.error("childNode " + c + " is not a child of " + this), e = {
node: this,
tree: this.tree,
operation: b,
childNode: c || null
}, d && a.extend(e, d), f({
type: "modifyChild"
}, e))
},
triggerModify: function (a, b) {
this.parent.triggerModifyChild(a, this, b)
},
visit: function (a, b) {
var c, d, e = !0,
f = this.children;
if (b === !0 && (e = a(this), e === !1 || "skip" === e)) return e;
if (f)
for (c = 0, d = f.length; c < d && (e = f[c].visit(a, !0), e !== !1); c++);
return e
},
visitAndLoad: function (b, c, d) {
var e, f, g, i = this;
return b && c === !0 && (f = b(i), f === !1 || "skip" === f) ? d ? f : h() : i.children || i.lazy ? (e = new a.Deferred, g = [], i.load().done(function () {
for (var c = 0, d = i.children.length; c < d; c++) {
if (f = i.children[c].visitAndLoad(b, !0, !0), f === !1) {
e.reject();
break
}
"skip" !== f && g.push(f)
}
a.when.apply(this, g).then(function () {
e.resolve()
})
}), e.promise()) : h()
},
visitParents: function (a, b) {
if (b && a(this) === !1) return !1;
for (var c = this.parent; c;) {
if (a(c) === !1) return !1;
c = c.parent
}
return !0
},
visitSiblings: function (a, b) {
var c, d, e, f = this.parent.children;
for (c = 0, d = f.length; c < d; c++)
if (e = f[c], (b || e !== this) && a(e) === !1) return !1;
return !0
},
warn: function (a) {
Array.prototype.unshift.call(arguments, this.toString()), c("warn", arguments)
}
}, p.prototype = {
_makeHookContext: function (b, c, d) {
var e, f;
return void 0 !== b.node ? (c && b.originalEvent !== c && a.error("invalid args"), e = b) : b.tree ? (f = b.tree, e = {
node: b,
tree: f,
widget: f.widget,
options: f.widget.options,
originalEvent: c
}) : b.widget ? e = {
node: null,
tree: b,
widget: b.widget,
options: b.widget.options,
originalEvent: c
} : a.error("invalid args"), d && a.extend(e, d), e
},
_callHook: function (b, c, d) {
var e = this._makeHookContext(c),
f = this[b],
g = Array.prototype.slice.call(arguments, 2);
return a.isFunction(f) || a.error("_callHook('" + b + "') is not a function"), g.unshift(e), f.apply(this, g)
},
_setExpiringValue: function (a, b, c) {
this._tempCache[a] = {
value: b,
expire: Date.now() + (+c || 50)
}
},
_getExpiringValue: function (a) {
var b = this._tempCache[a];
return b && b.expire < Date.now() ? b.value : (delete this._tempCache[a], null)
},
_requireExtension: function (c, d, e, f) {
e = !!e;
var g = this._local.name,
h = this.options.extensions,
i = a.inArray(c, h) < a.inArray(g, h),
j = d && null == this.ext[c],
k = !j && null != e && e !== i;
return b(g && g !== c, "invalid or same name"), !j && !k || (f || (j || d ? (f = "'" + g + "' extension requires '" + c + "'", k && (f += " to be registered " + (e ? "before" : "after") + " itself")) : f = "If used together, `" + c + "` must be registered " + (e ? "before" : "after") + " `" + g + "`"), a.error(f), !1)
},
activateKey: function (a) {
var b = this.getNodeByKey(a);
return b ? b.setActive() : this.activeNode && this.activeNode.setActive(!1), b
},
addPagingNode: function (a, b) {
return this.rootNode.addPagingNode(a, b)
},
applyPatch: function (c) {
var d, e, f, g, h, i, k = c.length,
l = [];
for (e = 0; e < k; e++) f = c[e], b(2 === f.length, "patchList must be an array of length-2-arrays"), g = f[0], h = f[1], i = null === g ? this.rootNode : this.getNodeByKey(g), i ? (d = new a.Deferred, l.push(d), i.applyPatch(h).always(j(d, i))) : this.warn("could not find node with key '" + g + "'");
return a.when.apply(a, l).promise()
},
clear: function (a) {
this._callHook("treeClear", this)
},
count: function () {
return this.rootNode.countChildren()
},
debug: function (a) {
this.options.debugLevel >= 2 && (Array.prototype.unshift.call(arguments, this.toString()), c("log", arguments))
},
enableUpdate: function (a) {
return a = a !== !1, !!this._enableUpdate == !!a ? a : (this._enableUpdate = a, a ? (this.debug("enableUpdate(true): redraw "), this.render()) : this.debug("enableUpdate(false)..."), !a)
},
findAll: function (a) {
return this.rootNode.findAll(a)
},
findFirst: function (a) {
return this.rootNode.findFirst(a)
},
findNextNode: function (b, c, d) {
var e = null,
f = c.parent.children,
g = null,
h = function (a, b, c) {
var d, e, f = a.children,
g = f.length,
i = f[b];
if (i && c(i) === !1) return !1;
if (i && i.children && i.expanded && h(i, 0, c) === !1) return !1;
for (d = b + 1; d < g; d++)
if (h(a, d, c) === !1) return !1;
return e = a.parent, e ? h(e, e.children.indexOf(a) + 1, c) : h(a, 0, c)
};
return b = "string" == typeof b ? n(b) : b, c = c || this.getFirstChild(), h(c.parent, f.indexOf(c), function (d) {
return d !== e && (e = e || d, a(d.span).is(":visible") ? (!b(d) || (g = d, g === c)) && void 0 : void d.debug("quicksearch: skipping hidden node"))
}), g
},
generateFormElements: function (b, c, d) {
function e(b) {
j.append(a("<input>", {
type: "checkbox",
name: g,
value: b.key,
checked: !0
}))
}
d = d || {};
var f, g = "string" == typeof b ? b : "ft_" + this._id + "[]",
h = "string" == typeof c ? c : "ft_" + this._id + "_active",
i = "fancytree_result_" + this._id,
j = a("#" + i),
k = 3 === this.options.selectMode && d.stopOnParents !== !1;
j.length ? j.empty() : j = a("<div>", {
id: i
}).hide().insertAfter(this.$container), c !== !1 && this.activeNode && j.append(a("<input>", {
type: "radio",
name: h,
value: this.activeNode.key,
checked: !0
})), d.filter ? this.visit(function (a) {
var b = d.filter(a);
return "skip" === b ? b : void(b !== !1 && e(a))
}) : b !== !1 && (f = this.getSelectedNodes(k), a.each(f, function (a, b) {
e(b)
}))
},
getActiveNode: function () {
return this.activeNode
},
getFirstChild: function () {
return this.rootNode.getFirstChild()
},
getFocusNode: function () {
return this.focusNode
},
getNodeByKey: function (a, b) {
var c, d;
return !b && (c = document.getElementById(this.options.idPrefix + a)) ? c.ftnode ? c.ftnode : null : (b = b || this.rootNode, d = null, b.visit(function (b) {
if (b.key === a) return d = b, !1
}, !0), d)
},
getRootNode: function () {
return this.rootNode
},
getSelectedNodes: function (a) {
return this.rootNode.getSelectedNodes(a)
},
hasFocus: function () {
return !!this._hasFocus
},
info: function (a) {
this.options.debugLevel >= 1 && (Array.prototype.unshift.call(arguments, this.toString()), c("info", arguments))
},
loadKeyPath: function (b, c, d) {
function e(a, b, d) {
c.call(q, b, "loading"), b.load().done(function () {
q.loadKeyPath.call(q, l[a], c, b).always(j(d, q))
}).fail(function (e) {
q.warn("loadKeyPath: error loading: " + a + " (parent: " + n + ")"), c.call(q, b, "error"), d.reject()
})
}
var f, g, h, i, k, l, m, n, o, p = this.options.keyPathSeparator,
q = this;
for (c = c || a.noop, a.isArray(b) || (b = [b]), l = {}, h = 0; h < b.length; h++)
for (n = d || this.rootNode, i = b[h], i.charAt(0) === p && (i = i.substr(1)), o = i.split(p); o.length;) {
if (k = o.shift(), m = n._findDirectChild(k), !m) {
this.warn("loadKeyPath: key not found: " + k + " (parent: " + n + ")"), c.call(this, k, "error");
break
}
if (0 === o.length) {
c.call(this, m, "ok");