Skip to content

Instantly share code, notes, and snippets.

@toddwprice
Created April 28, 2016 18:52
Show Gist options
  • Save toddwprice/60a70f49054aa2ec00bece9b02a00e08 to your computer and use it in GitHub Desktop.
Save toddwprice/60a70f49054aa2ec00bece9b02a00e08 to your computer and use it in GitHub Desktop.
import {inject, customAttribute} from 'aurelia-framework';
import pikaday from 'pikaday';
@customAttribute('datepicker')
@inject(Element)
export class DatePicker {
constructor(element) {
this.element = element;
}
attached() {
// console.log(Pikaday);
var picker = new pikaday({ field: this.element });
$(this.element).on('change', e => fireEvent(e.target, 'input'));
}
detached() {
$(this.element).off('change');
}
}
function createEvent(name) {
var event = document.createEvent('Event');
event.initEvent(name, true, true);
return event;
}
function fireEvent(element, name) {
var event = createEvent(name);
element.dispatchEvent(event);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment