New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-browser and more efficient encoder #4

Merged
merged 1 commit into from Sep 20, 2015
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+14 −3
Diff settings

Always

Just for now

Copy path View file
@@ -7,18 +7,19 @@ var resDemo = doc.querySelector("#demo");

var expanders = doc.querySelectorAll(".expander");
var expandedClass = "expanded";
var symbols = /[\r\n"%#()<>?\[\\\]^`{|}]/g;

// Textarea Actions
//----------------------------------------

initTar.onchange = function() {
resTar.value = escape(initTar.value);
resTar.value = encodeSVG(initTar.value);
};

initTar.onkeyup = function() {
var escaped = escape(initTar.value);
var escaped = encodeSVG(initTar.value);
resTar.value = escaped;
var resultCss = 'background-image: url(data:image/svg+xml,' + escaped + ')';
var resultCss = 'background-image: url("data:image/svg+xml,' + escaped + '")';
resCssTar.value = resultCss;
resDemo.setAttribute("style", resultCss);
};
@@ -37,6 +38,16 @@ for (var i = 0; i < expanders.length; i++) {
};
}

// Encoding
//----------------------------------------

function encodeSVG(data) {
// Use single quotes instead of double to avoid encoding.
if (data.indexOf("'") < 0)
data = data.replace(/"/g, "'");
return data.replace(symbols, escape);
}

// Common
//----------------------------------------

ProTip! Use n and p to navigate between commits in a pull request.