12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 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(){
- 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;
- }
- }
|