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:
parent
a4a9daa40b
commit
22b7400de8
|
@ -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("");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -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("");
|
||||||
|
};
|
||||||
|
|
||||||
})();
|
})();
|
Loading…
Reference in New Issue
Block a user