1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-10-04 18:00:44 +00:00

Added ability for macros to register their own event handlers, and a rendering callback

This commit is contained in:
Jeremy Ruston 2012-03-31 18:10:16 +01:00
parent 2faa668717
commit 350f2f50d4

View File

@ -259,15 +259,23 @@ MacroNode.prototype.renderInDom = function(parentDomNode,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 // Ask the macro to add event handlers to the node
for(var e in this.macro.events) { if(this.macro.addEventHandlers) {
// Register this macro node to handle the event via the handleEvent() method this.macro.addEventHandlers.call(this);
macroContainer.addEventListener(e,this,false); } else {
for(var e in this.macro.events) {
// 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++) {
this.content[t].renderInDom(macroContainer); this.content[t].renderInDom(macroContainer);
} }
// Call the macro renderInDom method if it has one
if(this.macro.renderInDom) {
this.macro.renderInDom.call(this);
}
}; };
MacroNode.prototype.refresh = function(changes) { MacroNode.prototype.refresh = function(changes) {