kopia lustrzana https://github.com/miklobit/TiddlyWiki5
				
				
				
			Add "index" attribute to range widget
							rodzic
							
								
									7beee4f9ce
								
							
						
					
					
						commit
						bfbd886a8b
					
				|  | @ -61,10 +61,14 @@ RangeWidget.prototype.getValue = function() { | ||||||
| 		fieldName = this.tiddlerField || "text", | 		fieldName = this.tiddlerField || "text", | ||||||
| 		value   = this.defaultValue; | 		value   = this.defaultValue; | ||||||
| 	if(tiddler) { | 	if(tiddler) { | ||||||
| 		if($tw.utils.hop(tiddler.fields,fieldName)) { | 		if(this.tiddlerIndex) { | ||||||
| 			value = tiddler.fields[fieldName] || ""; | 			value = this.wiki.extractTiddlerDataItem(tiddler,this.tiddlerIndex,this.defaultValue || ""); | ||||||
| 		} else { | 		} else { | ||||||
| 			value = this.defaultValue || ""; | 			if($tw.utils.hop(tiddler.fields,fieldName)) { | ||||||
|  | 				value = tiddler.fields[fieldName] || ""; | ||||||
|  | 			} else { | ||||||
|  | 				value = this.defaultValue || ""; | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return value; | 	return value; | ||||||
|  | @ -72,7 +76,11 @@ RangeWidget.prototype.getValue = function() { | ||||||
| 
 | 
 | ||||||
| RangeWidget.prototype.handleInputEvent = function(event) { | RangeWidget.prototype.handleInputEvent = function(event) { | ||||||
| 	if(this.getValue() !== this.inputDomNode.value) { | 	if(this.getValue() !== this.inputDomNode.value) { | ||||||
| 		this.wiki.setText(this.tiddlerTitle,this.tiddlerField,null,this.inputDomNode.value); | 		if(this.tiddlerIndex) { | ||||||
|  | 			this.wiki.setText(this.tiddlerTitle,"",this.tiddlerIndex,this.inputDomNode.value); | ||||||
|  | 		} else { | ||||||
|  | 			this.wiki.setText(this.tiddlerTitle,this.tiddlerField,null,this.inputDomNode.value); | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | @ -83,6 +91,7 @@ RangeWidget.prototype.execute = function() { | ||||||
| 	// Get the parameters from the attributes
 | 	// Get the parameters from the attributes
 | ||||||
| 	this.tiddlerTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler")); | 	this.tiddlerTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler")); | ||||||
| 	this.tiddlerField = this.getAttribute("field"); | 	this.tiddlerField = this.getAttribute("field"); | ||||||
|  | 	this.tiddlerIndex = this.getAttribute("index"); | ||||||
| 	this.minValue = this.getAttribute("min"); | 	this.minValue = this.getAttribute("min"); | ||||||
| 	this.maxValue = this.getAttribute("max"); | 	this.maxValue = this.getAttribute("max"); | ||||||
| 	this.increment = this.getAttribute("increment"); | 	this.increment = this.getAttribute("increment"); | ||||||
|  | @ -97,7 +106,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of | ||||||
| */ | */ | ||||||
| RangeWidget.prototype.refresh = function(changedTiddlers) { | RangeWidget.prototype.refresh = function(changedTiddlers) { | ||||||
| 	var changedAttributes = this.computeAttributes(); | 	var changedAttributes = this.computeAttributes(); | ||||||
| 	if(changedAttributes.tiddler || changedAttributes.field || changedAttributes['min'] || changedAttributes['max'] || changedAttributes['increment'] || changedAttributes["default"] || changedAttributes["class"]) { | 	if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes['min'] || changedAttributes['max'] || changedAttributes['increment'] || changedAttributes["default"] || changedAttributes["class"]) { | ||||||
| 		this.refreshSelf(); | 		this.refreshSelf(); | ||||||
| 		return true; | 		return true; | ||||||
| 	} else { | 	} else { | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| caption: range | caption: range | ||||||
| created: 20171102134825376 | created: 20171102134825376 | ||||||
| modified: 20180425132848231 | modified: 20191104185454972 | ||||||
| tags: Widgets | tags: Widgets | ||||||
| title: RangeWidget | title: RangeWidget | ||||||
| type: text/vnd.tiddlywiki | type: text/vnd.tiddlywiki | ||||||
|  | @ -15,11 +15,12 @@ The content of the `<$range>` widget is ignored. | ||||||
| 
 | 
 | ||||||
| |!Attribute |!Description | | |!Attribute |!Description | | ||||||
| |tiddler |Title of the tiddler to manipulate (defaults to the [[current tiddler|Current Tiddler]]) | | |tiddler |Title of the tiddler to manipulate (defaults to the [[current tiddler|Current Tiddler]]) | | ||||||
| |field |The field of the //tiddler// bound to the radio button| | |field |The field of the //tiddler// bound to the radio button | | ||||||
| |min |The minimum value to be able to be set by the `<$range>` widget.| | |index|<<.from-version "5.1.22">> The index of the //tiddler//, a [[DataTiddler|DataTiddlers]], to which the radio button is bound<<.tip "be sure to set the //tiddler// correctly">> | | ||||||
| |max |The maximum value to be able to be set by the `<$range>` widget.| | |min |The minimum value to be able to be set by the `<$range>` widget | | ||||||
| |increment |The minimum amount by which a value may be changed.  Defaults to 1.| | |max |The maximum value to be able to be set by the `<$range>` widget | | ||||||
| |default |The default value displayed if the field is missing or empty.| | |increment |The minimum amount by which a value may be changed.  Defaults to 1 | | ||||||
|  | |default |The default value displayed if the field is missing or empty | | ||||||
| |class |CSS classes to be assigned to the label around the radio button | | |class |CSS classes to be assigned to the label around the radio button | | ||||||
| 
 | 
 | ||||||
| ! Examples | ! Examples | ||||||
|  |  | ||||||
		Ładowanie…
	
		Reference in New Issue
	
	 Jeremy Ruston
						Jeremy Ruston