From c886cfe6f58bf053c72814fbcea2c5b0378dda15 Mon Sep 17 00:00:00 2001 From: Leilei332 Date: Sun, 15 Dec 2024 00:40:31 +0800 Subject: [PATCH 1/7] Add disabled parameter to select widget and browse widget (#8816) * Add disabled parameter to select widget and browse widget * Add disabled attribute to edit-shortcut --- core/modules/widgets/browse.js | 4 ++++ core/modules/widgets/edit-shortcut.js | 6 +++++- core/modules/widgets/select.js | 6 +++++- editions/tw5.com/tiddlers/widgets/BrowseWidget.tid | 1 + editions/tw5.com/tiddlers/widgets/SelectWidget.tid | 1 + 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/modules/widgets/browse.js b/core/modules/widgets/browse.js index 8130825b0..faff40e69 100644 --- a/core/modules/widgets/browse.js +++ b/core/modules/widgets/browse.js @@ -56,6 +56,9 @@ BrowseWidget.prototype.render = function(parent,nextSibling) { if(this.nwdirectory) { domNode.setAttribute("nwdirectory",this.nwdirectory); } + if(this.isDisabled === "yes") { + domNode.setAttribute("disabled", true); + } // Add a click event handler domNode.addEventListener("change",function (event) { if(self.message) { @@ -94,6 +97,7 @@ BrowseWidget.prototype.execute = function() { this.accept = this.getAttribute("accept"); this.webkitdirectory = this.getAttribute("webkitdirectory"); this.nwdirectory = this.getAttribute("nwdirectory"); + this.isDisabled = this.getAttribute("disabled", "no"); }; /* diff --git a/core/modules/widgets/edit-shortcut.js b/core/modules/widgets/edit-shortcut.js index 31d81b6b8..1935b2337 100644 --- a/core/modules/widgets/edit-shortcut.js +++ b/core/modules/widgets/edit-shortcut.js @@ -48,6 +48,9 @@ EditShortcutWidget.prototype.render = function(parent,nextSibling) { if(this.shortcutAriaLabel) { this.inputNode.setAttribute("aria-label",this.shortcutAriaLabel); } + if(this.isDisabled === "yes") { + this.inputNode.setAttribute("disabled", true); + } // Assign the current shortcut this.updateInputNode(); // Add event handlers @@ -77,6 +80,7 @@ EditShortcutWidget.prototype.execute = function() { this.shortcutTooltip = this.getAttribute("tooltip"); this.shortcutAriaLabel = this.getAttribute("aria-label"); this.shortcutFocus = this.getAttribute("focus"); + this.isDisabled = this.getAttribute("disabled", "no"); }; /* @@ -138,7 +142,7 @@ Selectively refreshes the widget if needed. Returns true if the widget needed re */ EditShortcutWidget.prototype.refresh = function(changedTiddlers) { var changedAttributes = this.computeAttributes(); - if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.placeholder || changedAttributes["default"] || changedAttributes["class"] || changedAttributes.style || changedAttributes.tooltip || changedAttributes["aria-label"] || changedAttributes.focus) { + if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.placeholder || changedAttributes["default"] || changedAttributes["class"] || changedAttributes.style || changedAttributes.tooltip || changedAttributes["aria-label"] || changedAttributes.focus || changedAttributes.disabled) { this.refreshSelf(); return true; } else if(changedTiddlers[this.shortcutTiddler]) { diff --git a/core/modules/widgets/select.js b/core/modules/widgets/select.js index 2940e3be0..f58a11891 100644 --- a/core/modules/widgets/select.js +++ b/core/modules/widgets/select.js @@ -53,6 +53,9 @@ SelectWidget.prototype.render = function(parent,nextSibling) { if(this.selectMultiple) { domNode.setAttribute("multiple","multiple"); } + if(this.isDisabled === "yes") { + domNode.setAttribute("disabled", true); + } if(this.selectSize) { domNode.setAttribute("size",this.selectSize); } @@ -172,6 +175,7 @@ SelectWidget.prototype.execute = function() { this.selectTabindex = this.getAttribute("tabindex"); this.selectTooltip = this.getAttribute("tooltip"); this.selectFocus = this.getAttribute("focus"); + this.isDisabled = this.getAttribute("disabled","no"); // Make the child widgets this.makeChildWidgets(); }; @@ -182,7 +186,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of SelectWidget.prototype.refresh = function(changedTiddlers) { var changedAttributes = this.computeAttributes(); // If we're using a different tiddler/field/index then completely refresh ourselves - if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.tooltip || changedAttributes.tabindex) { + if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.tooltip || changedAttributes.tabindex || changedAttributes.disabled) { this.refreshSelf(); return true; } else { diff --git a/editions/tw5.com/tiddlers/widgets/BrowseWidget.tid b/editions/tw5.com/tiddlers/widgets/BrowseWidget.tid index b0364a71a..ec8f098e4 100644 --- a/editions/tw5.com/tiddlers/widgets/BrowseWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/BrowseWidget.tid @@ -20,6 +20,7 @@ The content of the <<.wid BrowseWidget>> widget is ignored. |accept |<<.from-version "5.1.23">> Optional comma delimited [[list of file accepted extensions|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers]] and/or MIME types | |message |Optional override of widget message to be generated. The files will be passed in the JavaScript object `event.target.files` | |param |Optional parameter to be passed with the custom message | +|disabled |<<.from-version "5.3.7">> Optional. Set to "yes" to disable file browser. Defaults to "no". | |data-* |<<.from-version "5.3.2">> Optional [[data attributes|https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes]] to be assigned to the HTML element | |style.* |<<.from-version "5.3.2">> Optional [[CSS properties|https://developer.mozilla.org/en-US/docs/Web/CSS/Reference]] to be assigned to the HTML element | diff --git a/editions/tw5.com/tiddlers/widgets/SelectWidget.tid b/editions/tw5.com/tiddlers/widgets/SelectWidget.tid index 210b1d823..515c95c3c 100644 --- a/editions/tw5.com/tiddlers/widgets/SelectWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/SelectWidget.tid @@ -42,6 +42,7 @@ The content of the `<$select>` widget should be one or more HTML `