1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 23:03:15 +00:00

Move making a data uri into reusable utilities

This commit is contained in:
Jermolene 2015-03-18 11:40:09 +00:00
parent a4a9daa40b
commit 22b7400de8
2 changed files with 17 additions and 10 deletions

View File

@ -29,16 +29,7 @@ exports.params = [
Run the macro Run the macro
*/ */
exports.run = function(text,type) { exports.run = function(text,type) {
type = type || "text/vnd.tiddlywiki"; return $tw.utils.makeDataUri(text,type);
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("");
}; };
})(); })();

View File

@ -606,4 +606,20 @@ exports.timer = function(base) {
return m; 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("");
};
})(); })();