mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-17 15:21:22 +00:00
Added support for classes on macros
This commit is contained in:
@@ -26,6 +26,7 @@ The options available are:
|
|||||||
wiki: reference to the WikiStore associated with this macro
|
wiki: reference to the WikiStore associated with this macro
|
||||||
dependencies: optional Dependencies object representing the dependencies of this macro
|
dependencies: optional Dependencies object representing the dependencies of this macro
|
||||||
isBlock: true if this macro is being used as an HTML block
|
isBlock: true if this macro is being used as an HTML block
|
||||||
|
classes: array of classes to be assigned to the macro
|
||||||
|
|
||||||
Note that the dependencies will be evaluated if not provided.
|
Note that the dependencies will be evaluated if not provided.
|
||||||
*/
|
*/
|
||||||
@@ -40,6 +41,7 @@ var Macro = function(macroName,options) {
|
|||||||
this.wiki = options.wiki;
|
this.wiki = options.wiki;
|
||||||
this.dependencies = options.dependencies;
|
this.dependencies = options.dependencies;
|
||||||
this.isBlock = options.isBlock;
|
this.isBlock = options.isBlock;
|
||||||
|
this.classes = options.classes;
|
||||||
// Parse the macro parameters if required
|
// Parse the macro parameters if required
|
||||||
if(typeof this.srcParams === "string") {
|
if(typeof this.srcParams === "string") {
|
||||||
this.srcParams = this.parseMacroParamString(this.srcParams);
|
this.srcParams = this.parseMacroParamString(this.srcParams);
|
||||||
@@ -141,7 +143,8 @@ Macro.prototype.clone = function() {
|
|||||||
content: this.cloneContent(),
|
content: this.cloneContent(),
|
||||||
wiki: this.wiki,
|
wiki: this.wiki,
|
||||||
isBlock: this.isBlock,
|
isBlock: this.isBlock,
|
||||||
dependencies: this.dependencies
|
dependencies: this.dependencies,
|
||||||
|
classes: this.classes
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -184,7 +187,10 @@ Macro.prototype.renderInDom = function(parentDomNode,insertBefore) {
|
|||||||
} else {
|
} else {
|
||||||
parentDomNode.appendChild(domNode);
|
parentDomNode.appendChild(domNode);
|
||||||
}
|
}
|
||||||
// Add some debugging information to it
|
// Add classes and some debugging information to it
|
||||||
|
if(this.classes) {
|
||||||
|
domNode.setAttribute("class",this.classes.join(" "));
|
||||||
|
}
|
||||||
domNode.setAttribute("data-tw-macro",this.macroName);
|
domNode.setAttribute("data-tw-macro",this.macroName);
|
||||||
// Ask the macro to add event handlers to the node
|
// Ask the macro to add event handlers to the node
|
||||||
this.addEventHandlers();
|
this.addEventHandlers();
|
||||||
@@ -256,6 +262,11 @@ Macro.prototype.refreshInDom = function(changes) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Macro.prototype.addClass = function(className) {
|
||||||
|
this.classes = this.classes || [];
|
||||||
|
$tw.utils.pushTop(this.classes,className.split(" "));
|
||||||
|
};
|
||||||
|
|
||||||
exports.Macro = Macro;
|
exports.Macro = Macro;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user