Skip to content

Instantly share code, notes, and snippets.

@davismj
Created March 22, 2017 06:41
Show Gist options
  • Select an option

  • Save davismj/91991065de1b11e816893d82bde6f9c1 to your computer and use it in GitHub Desktop.

Select an option

Save davismj/91991065de1b11e816893d82bde6f9c1 to your computer and use it in GitHub Desktop.
import { inject } from 'aurelia-framework';
@inject(Element)
export class CustomDroppableCustomAttribute {
constructor(Element) {
this.element = Element;
}
attached() {
this.element.addEventListener('dragstart', this.enableDropzones);
this.element.addEventListener('dragenter', this.enableDropzones);
this.element.addEventListener('dragend', this.disableDropzones);
this.element.addEventListener('dragleave', this.disableDropzones);
}
detatched() {
this.element.removeEventListener('dragstart', this.enableDropzones);
this.element.removeEventListener('dragenter', this.enableDropzones);
this.element.removeEventListener('dragend', this.disableDropzones);
this.element.removeEventListener('dragleave', this.disableDropzones);
}
enableDropzones(event) {
// do what you do
}
disableDropzones(event) {
// stop doing it
}
}
<template>
<row custom-droppable>
<field name="name" custom-draggable></field>
<field name="produkt" custom-draggable></field>
</row>
<row custom-droppable></row>
</template>
// This is an alternative method that scopes the event aggregator
import { NewInstance, inject } from 'aurelia-framework';
import { EventAggregator } from 'aurelia-event-aggregator';
// Injecting a new instance of the event aggregator will prevent events from bubbling
// above this element, enabling you to scope events from children within this particular
// element. I recommend against this as you can typically achieve a better scoping pattern
// using native events. The event aggregator is best used for highly decoupled,
// application-wide eventing.
@inject(NewInstance.of(EventAggregator))
export class RowCustomElement {
constructor(EventAggregator) {
this.ea = EventAggregator;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment