mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-30 23:23:02 +00:00 
			
		
		
		
	Introduced new base class for Renderer nodes
Making the code a bit simpler
This commit is contained in:
		| @@ -11,6 +11,34 @@ Renderer objects | |||||||
|  |  | ||||||
| var utils = require("./Utils.js"); | var utils = require("./Utils.js"); | ||||||
|  |  | ||||||
|  | var Node = function(children) { | ||||||
|  | 	if(this instanceof Node) { | ||||||
|  | 		this.children = children; | ||||||
|  | 	} else { | ||||||
|  | 		return new Node(children); | ||||||
|  | 	} | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | Node.prototype.clone = function() { | ||||||
|  | 	// By default we don't actually clone nodes, we just re-use them (we do clone macros and elements) | ||||||
|  | 	return this; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | Node.prototype.execute = function(parents,tiddler) { | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | Node.prototype.render = function(type) { | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | Node.prototype.renderInDom = function(domNode) { | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | Node.prototype.refresh = function(changes) { | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | Node.prototype.refreshInDom = function(changes) { | ||||||
|  | }; | ||||||
|  |  | ||||||
| var MacroNode = function(macroName,paramFn,children,dependencies,store) { | var MacroNode = function(macroName,paramFn,children,dependencies,store) { | ||||||
| 	if(this instanceof MacroNode) { | 	if(this instanceof MacroNode) { | ||||||
| 		this.macroName = macroName; | 		this.macroName = macroName; | ||||||
| @@ -24,6 +52,9 @@ var MacroNode = function(macroName,paramFn,children,dependencies,store) { | |||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | MacroNode.prototype = new Node(); | ||||||
|  | MacroNode.prototype.constructor = MacroNode; | ||||||
|  |  | ||||||
| MacroNode.prototype.clone = function() { | MacroNode.prototype.clone = function() { | ||||||
| 	return new MacroNode(this.macroName,this.paramFn,this.cloneChildren(),this.dependencies,this.store); | 	return new MacroNode(this.macroName,this.paramFn,this.cloneChildren(),this.dependencies,this.store); | ||||||
| }; | }; | ||||||
| @@ -140,6 +171,9 @@ var ElementNode = function(type,attributes,children) { | |||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | ElementNode.prototype = new Node(); | ||||||
|  | ElementNode.prototype.constructor = ElementNode; | ||||||
|  |  | ||||||
| ElementNode.prototype.clone = function() { | ElementNode.prototype.clone = function() { | ||||||
| 	var childClones; | 	var childClones; | ||||||
| 	if(this.children) { | 	if(this.children) { | ||||||
| @@ -244,14 +278,8 @@ var TextNode = function(text) { | |||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
| TextNode.prototype.clone = function() { | TextNode.prototype = new Node(); | ||||||
| 	// We don't actually clone text nodes, instead we re-use them | TextNode.prototype.constructor = TextNode; | ||||||
| 	return this; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| TextNode.prototype.execute = function(parents,tiddler) { |  | ||||||
| 	// Text nodes don't need executing	 |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| TextNode.prototype.render = function(type) { | TextNode.prototype.render = function(type) { | ||||||
| 	return type === "text/html" ? utils.htmlEncode(this.text) : this.text; | 	return type === "text/html" ? utils.htmlEncode(this.text) : this.text; | ||||||
| @@ -261,14 +289,6 @@ TextNode.prototype.renderInDom = function(domNode) { | |||||||
| 	domNode.appendChild(document.createTextNode(this.text));	 | 	domNode.appendChild(document.createTextNode(this.text));	 | ||||||
| }; | }; | ||||||
|  |  | ||||||
| TextNode.prototype.refresh = function(changes) { |  | ||||||
| 	// Text nodes don't need refreshing	 |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| TextNode.prototype.refreshInDom = function(changes) { |  | ||||||
| 	// Text nodes don't need refreshing	 |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| var EntityNode = function(entity) { | var EntityNode = function(entity) { | ||||||
| 	if(this instanceof EntityNode) { | 	if(this instanceof EntityNode) { | ||||||
| 		this.entity = entity; | 		this.entity = entity; | ||||||
| @@ -277,14 +297,8 @@ var EntityNode = function(entity) { | |||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
| EntityNode.prototype.clone = function() { | EntityNode.prototype = new Node(); | ||||||
| 	// We don't actually clone entity nodes, instead we re-use them | EntityNode.prototype.constructor = EntityNode; | ||||||
| 	return this; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| EntityNode.prototype.execute = function(parents,tiddler) { |  | ||||||
| 	// Entity nodes don't need executing	 |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| EntityNode.prototype.render = function(type) { | EntityNode.prototype.render = function(type) { | ||||||
| 	return type === "text/html" ? this.entity : utils.entityDecode(this.entity); | 	return type === "text/html" ? this.entity : utils.entityDecode(this.entity); | ||||||
| @@ -294,14 +308,6 @@ EntityNode.prototype.renderInDom = function(domNode) { | |||||||
| 	domNode.appendChild(document.createTextNode(utils.entityDecode(this.entity))); | 	domNode.appendChild(document.createTextNode(utils.entityDecode(this.entity))); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| EntityNode.prototype.refresh = function(changes) { |  | ||||||
| 	// Entity nodes don't need refreshing	 |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| EntityNode.prototype.refreshInDom = function(changes) { |  | ||||||
| 	// Entity nodes don't need refreshing	 |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| var RawNode = function(html) { | var RawNode = function(html) { | ||||||
| 	if(this instanceof RawNode) { | 	if(this instanceof RawNode) { | ||||||
| 		this.html = html; | 		this.html = html; | ||||||
| @@ -310,14 +316,8 @@ var RawNode = function(html) { | |||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
| RawNode.prototype.clone = function() { | RawNode.prototype = new Node(); | ||||||
| 	// We don't actually clone raw nodes, instead we re-use them | RawNode.prototype.constructor = RawNode; | ||||||
| 	return this; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| RawNode.prototype.execute = function(parents,tiddler) { |  | ||||||
| 	// Raw nodes don't need executing	 |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| RawNode.prototype.render = function(type) { | RawNode.prototype.render = function(type) { | ||||||
| 	return this.html; | 	return this.html; | ||||||
| @@ -329,14 +329,6 @@ RawNode.prototype.renderInDom = function(domNode) { | |||||||
| 	domNode.appendChild(div);	 | 	domNode.appendChild(div);	 | ||||||
| }; | }; | ||||||
|  |  | ||||||
| RawNode.prototype.refresh = function(changes) { |  | ||||||
| 	// Raw nodes don't need refreshing	 |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| RawNode.prototype.refreshInDom = function(changes) { |  | ||||||
| 	// Raw nodes don't need refreshing	 |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| /* | /* | ||||||
| Static method to construct a label | Static method to construct a label | ||||||
| */ | */ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jeremy Ruston
					Jeremy Ruston