mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 12:07:19 +00:00
Move making a data uri into reusable utilities
This commit is contained in:
parent
a4a9daa40b
commit
22b7400de8
@ -29,16 +29,7 @@ exports.params = [
|
||||
Run the macro
|
||||
*/
|
||||
exports.run = function(text,type) {
|
||||
type = type || "text/vnd.tiddlywiki";
|
||||
var typeInfo = $tw.config.contentTypeInfo[type] || $tw.config.contentTypeInfo["text/plain"],
|
||||
isBase64 = typeInfo.encoding === "base64",
|
||||
parts = [];
|
||||
parts.push("data:");
|
||||
parts.push(type);
|
||||
parts.push(isBase64 ? ";base64" : "");
|
||||
parts.push(",");
|
||||
parts.push(isBase64 ? text : encodeURIComponent(text));
|
||||
return parts.join("");
|
||||
return $tw.utils.makeDataUri(text,type);
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -606,4 +606,20 @@ exports.timer = function(base) {
|
||||
return m;
|
||||
};
|
||||
|
||||
/*
|
||||
Convert text and content type to a data URI
|
||||
*/
|
||||
exports.makeDataUri = function(text,type) {
|
||||
type = type || "text/vnd.tiddlywiki";
|
||||
var typeInfo = $tw.config.contentTypeInfo[type] || $tw.config.contentTypeInfo["text/plain"],
|
||||
isBase64 = typeInfo.encoding === "base64",
|
||||
parts = [];
|
||||
parts.push("data:");
|
||||
parts.push(type);
|
||||
parts.push(isBase64 ? ";base64" : "");
|
||||
parts.push(",");
|
||||
parts.push(isBase64 ? text : encodeURIComponent(text));
|
||||
return parts.join("");
|
||||
};
|
||||
|
||||
})();
|
Loading…
Reference in New Issue
Block a user