mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-30 15:13:00 +00:00 
			
		
		
		
	Complete renaming the radio widget
This commit is contained in:
		| @@ -1,16 +1,16 @@ | |||||||
| /*\ | /*\ | ||||||
| title: $:/core/modules/widgets/fieldradio.js | title: $:/core/modules/widgets/radio.js | ||||||
| type: application/javascript | type: application/javascript | ||||||
| module-type: widget | module-type: widget | ||||||
|  |  | ||||||
| Fieldradio widget | Radio widget | ||||||
|  |  | ||||||
| Will set a field to the selected value: | Will set a field to the selected value: | ||||||
|  |  | ||||||
| ``` | ``` | ||||||
| 	<$fieldradio field="myfield" value="check 1">one</$fieldradio> | 	<$radio field="myfield" value="check 1">one</$radio> | ||||||
| 	<$fieldradio field="myfield" value="check 2">two</$fieldradio> | 	<$radio field="myfield" value="check 2">two</$radio> | ||||||
| 	<$fieldradio field="myfield" value="check 3">three</$fieldradio> | 	<$radio field="myfield" value="check 3">three</$radio> | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| |Parameter |Description |h | |Parameter |Description |h | ||||||
| @@ -29,19 +29,19 @@ Will set a field to the selected value: | |||||||
|  |  | ||||||
| var Widget = require("$:/core/modules/widgets/widget.js").widget; | var Widget = require("$:/core/modules/widgets/widget.js").widget; | ||||||
|  |  | ||||||
| var FieldradioWidget = function(parseTreeNode,options) { | var RadioWidget = function(parseTreeNode,options) { | ||||||
| 	this.initialise(parseTreeNode,options); | 	this.initialise(parseTreeNode,options); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| /* | /* | ||||||
| Inherit from the base widget class | Inherit from the base widget class | ||||||
| */ | */ | ||||||
| FieldradioWidget.prototype = new Widget(); | RadioWidget.prototype = new Widget(); | ||||||
|  |  | ||||||
| /* | /* | ||||||
| Render this widget into the DOM | Render this widget into the DOM | ||||||
| */ | */ | ||||||
| FieldradioWidget.prototype.render = function(parent,nextSibling) { | RadioWidget.prototype.render = function(parent,nextSibling) { | ||||||
| 	// Save the parent dom node | 	// Save the parent dom node | ||||||
| 	this.parentDomNode = parent; | 	this.parentDomNode = parent; | ||||||
| 	// Compute our attributes | 	// Compute our attributes | ||||||
| @@ -50,10 +50,10 @@ FieldradioWidget.prototype.render = function(parent,nextSibling) { | |||||||
| 	this.execute(); | 	this.execute(); | ||||||
| 	// Create our elements | 	// Create our elements | ||||||
| 	this.labelDomNode = this.document.createElement("label"); | 	this.labelDomNode = this.document.createElement("label"); | ||||||
| 	this.labelDomNode.setAttribute("class",this.fieldradioClass); | 	this.labelDomNode.setAttribute("class",this.radioClass); | ||||||
| 	this.inputDomNode = this.document.createElement("input"); | 	this.inputDomNode = this.document.createElement("input"); | ||||||
| 	this.inputDomNode.setAttribute("type","radio"); | 	this.inputDomNode.setAttribute("type","radio"); | ||||||
| 	if(this.getValue() == this.fieldradioValue) { | 	if(this.getValue() == this.radioValue) { | ||||||
| 		this.inputDomNode.setAttribute("checked","true"); | 		this.inputDomNode.setAttribute("checked","true"); | ||||||
| 	} | 	} | ||||||
| 	this.labelDomNode.appendChild(this.inputDomNode); | 	this.labelDomNode.appendChild(this.inputDomNode); | ||||||
| @@ -69,22 +69,22 @@ FieldradioWidget.prototype.render = function(parent,nextSibling) { | |||||||
| 	this.domNodes.push(this.labelDomNode); | 	this.domNodes.push(this.labelDomNode); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| FieldradioWidget.prototype.getValue = function() { | RadioWidget.prototype.getValue = function() { | ||||||
| 	var tiddler = this.wiki.getTiddler(this.fieldradioTitle); | 	var tiddler = this.wiki.getTiddler(this.radioTitle); | ||||||
| 	return tiddler && tiddler.getFieldString(this.fieldradioField); | 	return tiddler && tiddler.getFieldString(this.radioField); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| FieldradioWidget.prototype.setValue = function() { | RadioWidget.prototype.setValue = function() { | ||||||
| 	var tiddler = this.wiki.getTiddler(this.fieldradioTitle); | 	var tiddler = this.wiki.getTiddler(this.radioTitle); | ||||||
| 	if(this.fieldradioField == "") { | 	if(this.radioField == "") { | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	var addition = {}; | 	var addition = {}; | ||||||
| 	addition[this.fieldradioField] = this.fieldradioValue; | 	addition[this.radioField] = this.radioValue; | ||||||
| 	this.wiki.addTiddler(new $tw.Tiddler(tiddler,addition)); | 	this.wiki.addTiddler(new $tw.Tiddler(tiddler,addition)); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| FieldradioWidget.prototype.handleChangeEvent = function(event) { | RadioWidget.prototype.handleChangeEvent = function(event) { | ||||||
| 	if (this.inputDomNode.checked) { | 	if (this.inputDomNode.checked) { | ||||||
| 		this.setValue(); | 		this.setValue(); | ||||||
| 	} | 	} | ||||||
| @@ -93,16 +93,16 @@ FieldradioWidget.prototype.handleChangeEvent = function(event) { | |||||||
| /* | /* | ||||||
| Compute the internal state of the widget | Compute the internal state of the widget | ||||||
| */ | */ | ||||||
| FieldradioWidget.prototype.execute = function() { | RadioWidget.prototype.execute = function() { | ||||||
| 	// Get the parameters from the attributes | 	// Get the parameters from the attributes | ||||||
| 	this.fieldradioTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler")); | 	this.radioTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler")); | ||||||
| 	this.fieldradioField = this.getAttribute("field"); | 	this.radioField = this.getAttribute("field"); | ||||||
| 	this.fieldradioValue = this.getAttribute("value"); | 	this.radioValue = this.getAttribute("value"); | ||||||
| 	this.fieldradioClass = this.getAttribute("class",""); | 	this.radioClass = this.getAttribute("class",""); | ||||||
| 	if (this.fieldradioClass !== "") { | 	if (this.radioClass !== "") { | ||||||
| 		this.fieldradioClass += " "; | 		this.radioClass += " "; | ||||||
| 	} | 	} | ||||||
| 	this.fieldradioClass += "tw-fieldradio"; | 	this.radioClass += "tw-radio"; | ||||||
| 	// Make the child widgets | 	// Make the child widgets | ||||||
| 	this.makeChildWidgets(); | 	this.makeChildWidgets(); | ||||||
| }; | }; | ||||||
| @@ -110,14 +110,14 @@ FieldradioWidget.prototype.execute = function() { | |||||||
| /* | /* | ||||||
| Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering | Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering | ||||||
| */ | */ | ||||||
| FieldradioWidget.prototype.refresh = function(changedTiddlers) { | RadioWidget.prototype.refresh = function(changedTiddlers) { | ||||||
| 	var changedAttributes = this.computeAttributes(); | 	var changedAttributes = this.computeAttributes(); | ||||||
| 	if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.value || changedAttributes["class"]) { | 	if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.value || changedAttributes["class"]) { | ||||||
| 		this.refreshSelf(); | 		this.refreshSelf(); | ||||||
| 		return true; | 		return true; | ||||||
| 	} else { | 	} else { | ||||||
| 		var refreshed = false; | 		var refreshed = false; | ||||||
| 		if(changedTiddlers[this.fieldradioTitle]) { | 		if(changedTiddlers[this.radioTitle]) { | ||||||
| 			this.inputDomNode.checked = this.getValue(); | 			this.inputDomNode.checked = this.getValue(); | ||||||
| 			refreshed = true; | 			refreshed = true; | ||||||
| 		} | 		} | ||||||
| @@ -125,6 +125,6 @@ FieldradioWidget.prototype.refresh = function(changedTiddlers) { | |||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
| exports.fieldradio = FieldradioWidget; | exports.radio = RadioWidget; | ||||||
|  |  | ||||||
| })(); | })(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jermolene
					Jermolene