1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-08 16:30:26 +00:00

Add support for oncompletion handler

This commit is contained in:
Jeremy Ruston 2024-12-18 19:24:55 +00:00
parent 42b79213dd
commit ed53a8d580
2 changed files with 17 additions and 1 deletions

View File

@ -18,6 +18,8 @@ The following parameters are supported:
|''height'' |Optional height of the image in pixels |
|''save-file'' |Optional filename to save the image to |
|''save-title'' |Optional title of tiddler to save the image to |
|''oncompletion'' |Optional action string to be invoked when the save operation has completed |
|''var-*'' |Variables to be passed to the completion handler (without the "var-" prefix) |
!! Examples

View File

@ -19,10 +19,22 @@ exports.before = ["render"];
exports.synchronous = true;
exports.startup = function() {
var getPropertiesWithPrefix = function(properties,prefix) {
var result = Object.create(null);
$tw.utils.each(properties,function(value,name) {
if(name.indexOf(prefix) === 0) {
result[name.substring(prefix.length)] = properties[name];
}
});
return result;
};
$tw.rootWidget.addEventListener("tm-save-dom-to-image",function(event) {
var self=this; /* ELS */
var params = event.paramObject || {},
domToImage = require("$:/plugins/tiddlywiki/dom-to-image/dom-to-image-more.js"),
domNode = document.querySelector(params.selector || "body.tc-body");
domNode = document.querySelector(params.selector || "body.tc-body"),
oncompletion = params.oncompletion,
variables = getPropertiesWithPrefix(params,"var-");
if(domNode) {
var method = "toPng";
switch(params.format) {
@ -67,6 +79,7 @@ exports.startup = function() {
}));
}
}
self.wiki.invokeActionString(oncompletion,self,variables,{parentWidget: $tw.rootWidget});
})
.catch(function(error) {
console.error('oops, something went wrong!', error);
@ -76,3 +89,4 @@ exports.startup = function() {
};
})();