Last active
May 25, 2017 16:30
-
-
Save AshleyGrant/987c319525ddc11f3ce6faf4094224a8 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> | |
| <svg width="550" height="550" | |
| mousedown.trigger="mouseDown($event)" | |
| mousemove.trigger="mouseMove($event)" | |
| mouseup.trigger="mouseUp($event)" | |
| > | |
| <rect repeat.for="box of boxes" | |
| data-id.bind="box.id" | |
| x.bind="box.x" | |
| y.bind="box.y" | |
| width="20" | |
| height="20" | |
| stroke="black" | |
| fill.bind="box.id == currentId ? '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
| 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
| <template> | |
| <rect | |
| dataId.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> | |
| </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 Box { | |
| @bindable box; | |
| @bindable selected; | |
| } |
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment