import { t } from "../services/i18n.js"; import NoteContextAwareWidget from "./note_context_aware_widget.js"; const TPL = `
`; export default class SwitchWidget extends NoteContextAwareWidget { switchOnName; switchOnTooltip; switchOffName; switchOffTooltip; currentState = false; doRender() { this.$widget = $(TPL); this.$switchButton = this.$widget.find(".switch-button"); this.$switchButton.on("click", () => this.toggle(!this.currentState)); this.$switchName = this.$widget.find(".switch-name"); this.$helpButton = this.$widget.find(".switch-help-button"); } toggle(state) { if (state) { this.switchOn(); } else { this.switchOff(); } } switchOff() {} switchOn() {} /** Gets or sets whether the switch is toggled. */ get isToggled() { return this.currentState; } set isToggled(state) { this.currentState = !!state; if (this.currentState) { this.$switchName.text(this.switchOffName); this.$switchButton.attr("title", this.switchOffTooltip); this.$switchButton.addClass("on"); } else { this.$switchName.text(this.switchOnName); this.$switchButton.attr("title", this.switchOnTooltip); this.$switchButton.removeClass("on"); } } }