From d779c44cba942604c3a141fe0aef3ccafa19b8d9 Mon Sep 17 00:00:00 2001 From: ache Date: Fri, 2 Feb 2018 03:55:35 +0100 Subject: Removing unnecessary libraries --- app.js | 3 +- public/index.html | 6 ++-- public/js/script.js | 94 ++++++++++++++++++++++++++++++++--------------------- 3 files changed, 60 insertions(+), 43 deletions(-) diff --git a/app.js b/app.js index a652bd1..5d19e75 100644 --- a/app.js +++ b/app.js @@ -36,7 +36,7 @@ const remark = require('remark-parse'); const inspect = require('unist-util-inspect'); -const useLandScript = ' '; +const useLandScript = ''; const userSide_Button = ''; function to_HTML(data, fnc) { @@ -88,7 +88,6 @@ app.get('/' + path + '/*', (req, res) => { /* Debbug comment const a = unified() .use(remark) - .use(mermaid) .use(lineInput) .use(textInput) .use(html, {allowDangerousHTML: true}) diff --git a/public/index.html b/public/index.html index 3174635..7f0e040 100644 --- a/public/index.html +++ b/public/index.html @@ -6,10 +6,8 @@ markdown-viewer - 🐇 - - @@ -19,8 +17,8 @@
-
-
+
+

Fichiers

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; } -- cgit v1.2.3