aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2018-02-02 03:55:35 +0100
committerache <ache@ache.one>2018-02-02 04:00:29 +0100
commitd779c44cba942604c3a141fe0aef3ccafa19b8d9 (patch)
treea296f2298e6a01fbbf8aba90ba5d72db650f43e2
parentImproving general readability (diff)
Removing unnecessary libraries
-rw-r--r--app.js3
-rw-r--r--public/index.html6
-rw-r--r--public/js/script.js94
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 = ' <script> mermaid.contentLoaded(); </script>';
+const useLandScript = '';
const userSide_Button = '<button class="raw_button" ><div><div>Raw</div></div></button></form>';
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 @@
<title>markdown-viewer - 🐇</title>
<link rel="icon" type="image/png" href="img/favicon.ico" />
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="js/script.js"></script>
<script src="js/qcm.js"></script>
- <script src="./mermaid.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css" crossorigin="anonymous">
@@ -19,8 +17,8 @@
<body>
<div>
- <div class="row">
- <div id="tree" class="tree">
+ <div id="mainRow" class="row">
+ <div id="tree">
<h4>Fichiers</h4>
</div>
<div id="md" class="view">
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;
}