@wise-community/drawing-tool
Version:
HTML5 Drawing Tool
81 lines (80 loc) • 3.3 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML5 Drawing Tool Demo</title>
<style type="text/css">
body {
font-family: Arial;
}
</style>
</head>
<body>
<div class="container">
<div id="drawing-tool"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.5.0/fabric.js"></script>
<link type="text/css" rel="stylesheet" href="../drawing-tool.css" />
<script src="../drawing-tool.js"></script>
<script>
var drawingTool = new DrawingTool("#drawing-tool", {
stamps: {
'Molecules': [
'https://interactions-resources.concord.org/stamps/simple-atom.svg',
'https://interactions-resources.concord.org/stamps/diatomic.svg',
'https://interactions-resources.concord.org/stamps/diatomic-red.svg',
'https://interactions-resources.concord.org/stamps/triatomic.svg',
'https://interactions-resources.concord.org/stamps/positive-atom.svg',
'https://interactions-resources.concord.org/stamps/negative-atom.svg',
'https://interactions-resources.concord.org/stamps/slow-particle.svg',
'https://interactions-resources.concord.org/stamps/medium-particle.svg',
'https://interactions-resources.concord.org/stamps/fast-particle.svg',
'https://interactions-resources.concord.org/stamps/low-density-particles.svg'
],
'Second Molecules': [
'https://interactions-resources.concord.org/stamps/simple-atom.svg',
'https://interactions-resources.concord.org/stamps/diatomic.svg',
'https://interactions-resources.concord.org/stamps/diatomic-red.svg',
'https://interactions-resources.concord.org/stamps/triatomic.svg',
'https://interactions-resources.concord.org/stamps/positive-atom.svg',
'https://interactions-resources.concord.org/stamps/negative-atom.svg',
'https://interactions-resources.concord.org/stamps/slow-particle.svg',
'https://interactions-resources.concord.org/stamps/medium-particle.svg',
'https://interactions-resources.concord.org/stamps/fast-particle.svg',
'https://interactions-resources.concord.org/stamps/low-density-particles.svg'
]
},
parseSVG: true,
separatorsAfter: [
"stamp",
"strokeWidthPalette"
]
});
var state = null;
$("#set-background").on("click", function () {
drawingTool.setBackgroundImage($("#background-src").val());
});
$("#resize-background").on("click", function () {
drawingTool.resizeBackgroundToCanvas();
});
$("#resize-canvas").on("click", function () {
drawingTool.resizeCanvasToBackground();
});
$("#shrink-background").on("click", function () {
drawingTool.shrinkBackgroundToCanvas();
});
$("#clear").on("click", function () {
drawingTool.clear(true);
});
$("#save").on("click", function () {
state = drawingTool.save();
$("#load").removeAttr("disabled");
});
$("#load").on("click", function () {
if (state === null) return;
drawingTool.load(state);
});
</script>
</body>
</html>