mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-31 15:42:59 +00:00 
			
		
		
		
	Add "info" widget for displaying information about tiddlers
Currently only supports displaying the changecount of a tiddler
This commit is contained in:
		
							
								
								
									
										50
									
								
								core/modules/widgets/info.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								core/modules/widgets/info.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | |||||||
|  | /*\ | ||||||
|  | title: $:/core/modules/widget/info.js | ||||||
|  | type: application/javascript | ||||||
|  | module-type: widget | ||||||
|  |  | ||||||
|  | Implements the info widget that displays various information about a specified tiddler. | ||||||
|  |  | ||||||
|  | \*/ | ||||||
|  | (function(){ | ||||||
|  |  | ||||||
|  | /*jslint node: true, browser: true */ | ||||||
|  | /*global $tw: false */ | ||||||
|  | "use strict"; | ||||||
|  |  | ||||||
|  | var InfoWidget = function(renderer) { | ||||||
|  | 	// Save state | ||||||
|  | 	this.renderer = renderer; | ||||||
|  | 	// Generate child nodes | ||||||
|  | 	this.generate(); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | InfoWidget.types = { | ||||||
|  | 	changecount: function(options) {return options.wiki.getChangeCount(options.title);} | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | InfoWidget.prototype.generate = function() { | ||||||
|  | 	// Get attributes | ||||||
|  | 	this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.getContextTiddlerTitle()); | ||||||
|  | 	this.type = this.renderer.getAttribute("type","changecount"); | ||||||
|  | 	// Get the appropriate value for the current tiddler | ||||||
|  | 	var value = "", | ||||||
|  | 		fn = InfoWidget.types[this.type]; | ||||||
|  | 	if(fn) { | ||||||
|  | 		value = fn({ | ||||||
|  | 			wiki: this.renderer.renderTree.wiki, | ||||||
|  | 			title: this.tiddlerTitle | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
|  | 	// Set the element | ||||||
|  | 	this.tag = "span"; | ||||||
|  | 	this.attributes = {}; | ||||||
|  | 	this.children = this.renderer.renderTree.createRenderers(this.renderer.renderContext,[{ | ||||||
|  | 		type: "text", | ||||||
|  | 		text: value | ||||||
|  | 	}]); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | exports.info = InfoWidget; | ||||||
|  |  | ||||||
|  | })(); | ||||||
		Reference in New Issue
	
	Block a user
	 Jeremy Ruston
					Jeremy Ruston