aurelia-materialize-bridge
Version:
Aurelia interface to http://materializecss.com/
56 lines (44 loc) • 1.08 kB
text/typescript
import * as au from "../aurelia";
.customElement("md-switch")
.autoinject
export class MdSwitch {
constructor(private element: Element) { }
checkbox: HTMLInputElement;
.ato.bindable.booleanMd({ defaultBindingMode: au.bindingMode.twoWay })
checked: boolean;
checkedChanged(newValue: boolean) {
if (this.checkbox) {
this.checkbox.checked = !!newValue;
}
}
.ato.bindable.booleanMd
disabled: boolean;
disabledChanged() {
if (this.checkbox) {
this.checkbox.disabled = this.disabled;
}
}
.ato.bindable.booleanMd
readonly: boolean = false;
.bindable
labelOff: string = "Off";
.bindable
labelOn: string = "On";
attached() {
this.checkbox.checked = this.checked;
this.disabledChanged();
this.checkbox.addEventListener("change", this.handleChange);
}
detached() {
if (this.checkbox) {
this.checkbox.removeEventListener("change", this.handleChange);
}
}
handleChange = () => {
this.checked = this.checkbox.checked;
au.fireEvent(this.element, "blur");
}
blur() {
au.fireEvent(this.element, "blur");
}
}