1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import EventSystem from './EventSystem';
- export default class Mouse extends EventSystem{
- constructor(container = window){
- super()
- this.container = container;
- }
- handler(e) {
- switch(e.button){
- case 0:
- this.emit('LeftDown',e);
- break;
- case 2:
- this.emit('RightDown',e);
- break;
- default:
- console.log('sss')
- break;
- }
- }
- dropHandler(event) {
- let data = event.dataTransfer.getData('MyObject');
- this.emit('Drop', {
- event,
- data
- });
- }
- droppable(droppable = true) {
- this.isDroppable = droppable;
- return this;
- }
- cancel(e) { e.preventDefault(); }
- listen(){
- console.log(this)
- this.container.addEventListener('mousedown', this.handler.bind(this));
- if(this.isDroppable) {
- this.container.addEventListener('dragover', this.cancel);
- this.container.addEventListener('drop', this.dropHandler.bind(this));
- }
- return this;
- }
- }
|