This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/d-checkbox.js.es6
2018-06-15 17:03:24 +02:00

26 lines
664 B
JavaScript

import { on } from "ember-addons/ember-computed-decorators";
export default Ember.Component.extend({
tagName: "label",
@on("didInsertElement")
_init() {
const checked = this.get("checked");
if (checked && checked !== "false") {
this.$("input").prop("checked", true);
}
// In Ember 13.3 we can use action on the checkbox `{{input}}` but not in 1.11
this.$("input").on("click.d-checkbox", () => {
Ember.run.scheduleOnce("afterRender", () =>
this.sendAction("change", this.$("input").prop("checked"))
);
});
},
@on("willDestroyElement")
_clear() {
this.$("input").off("click.d-checkbox");
}
});