mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +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:
parent
4d9e6831bb
commit
5cbe4c5317
@ -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);
|
||||||
};
|
};
|
||||||
@ -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;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user