mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-31 07:32:59 +00:00 
			
		
		
		
	Refactored macro implementation
Now setting event handlers to the macro object, the browser invokes the handleEvent method. Gets rid of a closure, which is good
This commit is contained in:
		| @@ -210,12 +210,9 @@ MacroNode.prototype.renderInDom = function(domNode,insertBefore) { | |||||||
| 	// Add some debugging information to it | 	// Add some debugging information to it | ||||||
| 	macroContainer.setAttribute("data-tw-macro",this.macroName); | 	macroContainer.setAttribute("data-tw-macro",this.macroName); | ||||||
| 	// Add event handlers to the node | 	// Add event handlers to the node | ||||||
| 	var self = this, |  | ||||||
| 		dispatchMacroEvent = function(event) { |  | ||||||
| 			self.macro.events[event.type].call(self,event); |  | ||||||
| 		}; |  | ||||||
| 	for(var e in this.macro.events) { | 	for(var e in this.macro.events) { | ||||||
| 		macroContainer.addEventListener(e,dispatchMacroEvent,false); | 		// Register this macro node to handle the event via the handleEvent() method | ||||||
|  | 		macroContainer.addEventListener(e,this,false); | ||||||
| 	} | 	} | ||||||
| 	// Render the content of the macro | 	// Render the content of the macro | ||||||
| 	for(var t=0; t<this.content.length; t++) { | 	for(var t=0; t<this.content.length; t++) { | ||||||
| @@ -223,6 +220,10 @@ MacroNode.prototype.renderInDom = function(domNode,insertBefore) { | |||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | MacroNode.prototype.handleEvent = function(event) { | ||||||
|  | 	return this.macro.events[event.type].call(this,event); | ||||||
|  | }; | ||||||
|  |  | ||||||
| MacroNode.prototype.refresh = function(changes) { | MacroNode.prototype.refresh = function(changes) { | ||||||
| 	var t, | 	var t, | ||||||
| 		self = this; | 		self = this; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jeremy Ruston
					Jeremy Ruston