mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-08 00:10:27 +00:00
Add support for oncompletion handler
This commit is contained in:
parent
42b79213dd
commit
ed53a8d580
@ -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
|
||||
|
||||
|
@ -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() {
|
||||
};
|
||||
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user