mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-29 22:53:00 +00:00 
			
		
		
		
	add invert parameter to checkbox plugin
for when you want a tag to denote the lack of a check rather than the presence of one.
This commit is contained in:
		| @@ -58,8 +58,12 @@ CheckboxWidget.prototype.getValue = function() { | |||||||
| 	var tiddler = this.wiki.getTiddler(this.checkboxTitle); | 	var tiddler = this.wiki.getTiddler(this.checkboxTitle); | ||||||
| 	if(tiddler) { | 	if(tiddler) { | ||||||
| 		if(this.checkboxTag) { | 		if(this.checkboxTag) { | ||||||
|  | 			if(this.checkboxInvert) { | ||||||
|  | 				return !tiddler.hasTag(this.checkboxTag); | ||||||
|  | 			} else { | ||||||
| 				return tiddler.hasTag(this.checkboxTag); | 				return tiddler.hasTag(this.checkboxTag); | ||||||
| 			} | 			} | ||||||
|  | 		} | ||||||
| 		if(this.checkboxField) { | 		if(this.checkboxField) { | ||||||
| 			var value = tiddler.fields[this.checkboxField] || this.checkboxDefault || ""; | 			var value = tiddler.fields[this.checkboxField] || this.checkboxDefault || ""; | ||||||
| 			if(value === this.checkboxChecked) { | 			if(value === this.checkboxChecked) { | ||||||
| @@ -90,15 +94,23 @@ CheckboxWidget.prototype.handleChangeEvent = function(event) { | |||||||
| 		tiddler = this.wiki.getTiddler(this.checkboxTitle), | 		tiddler = this.wiki.getTiddler(this.checkboxTitle), | ||||||
| 		fallbackFields = {text: ""}, | 		fallbackFields = {text: ""}, | ||||||
| 		newFields = {title: this.checkboxTitle}, | 		newFields = {title: this.checkboxTitle}, | ||||||
| 		hasChanged = false; | 		hasChanged = false, | ||||||
|  | 		tagCheck = false; | ||||||
|  | 	if(this.checkboxTag && this.checkboxInvert === "yes") { | ||||||
|  | 		tagCheck = tiddler.hasTag(this.checkboxTag) === checked; | ||||||
|  | 	} else { | ||||||
|  | 		tagCheck = tiddler.hasTag(this.checkboxTag) !== checked; | ||||||
|  | 	} | ||||||
| 	// Set the tag if specified | 	// Set the tag if specified | ||||||
| 	if(this.checkboxTag && (!tiddler || tiddler.hasTag(this.checkboxTag) !== checked)) { | 	if(this.checkboxTag && (!tiddler || tagCheck)) { | ||||||
| 		newFields.tags = tiddler ? (tiddler.fields.tags || []).slice(0) : []; | 		newFields.tags = tiddler ? (tiddler.fields.tags || []).slice(0) : []; | ||||||
| 		var pos = newFields.tags.indexOf(this.checkboxTag); | 		var pos = newFields.tags.indexOf(this.checkboxTag); | ||||||
| 		if(pos !== -1) { | 		if(pos !== -1) { | ||||||
| 			newFields.tags.splice(pos,1); | 			newFields.tags.splice(pos,1); | ||||||
| 		} | 		} | ||||||
| 		if(checked) { | 		if(this.checkboxInvert === "yes" && !checked) { | ||||||
|  | 			newFields.tags.push(this.checkboxTag); | ||||||
|  | 		} else if(this.checkboxInvert !== "yes" && checked) { | ||||||
| 			newFields.tags.push(this.checkboxTag); | 			newFields.tags.push(this.checkboxTag); | ||||||
| 		} | 		} | ||||||
| 		hasChanged = true; | 		hasChanged = true; | ||||||
| @@ -128,6 +140,7 @@ CheckboxWidget.prototype.execute = function() { | |||||||
| 	this.checkboxUnchecked = this.getAttribute("unchecked"); | 	this.checkboxUnchecked = this.getAttribute("unchecked"); | ||||||
| 	this.checkboxDefault = this.getAttribute("default"); | 	this.checkboxDefault = this.getAttribute("default"); | ||||||
| 	this.checkboxClass = this.getAttribute("class",""); | 	this.checkboxClass = this.getAttribute("class",""); | ||||||
|  | 	this.checkboxInvert = this.getAttribute("invert",""); | ||||||
| 	// Make the child widgets | 	// Make the child widgets | ||||||
| 	this.makeChildWidgets(); | 	this.makeChildWidgets(); | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 James Welford Anderson
					James Welford Anderson