mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-02 12:19:11 +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:
parent
e17772c830
commit
b64e44d1af
@ -210,12 +210,9 @@ MacroNode.prototype.renderInDom = function(domNode,insertBefore) {
|
||||
// Add some debugging information to it
|
||||
macroContainer.setAttribute("data-tw-macro",this.macroName);
|
||||
// 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) {
|
||||
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
|
||||
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) {
|
||||
var t,
|
||||
self = this;
|
||||
|
Loading…
Reference in New Issue
Block a user