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.$switchToggle = this.$widget.find(".switch-toggle"); this.$switchToggle.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; this.$switchButton.toggleClass("on", this.currentState); this.$switchToggle.prop("checked", this.currentState); if (this.currentState) { this.$switchName.text(this.switchOffName); this.$switchButton.attr("title", this.switchOffTooltip); } else { this.$switchName.text(this.switchOnName); this.$switchButton.attr("title", this.switchOnTooltip); } } }