From ed53a8d58060c45bacbb446026ab9e499349be36 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 18 Dec 2024 19:24:55 +0000 Subject: [PATCH] Add support for oncompletion handler --- plugins/tiddlywiki/dom-to-image/docs.tid | 2 ++ plugins/tiddlywiki/dom-to-image/startup.js | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/tiddlywiki/dom-to-image/docs.tid b/plugins/tiddlywiki/dom-to-image/docs.tid index 095406477..5183e9758 100644 --- a/plugins/tiddlywiki/dom-to-image/docs.tid +++ b/plugins/tiddlywiki/dom-to-image/docs.tid @@ -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 diff --git a/plugins/tiddlywiki/dom-to-image/startup.js b/plugins/tiddlywiki/dom-to-image/startup.js index adc2ca65d..4584752b8 100644 --- a/plugins/tiddlywiki/dom-to-image/startup.js +++ b/plugins/tiddlywiki/dom-to-image/startup.js @@ -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() { }; })(); + \ No newline at end of file