aboutsummaryrefslogtreecommitdiff
path: root/public/js/script.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js/script.js')
-rw-r--r--public/js/script.js94
1 files changed, 57 insertions, 37 deletions
diff --git a/public/js/script.js b/public/js/script.js
index cbc4221..5fd9b07 100644
--- a/public/js/script.js
+++ b/public/js/script.js
@@ -1,46 +1,66 @@
-$(document).ready(function() {
- $.get('/data', function(data) {
- $('#tree').append(addDirectory(data));
+'use strict';
- $('a').click(function(e) {
- e.preventDefault();
- e.stopPropagation();
- $.get(this.href, function(data) {
- $('#md').html(data);
- MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
- });
+document.addEventListener('DOMContentLoaded', () => {
+ const httpRequest = new XMLHttpRequest();
+
+ httpRequest.onreadystatechange = () => {
+ if( httpRequest.readyState ===4 && httpRequest.status === 200) {
+ const response = httpRequest.responseText;
+ const data = JSON.parse(response);
+ document.getElementById('tree').appendChild(addDirectory(data));
+
+ Array.from(document.getElementsByTagName('a')).forEach( (a) => {
+ a.onclick = (function (e) {
+ e.preventDefault();
+ e.stopPropagation();
+ const setMd = new XMLHttpRequest();
+ setMd.onreadystatechange = () => {
+ if( setMd.readyState ===4 && setMd.status === 200) {
+ document.getElementById('md');
+ md.innerHTML = setMd.responseText;
+ }
+ }
+ setMd.open('GET', a.href);
+ setMd.send();
+ });
+ });
+ Array.from(document.getElementsByClassName("directory")).forEach( (dir) => {
+ dir.querySelectorAll('ul').forEach( (ul) => {
+ ul.style.display = 'none';
});
-
+ dir.onclick = ( (e) => {
+ e.stopPropagation();
- $('.directory').find('ul').hide();
- $('.directory').click(function(e) {
- e.stopPropagation();
- $(this).children('ul').slideToggle();
- MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
+ dir.querySelectorAll('ul').forEach( (ul) => {
+ ul.style.display = ul.style.display === 'none' ? 'block' : 'none';
+ });
});
- });
+ });
+ }
+ };
+ httpRequest.open('GET', '/data');
+ httpRequest.send();
});
-
function addDirectory(data) {
- var ul = document.createElement('ul');
- data.children.forEach(function(item) {
- var li = document.createElement('li');
- var text = document.createTextNode(item.name);
+ const ul = document.createElement('ul');
+ data.children.forEach(item => {
+ const li = document.createElement('li');
+ const text = document.createTextNode(item.name);
- if (item.type === "file") {
- var a = document.createElement('a');
- a.appendChild(text);
- a.href = item.path;
- li.appendChild(a);
- li.classList.add("file");
- } else {
- li.appendChild(text);
- li.tabIndex = 0
- li.appendChild(addDirectory(item));
- li.classList.add("directory");
- }
- ul.appendChild(li);
- });
- return ul;
+ if (item.type === 'file') {
+ const a = document.createElement('a');
+ a.appendChild(text);
+ a.href = item.path;
+ li.appendChild(a);
+ li.classList.add('file');
+ } else {
+ li.appendChild(text);
+ li.tabIndex = 0;
+ li.appendChild(addDirectory(item));
+ li.classList.add('directory');
+ }
+ ul.appendChild(li);
+ });
+ return ul;
}