89 lines
2.3 KiB
HTML
89 lines
2.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>fa-diagrams example</title>
|
|
<script src="http://code.jquery.com/jquery-3.4.1.min.js"></script>
|
|
<script src="github-cdn.js"></script>
|
|
<script src="toml-parser.js"></script>
|
|
<style>
|
|
* {
|
|
padding: 0;
|
|
margin: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
html, body {
|
|
height: 100vh;
|
|
background: none;
|
|
}
|
|
|
|
#left {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
width: calc(30% - 5px);
|
|
height: 100vh;
|
|
border-right: 5px solid #333;
|
|
}
|
|
|
|
#right {
|
|
position: absolute;
|
|
top: 0;
|
|
right: 0;
|
|
width: 70%;
|
|
height: 100vh;
|
|
}
|
|
|
|
#input {
|
|
width: 100%;
|
|
height: 100vh;
|
|
padding: 1em;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="left">
|
|
<textarea id="input" autocomplete="false" spellcheck="false"></textarea>
|
|
</div>
|
|
<div id="right"></div>
|
|
<script>
|
|
$(document).ready(() => {
|
|
|
|
github('klemek/fa-diagrams').loadScripts('dist/fa-diagrams-data.min.js', 'dist/fa-diagrams.min.js').then(() => {
|
|
|
|
$.get('sample.toml', (data) => {
|
|
$('#input').val(data).trigger('paste');
|
|
});
|
|
|
|
let timeout;
|
|
$('#input').on('change keyup paste', () => {
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(() => {
|
|
try {
|
|
const findLineBreaks = (data) => {
|
|
Object.keys(data).forEach(key => {
|
|
if (typeof data[key] === 'object')
|
|
findLineBreaks(data[key]);
|
|
else if (typeof data[key] === 'string')
|
|
data[key] = data[key].replace(/\\n/gm, '\n');
|
|
});
|
|
};
|
|
const parser = new TOMLParser();
|
|
parser.parse($('#input').val());
|
|
let data = parser.finish();
|
|
console.log(data);
|
|
findLineBreaks(data);
|
|
$('#right').html(faDiagrams.compute(data));
|
|
} catch (err) {
|
|
$('#right').html(`<h2>${err.toString().replace(/\n/gm, '<br>')}</h2>`);
|
|
console.error(err);
|
|
}
|
|
}, 500);
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|