mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-30 23:23:02 +00:00 
			
		
		
		
	More refactoring of relativedate implementation
This commit is contained in:
		| @@ -37,7 +37,7 @@ Trigger the timer when the relative date is put into the DOM | |||||||
| */ | */ | ||||||
| RelativeDateViewer.prototype.postRenderInDom = function() { | RelativeDateViewer.prototype.postRenderInDom = function() { | ||||||
| 	if(this.relativeDate) { | 	if(this.relativeDate) { | ||||||
| 		this.setTimer(); | 		this.update(); | ||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -60,12 +60,15 @@ RelativeDateViewer.prototype.setTimer = function() { | |||||||
| Update the relative date display, and trigger the timer for the next update | Update the relative date display, and trigger the timer for the next update | ||||||
| */ | */ | ||||||
| RelativeDateViewer.prototype.update = function() { | RelativeDateViewer.prototype.update = function() { | ||||||
| 	while(this.viewMacro.child.domNode.hasChildNodes()) { |  | ||||||
| 		this.viewMacro.child.domNode.removeChild(this.viewMacro.child.domNode.firstChild); |  | ||||||
| 	} |  | ||||||
| 	this.relativeDate = $tw.utils.getRelativeDate((new Date()) - this.value); | 	this.relativeDate = $tw.utils.getRelativeDate((new Date()) - this.value); | ||||||
| 	this.viewMacro.child.domNode.appendChild(document.createTextNode(this.relativeDate.description)); | 	if(this.relativeDate.delta > 0) { | ||||||
| 	this.setTimer(); | console.log("updating",this.relativeDate.description); | ||||||
|  | 		while(this.viewMacro.child.domNode.hasChildNodes()) { | ||||||
|  | 			this.viewMacro.child.domNode.removeChild(this.viewMacro.child.domNode.firstChild); | ||||||
|  | 		} | ||||||
|  | 		this.viewMacro.child.domNode.appendChild(document.createTextNode(this.relativeDate.description)); | ||||||
|  | 		this.setTimer(); | ||||||
|  | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
| exports["relativedate"] = RelativeDateViewer; | exports["relativedate"] = RelativeDateViewer; | ||||||
|   | |||||||
| @@ -171,12 +171,14 @@ exports.getRelativeDate = function(delta) { | |||||||
| 		var result = Math.floor(delta / units[t].duration); | 		var result = Math.floor(delta / units[t].duration); | ||||||
| 		if(result >= 2) { | 		if(result >= 2) { | ||||||
| 			return { | 			return { | ||||||
|  | 				delta: delta, | ||||||
| 				description: result + " " + units[t].name + " ago", | 				description: result + " " + units[t].name + " ago", | ||||||
| 				updatePeriod: units[t].duration | 				updatePeriod: units[t].duration | ||||||
| 			}; | 			}; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return { | 	return { | ||||||
|  | 		delta: delta, | ||||||
| 		description: "1 second ago", | 		description: "1 second ago", | ||||||
| 		updatePeriod: 1000 | 		updatePeriod: 1000 | ||||||
| 	}; | 	}; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jeremy Ruston
					Jeremy Ruston