-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
73 lines (69 loc) · 2.78 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Syntax Diagram</title>
<script type="text/javascript" src="js/libs/raphael-min.js"></script>
<script type="text/javascript" src="js/libs/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="js/libs/canvg-1.0.js"></script>
<script type="text/javascript" src="js/libs/rgbcolor.js"></script>
</head>
<body>
<a href="https://github.com/atomble/syntax-diagram">Project Homepage</a>
<div>
<textarea id="code" rows="15" cols="125"></textarea>
<br />
<input type="button" class="button" value="Create Diagram" id="create" />
</div>
<div id="diagram"></div>
<div id="svg-support" style="display:none">
<textarea id="svg" rows="15" cols="125" readonly></textarea>
<div>
<div>
<input type="checkbox" class="checkbox" value="checked" id="enable-raster" />
Bitmap Rendering
</div>
<canvas id="canvas" height="10"></canvas>
<br />
<a id="dl" href="#" target="_blank"></a>
</div>
</div>
<script src="js/syntax-diagram.min.js"></script>
<script type="text/javascript" src="js/libs/coffee-script.js"></script>
<script type="text/coffeescript" src="src/syntax-diagram.coffee"></script>
<script type="text/javascript">
$(document).ready(function(){
var supportsSvg = document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1");
function enableRasterize() {
return !!$("#enable-raster").attr("checked");
}
if (supportsSvg) {
$("#svg-support").css("display", "block");
}
function submit() {
try {
var d = SyntaxDiagram("diagram", $("#code").val());
var svg = $("#diagram").html();
$("#svg").val(svg);
try {
if (enableRasterize() && supportsSvg) {
var canvas = document.getElementById("canvas");
$(canvas).height(d.height).width(d.width);
canvg(canvas, svg);
var dl = document.getElementById("dl");
dl.href = document.getElementById("canvas").toDataURL();
dl.innerHTML = "Download";
}
} catch(e) {}
} catch (error) {
alert(error);
}
}
$("#create").click(submit);
$('#code').keydown(function (e) {
if (e.ctrlKey && e.keyCode == 13) submit();
});
});
</script>
</body>
</html>