mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-02 20:29:10 +00:00
Refactor image-to-dom to be a separate plugin
This commit is contained in:
parent
6e1b58fca7
commit
42b79213dd
@ -8,7 +8,7 @@
|
|||||||
"tiddlywiki/confetti",
|
"tiddlywiki/confetti",
|
||||||
"tiddlywiki/dynannotate",
|
"tiddlywiki/dynannotate",
|
||||||
"tiddlywiki/tour",
|
"tiddlywiki/tour",
|
||||||
"tiddlywiki/geospatial"
|
"tiddlywiki/dom-to-image"
|
||||||
],
|
],
|
||||||
"themes": [
|
"themes": [
|
||||||
"tiddlywiki/vanilla",
|
"tiddlywiki/vanilla",
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
title: $:/plugins/tiddlywiki/geospatial/docs/save-dom-to-image
|
title: $:/plugins/tiddlywiki/dom-to-image/docs
|
||||||
caption: tm-save-dom-to-image message
|
caption: tm-save-dom-to-image message
|
||||||
tags: $:/tags/GeospatialDocs
|
|
||||||
|
|
||||||
!! `tm-save-dom-to-image` message
|
!! `tm-save-dom-to-image` message
|
||||||
|
|
@ -4,7 +4,7 @@
|
|||||||
"file": "dom-to-image-more.min.js",
|
"file": "dom-to-image-more.min.js",
|
||||||
"fields": {
|
"fields": {
|
||||||
"type": "application/javascript",
|
"type": "application/javascript",
|
||||||
"title": "$:/plugins/tiddlywiki/geospatial/dom-to-image-more.js",
|
"title": "$:/plugins/tiddlywiki/dom-to-image/dom-to-image-more.js",
|
||||||
"module-type": "library",
|
"module-type": "library",
|
||||||
"url": "https://github.com/1904labs/dom-to-image-more",
|
"url": "https://github.com/1904labs/dom-to-image-more",
|
||||||
"version": "3.5.0"
|
"version": "3.5.0"
|
||||||
@ -14,7 +14,7 @@
|
|||||||
"file": "LICENSE",
|
"file": "LICENSE",
|
||||||
"fields": {
|
"fields": {
|
||||||
"type": "text/plain",
|
"type": "text/plain",
|
||||||
"title": "$:/plugins/tiddlywiki/geospatial/dom-to-image-more/LICENSE"
|
"title": "$:/plugins/tiddlywiki/dom-to-image/dom-to-image-more/LICENSE"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
7
plugins/tiddlywiki/dom-to-image/plugin.info
Normal file
7
plugins/tiddlywiki/dom-to-image/plugin.info
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"title": "$:/plugins/tiddlywiki/dom-to-image",
|
||||||
|
"name": "Dom-to-image",
|
||||||
|
"description": "Save DOM nodes as images",
|
||||||
|
"list": "readme docs",
|
||||||
|
"stability": "STABILITY_1_EXPERIMENTAL"
|
||||||
|
}
|
3
plugins/tiddlywiki/dom-to-image/readme.tid
Normal file
3
plugins/tiddlywiki/dom-to-image/readme.tid
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
title: $:/plugins/tiddlywiki/dom-to-image/readme
|
||||||
|
|
||||||
|
* [[dom-to-image-more|https://github.com/1904labs/dom-to-image-more]], an open source library for saving web content as images
|
78
plugins/tiddlywiki/dom-to-image/startup.js
Normal file
78
plugins/tiddlywiki/dom-to-image/startup.js
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/plugins/tiddlywiki/dom-to-image/startup.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: startup
|
||||||
|
|
||||||
|
dom-to-image initialisation
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// Export name and synchronous status
|
||||||
|
exports.name = "dom-to-image";
|
||||||
|
exports.after = ["rootwidget"];
|
||||||
|
exports.before = ["render"];
|
||||||
|
exports.synchronous = true;
|
||||||
|
|
||||||
|
exports.startup = function() {
|
||||||
|
$tw.rootWidget.addEventListener("tm-save-dom-to-image",function(event) {
|
||||||
|
var params = event.paramObject || {},
|
||||||
|
domToImage = require("$:/plugins/tiddlywiki/dom-to-image/dom-to-image-more.js"),
|
||||||
|
domNode = document.querySelector(params.selector || "body.tc-body");
|
||||||
|
if(domNode) {
|
||||||
|
var method = "toPng";
|
||||||
|
switch(params.format) {
|
||||||
|
case "jpeg":
|
||||||
|
// Intentional fallthrough
|
||||||
|
case "jpg":
|
||||||
|
method = "toJpeg";
|
||||||
|
break;
|
||||||
|
case "svg":
|
||||||
|
method = "toSvg";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
domToImage[method](domNode,{
|
||||||
|
height: $tw.utils.parseInt(params.height) || domNode.offsetHeight,
|
||||||
|
width: $tw.utils.parseInt(params.width) || domNode.offsetWidth,
|
||||||
|
quality: $tw.utils.parseNumber(params.quality),
|
||||||
|
scale: $tw.utils.parseNumber(params.scale) || 1
|
||||||
|
})
|
||||||
|
.then(function(dataUrl) {
|
||||||
|
// Save the image
|
||||||
|
if(params["save-file"]) {
|
||||||
|
var link = document.createElement("a");
|
||||||
|
link.download = params["save-file"];
|
||||||
|
link.href = dataUrl;
|
||||||
|
link.click();
|
||||||
|
}
|
||||||
|
// Save the tiddler
|
||||||
|
if(params["save-title"]) {
|
||||||
|
if(dataUrl.indexOf("data:image/svg+xml;") === 0) {
|
||||||
|
var commaIndex = dataUrl.indexOf(",");
|
||||||
|
$tw.wiki.addTiddler(new $tw.Tiddler({
|
||||||
|
title: params["save-title"],
|
||||||
|
type: "image/svg+xml",
|
||||||
|
"text": decodeURIComponent(dataUrl.substring(commaIndex + 1))
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
var parts = dataUrl.split(";base64,");
|
||||||
|
$tw.wiki.addTiddler(new $tw.Tiddler({
|
||||||
|
title: params["save-title"],
|
||||||
|
type: parts[0].split(":")[1],
|
||||||
|
"text": parts[1]
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function(error) {
|
||||||
|
console.error('oops, something went wrong!', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
@ -11,4 +11,3 @@ The Geospatial Plugin incorporates a number of third party libraries and online
|
|||||||
* [[TravelTime|https://traveltime.com/]], a commercial API for [[geocoding|https://traveltime.com/features/geocoding]], [[routing|https://traveltime.com/features/multi-modal-routing]] and [[isochrones|https://traveltime.com/features/isochrones]]
|
* [[TravelTime|https://traveltime.com/]], a commercial API for [[geocoding|https://traveltime.com/features/geocoding]], [[routing|https://traveltime.com/features/multi-modal-routing]] and [[isochrones|https://traveltime.com/features/isochrones]]
|
||||||
* [[Flickr|https://www.flickr.com/services/api/]], a free API for retrieving geotagged photographs
|
* [[Flickr|https://www.flickr.com/services/api/]], a free API for retrieving geotagged photographs
|
||||||
* [[OpenLocationCode|https://github.com/google/open-location-code]], Google's open source library for converting to and from Open Location Codes (also known as [[PlusCodes|https://maps.google.com/pluscodes/]])
|
* [[OpenLocationCode|https://github.com/google/open-location-code]], Google's open source library for converting to and from Open Location Codes (also known as [[PlusCodes|https://maps.google.com/pluscodes/]])
|
||||||
* [[dom-to-image-more|https://github.com/1904labs/dom-to-image-more]], an open source library for saving web content as images
|
|
||||||
|
Loading…
Reference in New Issue
Block a user