Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client: switch widget: handle the disabled state
Adorian Dorand4ef84e0b72f
diff --git a/src/public/app/widgets/shared_switch.js b/src/public/app/widgets/shared_switch.jsindex e739ecf328..90d2e7e9e3 100644--- a/src/public/app/widgets/shared_switch.js+++ b/src/public/app/widgets/shared_switch.js@@ -56,11 +56,11 @@ export default class SharedSwitchWidget extends SwitchWidget {this.isToggled = isShared;if (switchDisabled) {- //this.$widget.attr("title", t("shared_switch.inherited"));- //this.$switchOff.addClass("switch-disabled");+ this.disabledTooltip = t("shared_switch.inherited");+ this.canToggle = false;} else {- //this.$widget.removeAttr("title");- //this.$switchOff.removeClass("switch-disabled");+ this.disabledTooltip = "";+ this.canToggle = true;}}diff --git a/src/public/app/widgets/switch.js b/src/public/app/widgets/switch.jsindex e9983d5e36..45a0a03075 100644--- a/src/public/app/widgets/switch.js+++ b/src/public/app/widgets/switch.js@@ -28,7 +28,6 @@ const TPL = `border-radius: 24px;background-color: var(--switch-off-track-background);transition: background 200ms ease-in;- cursor: pointer;}.switch-widget .switch-button.on {@@ -61,13 +60,17 @@ const TPL = `background 100ms ease-in;}- .switch-widget .switch-button > input[type="checkbox"] {+ .switch-widget .switch-button input[type="checkbox"] {position: absolute:top: 0;left: 0;width: 100%;height: 100%;opacity: 0;+ }++ .switch-widget .switch-button:not(.disabled) input[type="checkbox"],+ .switch-widget .switch-button:not(.disabled) {cursor: pointer;}@@ -76,9 +79,8 @@ const TPL = `outline-offset: 2px;}- .switch-widget .switch-disabled {+ .switch-widget .switch-button.disabled {opacity: 70%;- pointer-events: none;}.switch-widget .switch-help-button {@@ -117,6 +119,8 @@ export default class SwitchWidget extends NoteContextAwareWidget {switchOffName;switchOffTooltip;+ disabledTooltip;+currentState = false;doRender() {@@ -167,4 +171,19 @@ export default class SwitchWidget extends NoteContextAwareWidget {this.$switchButton.attr("title", this.switchOnTooltip);}}++ get canToggle() {+ return (!this.$switchButton.hasClass("disabled"));+ }++ set canToggle(isEnabled) {+ this.$switchButton.toggleClass("disabled", !isEnabled);+ this.$switchToggle.attr("disabled", !isEnabled);++ if (isEnabled) {+ this.isToggled = this.currentState; // Reapply the correct tooltip+ } else {+ this.$switchButton.attr("title", this.disabledTooltip);+ }+ }}