kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Refactored macro implementation
Now setting event handlers to the macro object, the browser invokes the handleEvent method. Gets rid of a closure, which is goodprint-window-tiddler
rodzic
e17772c830
commit
b64e44d1af
|
@ -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;
|
||||||
|
|
Ładowanie…
Reference in New Issue