Created
April 28, 2016 18:52
-
-
Save toddwprice/60a70f49054aa2ec00bece9b02a00e08 to your computer and use it in GitHub Desktop.
This file contains 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 {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