Last active
May 25, 2017 16:46
-
-
Save AshleyGrant/8cff50b9312b448bf4807c43b6f4b29f to your computer and use it in GitHub Desktop.
Aurelia Gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <require from="./my-box"></require> | |
| <svg width="550" height="550" | |
| mousedown.trigger="mouseDown($event)" | |
| mousemove.trigger="mouseMove($event)" | |
| mouseup.trigger="mouseUp($event)" | |
| > | |
| <my-box repeat.for="box of boxes" | |
| box.bind="box" | |
| selected.bind="box.id === currentId"> | |
| </my-box> | |
| </svg> | |
| </template> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getRandomInt(min, max) { | |
| return Math.floor(Math.random() * (max - min)) + min; | |
| } | |
| export class App { | |
| currentId = null; | |
| boxes = []; | |
| offsetX; | |
| offsetY; | |
| attached() { | |
| for (let i=0; i < 10000; i++) { | |
| const id = i; | |
| const x = getRandomInt(0, 500); | |
| const y = getRandomInt(0, 500); | |
| const box = { | |
| id, | |
| x, | |
| y | |
| }; | |
| this.boxes.push(box); | |
| } | |
| } | |
| mouseDown(event) { | |
| const id = Number(event.target.getAttribute("data-id")); | |
| const box = this.boxes[id]; | |
| const mouseX = event.clientX; | |
| const mouseY = event.clientY; | |
| this.offsetX = box.x - mouseX; | |
| this.offsetY = box.y - mouseY; | |
| this.currentId = id; | |
| } | |
| mouseMove(event) { | |
| event.preventDefault(); | |
| if (this.currentId !== null) { | |
| this.updateBox(this.currentId, event.clientX + this.offsetX, event.clientY + this.offsetY); | |
| } | |
| } | |
| mouseUp($event) { | |
| this.currentId = null; | |
| } | |
| updateBox(id, x, y) { | |
| const box = this.boxes[id]; | |
| box.x = x; | |
| box.y = y; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>Aurelia</title> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| </head> | |
| <body aurelia-app> | |
| <h1>Loading...</h1> | |
| <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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <svg> | |
| <rect | |
| data-id.bind="box.id" | |
| x.bind="box.x" | |
| y.bind="box.y" | |
| width="20" | |
| height="20" | |
| stroke="black" | |
| fill.bind="selected ? 'red' : 'transparent'" | |
| strokeWidth="1"></rect></svg> | |
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {bindable, containerless} from 'aurelia-framework'; | |
| @containerless() | |
| export class MyBox { | |
| @bindable box; | |
| @bindable selected; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment