1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 23:03:15 +00:00

Add radio actions, th-radio-variables hook and fix label refresh problem (#5154)

* Add actions to radio-widget, pass trhough all attributes and user parameters, fix label refresh

* invoke th-radio-hook instead of hardcoded variables

* simplify code and test it with a plugin hook

* remove hook
This commit is contained in:
Mario Pietsch 2020-11-30 18:28:49 +01:00 committed by GitHub
parent 4d9e6831bb
commit 5cbe4c5317
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,7 +13,6 @@ Set a field or index at a given tiddler via radio buttons
"use strict"; "use strict";
var Widget = require("$:/core/modules/widgets/widget.js").widget; var Widget = require("$:/core/modules/widgets/widget.js").widget;
var RadioWidget = function(parseTreeNode,options) { var RadioWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options); this.initialise(parseTreeNode,options);
}; };
@ -37,8 +36,8 @@ RadioWidget.prototype.render = function(parent,nextSibling) {
// Create our elements // Create our elements
this.labelDomNode = this.document.createElement("label"); this.labelDomNode = this.document.createElement("label");
this.labelDomNode.setAttribute("class", this.labelDomNode.setAttribute("class",
"tc-radio " + this.radioClass + (isChecked ? " tc-radio-selected" : "") "tc-radio " + this.radioClass + (isChecked ? " tc-radio-selected" : "")
); );
this.inputDomNode = this.document.createElement("input"); this.inputDomNode = this.document.createElement("input");
this.inputDomNode.setAttribute("type","radio"); this.inputDomNode.setAttribute("type","radio");
if(isChecked) { if(isChecked) {
@ -86,6 +85,10 @@ RadioWidget.prototype.handleChangeEvent = function(event) {
if(this.inputDomNode.checked) { if(this.inputDomNode.checked) {
this.setValue(); this.setValue();
} }
// Trigger actions
if(this.radioActions) {
this.invokeActionString(this.radioActions,this,event,{"actionValue": this.radioValue});
}
}; };
/* /*
@ -99,6 +102,7 @@ RadioWidget.prototype.execute = function() {
this.radioValue = this.getAttribute("value"); this.radioValue = this.getAttribute("value");
this.radioClass = this.getAttribute("class",""); this.radioClass = this.getAttribute("class","");
this.isDisabled = this.getAttribute("disabled","no"); this.isDisabled = this.getAttribute("disabled","no");
this.radioActions = this.getAttribute("actions","");
// Make the child widgets // Make the child widgets
this.makeChildWidgets(); this.makeChildWidgets();
}; };
@ -108,16 +112,11 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
*/ */
RadioWidget.prototype.refresh = function(changedTiddlers) { RadioWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes(); var changedAttributes = this.computeAttributes();
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.value || changedAttributes["class"] || changedAttributes.disabled) { if(($tw.utils.count(changedAttributes) > 0) || changedTiddlers[this.radioTitle]) {
this.refreshSelf(); this.refreshSelf();
return true; return true;
} else { } else {
var refreshed = false; return this.refreshChildren(changedTiddlers);
if(changedTiddlers[this.radioTitle]) {
this.inputDomNode.checked = this.getValue() === this.radioValue;
refreshed = true;
}
return this.refreshChildren(changedTiddlers) || refreshed;
} }
}; };