From 22b7400de8c3ae019b63462eb7117d9cbfbae1a6 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Wed, 18 Mar 2015 11:40:09 +0000 Subject: [PATCH] Move making a data uri into reusable utilities --- core/modules/macros/makedatauri.js | 11 +---------- core/modules/utils/utils.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/core/modules/macros/makedatauri.js b/core/modules/macros/makedatauri.js index 418a95f6b..4b578f466 100644 --- a/core/modules/macros/makedatauri.js +++ b/core/modules/macros/makedatauri.js @@ -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); }; })(); diff --git a/core/modules/utils/utils.js b/core/modules/utils/utils.js index 80167d4ab..35bc1ff32 100644 --- a/core/modules/utils/utils.js +++ b/core/modules/utils/utils.js @@ -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(""); +}; + })(); \ No newline at end of file