Skip to content

Instantly share code, notes, and snippets.

@bigopon
Last active August 16, 2017 04:41
Show Gist options
  • Save bigopon/d8f5d1eb66a3757e886e768ab95e10b0 to your computer and use it in GitHub Desktop.
Save bigopon/d8f5d1eb66a3757e886e768ab95e10b0 to your computer and use it in GitHub Desktop.
Aurelia adjusted EventManger & Listener
<template>
<require from="./my-canvas"></require>
<select value.bind='drawInstruction'>
<option repeat.for='draw of draws' value.bind='draw'>${draw}</option>
</select>
<my-canvas draw-instruction.bind='drawInstruction'></my-canvas>
</template>
// import './no-break-adjusted-events'
export class App {
draws = [
'Arrow',
'Ellipse'
]
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<style>
body {
padding: 20px;
}
.form-component {
display: block;
margin-bottom: 20px;
}
</style>
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jcanvas/20.1.2/min/jcanvas.min.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
<script>
require(['aurelia-bootstrapper']);
</script>
</body>
</html>
<template css="display: block; width: ${size}px; height: ${size}px">
<canvas width.bind='size' height.bind='size' ref='canvas'></canvas>
</template>
import { bindable } from 'aurelia-framework';
export class MyCanvas {
@bindable drawInstruction
@bindable size = 300
canvas; // reference to canvas element will be assigned by framework
bind() {
this.$canvas = $(this.canvas);
}
drawInstructionChanged(newVal) {
this.$canvas.clearCanvas()
this['draw' + newVal] && this['draw' + newVal]();
}
drawArrow() {
this.$canvas.drawLine({
strokeStyle: '#000',
strokeWidth: 4,
rounded: true,
startArrow: true,
arrowRadius: 15,
arrowAngle: 90,
x1: 100, y1: 100,
x2: 150, y2: 125,
x3: 200, y3: 75
});
}
drawEllipse() {
this.$canvas.drawEllipse({
fillStyle: '#c33',
x: 150, y: 100,
width: 200, height: 100
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment