Last active
December 8, 2020 02:49
-
-
Save djodonnell/7f48387124c7450f8a3a15429fb738da to your computer and use it in GitHub Desktop.
Ember InteractJS Simple Div
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 Controller from '@ember/controller'; | |
| import { tracked } from '@glimmer/tracking'; | |
| import { action } from '@ember/object'; | |
| import interact from 'interactjs'; | |
| export default class ApplicationController extends Controller { | |
| // initialise grid properties | |
| dragCardPositionDelta; | |
| // methods | |
| @action | |
| addCardInteraction(element) { | |
| this.boardElement = element; | |
| // make elements with a class of draggable | |
| this.draggableCards = interact('.draggable-card'); | |
| this.draggableCards.draggable({ | |
| origin: 'self', | |
| inertia: false, | |
| modifiers: [ | |
| interact.modifiers.restrict({ | |
| restriction: 'self' | |
| }) | |
| ], | |
| listeners: { | |
| start: this.dragStart, | |
| move: this.dragMove, | |
| end: this.dragEnd | |
| } | |
| }); | |
| } | |
| @action | |
| dragStart(event) { | |
| // modify dom to support dragging the element | |
| event.target.style.position = 'relative'; | |
| event.target.style.touchAction = 'none'; | |
| event.target.style.userSelect = 'none'; | |
| event.target.style.left = '0px'; | |
| event.target.style.top = '0px'; | |
| console.log('dragStart (card: ' + event.target.id + ')' ); | |
| this.dragCardPositionDelta = { dx: 0, dy: 0 }; | |
| }; | |
| @action | |
| dragMove(event) { | |
| console.log('dragMove()'); | |
| let dx = event.dx == null ? 0 : event.dx; | |
| let dy = event.dy == null ? 0 : event.dy; | |
| this.dragCardPositionDelta.dx += dx; | |
| this.dragCardPositionDelta.dy += dy; | |
| // debugger; | |
| event.target.style.transform = | |
| `translate( | |
| ${this.dragCardPositionDelta.dx}px, | |
| ${this.dragCardPositionDelta.dy}px | |
| )`; | |
| }; | |
| @action | |
| dragEnd(event, pointer) { | |
| console.log('dragEnd()'); | |
| console.dir(arguments); | |
| }; | |
| } |
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
| { | |
| "version": "0.17.1", | |
| "EmberENV": { | |
| "FEATURES": {}, | |
| "_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
| "_APPLICATION_TEMPLATE_WRAPPER": true, | |
| "_JQUERY_INTEGRATION": true | |
| }, | |
| "options": { | |
| "use_pods": false, | |
| "enable-testing": false | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
| "ember": "3.18.1", | |
| "ember-template-compiler": "3.18.1", | |
| "ember-testing": "3.18.1", | |
| "@ember/render-modifiers": "^1.0.2", | |
| "interactjs": "^1.10.1", | |
| }, | |
| "addons": { | |
| "@glimmer/component": "1.0.0" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment