CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/docs/_includes/js/custom.js
Views: 11623
1
// Handle opening/closing module overview list items
2
jtd.onReady(function(ready) {
3
var forEach = function (list, callback) {
4
for (var i = 0; i < list.length; i++) {
5
callback(list[i])
6
}
7
};
8
9
// Bind listeners for expand all / collapse all functionality
10
var bindToggleAll = function (selector, options) {
11
var isOpen = options.open;
12
var expandAllButtons = document.querySelectorAll(selector);
13
forEach(expandAllButtons, function (button) {
14
jtd.addEvent(button, 'click', function (e) {
15
var originalTarget = e.target || e.srcElement || e.originalTarget;
16
if (originalTarget.tagName !== 'A') { return; }
17
18
var moduleList = originalTarget.closest('.module-list');
19
forEach(moduleList.querySelectorAll('.folder > ul'), function (list) {
20
if (isOpen) {
21
list.classList.add('open');
22
} else {
23
list.classList.remove('open');
24
}
25
})
26
27
e.preventDefault();
28
});
29
});
30
};
31
bindToggleAll('.module-list [data-expand-all]', { open: true })
32
bindToggleAll('.module-list [data-collapse-all]', { open: false })
33
34
// Bind listeners for collapsing module navigation items
35
var moduleStructureElements = document.querySelectorAll('.module-structure');
36
forEach(moduleStructureElements, function (moduleStructure) {
37
jtd.addEvent(moduleStructure, 'click', function (e) {
38
var originalTarget = e.target || e.srcElement || e.originalTarget;
39
if (originalTarget.tagName !== 'A') { return; }
40
41
var parentListItem = originalTarget.closest('li');
42
if (parentListItem.className.indexOf('folder') === -1) { return; }
43
44
toggleChildModuleList(parentListItem)
45
e.preventDefault();
46
});
47
})
48
49
var toggleChildModuleList = function (parent) {
50
var list = parent.querySelector('ul');
51
if (!list) {
52
return;
53
}
54
list.classList.toggle('open');
55
// Recursively automatically open any nested lists of size 1
56
if (list.children.length === 1) {
57
toggleChildModuleList(list.children[0])
58
}
59
}
60
});
61
62