MCPcopy Create free account
hub / github.com/Samirla/xmlview / expandNode

Function expandNode

src/controller.js:48–78  ·  view source on GitHub ↗

* Expand node * @param {Element|jQuery} elem Node to expand * @param {Boolean} is_recursive Recursively expand all child nodes

(elem, is_recursive)

Source from the content-addressed store, hash-verified

46 * @param {Boolean} is_recursive Recursively expand all child nodes
47 */
48 function expandNode(elem, is_recursive) {
49 if (!xv_dom.hasClass(elem, 'xv-collapsed')) // additional check for recursive calls
50 return;
51
52 // check if current node has unprocessed children
53 xv_dom.removeClass(elem, 'xv-collapsed');
54 if (hasUnprocessedChildren(elem)) {
55 // render all first-level child nodes
56 var orig_elem = xv_renderer.getOriginalNode(elem),
57 /** @type {Element} */
58 cur_child = _.detect(elem.childNodes, function(n) {
59 return n.nodeType == 1 && xv_dom.hasClass(n, 'xv-tag-children');
60 });
61
62 var f = document.createDocumentFragment();
63 _.each(orig_elem.childNodes, function(n) {
64 var r = xv_renderer.render(n, 0);
65 if (r) f.appendChild(r);
66 });
67
68 xv_dom.empty(cur_child);
69 cur_child.appendChild(f);
70 xv_dom.removeClass(elem, 'xv-has-unprocessed');
71 }
72
73 if (is_recursive) {
74 _.each(xv_dom.getByClass('xv-collapsed', elem), function(n) {
75 expandNode(n, is_recursive);
76 });
77 }
78 }
79
80 /**
81 * Collapse expanded node

Callers 1

controller.jsFile · 0.70

Calls 1

hasUnprocessedChildrenFunction · 0.70

Tested by

no test coverage detected