Fixed base64 decoder
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@980 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
@@ -2092,12 +2092,6 @@ function svg_edit_setup() {
|
|||||||
// var revnums = "svg-editor.js ($Rev$) ";
|
// var revnums = "svg-editor.js ($Rev$) ";
|
||||||
// revnums += svgCanvas.getVersion();
|
// revnums += svgCanvas.getVersion();
|
||||||
// $('#copyright')[0].setAttribute("title", revnums);
|
// $('#copyright')[0].setAttribute("title", revnums);
|
||||||
var loc = document.location.href;
|
|
||||||
if(loc.indexOf('?source=') != -1) {
|
|
||||||
var pre = '?source=data:image/svg+xml;base64,';
|
|
||||||
var src = loc.substring(loc.indexOf(pre) + pre.length);
|
|
||||||
svgCanvas.setSvgString(Utils.decode64(src));
|
|
||||||
}
|
|
||||||
return svgCanvas;
|
return svgCanvas;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2236,6 +2230,14 @@ function setSVGIcons() {
|
|||||||
// Make smaller
|
// Make smaller
|
||||||
svgCanvas.setIconSize('s');
|
svgCanvas.setIconSize('s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load source if given
|
||||||
|
var loc = document.location.href;
|
||||||
|
if(loc.indexOf('?source=') != -1) {
|
||||||
|
var pre = '?source=data:image/svg+xml;base64,';
|
||||||
|
var src = loc.substring(loc.indexOf(pre) + pre.length);
|
||||||
|
svgCanvas.setSvgString(Utils.decode64(src));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5996,35 +5996,38 @@ var Utils = {
|
|||||||
|
|
||||||
"decode64" : function(input) {
|
"decode64" : function(input) {
|
||||||
if(window.atob) return window.atob(input);
|
if(window.atob) return window.atob(input);
|
||||||
var output = new StringMaker();
|
var output = "";
|
||||||
var chr1, chr2, chr3;
|
var chr1, chr2, chr3 = "";
|
||||||
var enc1, enc2, enc3, enc4;
|
var enc1, enc2, enc3, enc4 = "";
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|
||||||
// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
|
// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
|
||||||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
||||||
|
|
||||||
while (i < input.length) {
|
do {
|
||||||
enc1 = keyStr.indexOf(input.charAt(i++));
|
enc1 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
enc2 = keyStr.indexOf(input.charAt(i++));
|
enc2 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
enc3 = keyStr.indexOf(input.charAt(i++));
|
enc3 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
enc4 = keyStr.indexOf(input.charAt(i++));
|
enc4 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
|
|
||||||
chr1 = (enc1 << 2) | (enc2 >> 4);
|
chr1 = (enc1 << 2) | (enc2 >> 4);
|
||||||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
||||||
chr3 = ((enc3 & 3) << 6) | enc4;
|
chr3 = ((enc3 & 3) << 6) | enc4;
|
||||||
|
|
||||||
output.append(String.fromCharCode(chr1));
|
output = output + String.fromCharCode(chr1);
|
||||||
|
|
||||||
if (enc3 != 64) {
|
if (enc3 != 64) {
|
||||||
output.append(String.fromCharCode(chr2));
|
output = output + String.fromCharCode(chr2);
|
||||||
}
|
}
|
||||||
if (enc4 != 64) {
|
if (enc4 != 64) {
|
||||||
output.append(String.fromCharCode(chr3));
|
output = output + String.fromCharCode(chr3);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return output.toString();
|
chr1 = chr2 = chr3 = "";
|
||||||
|
enc1 = enc2 = enc3 = enc4 = "";
|
||||||
|
|
||||||
|
} while (i < input.length);
|
||||||
|
return unescape(output);
|
||||||
},
|
},
|
||||||
|
|
||||||
// based on http://phpjs.org/functions/utf8_encode:577
|
// based on http://phpjs.org/functions/utf8_encode:577
|
||||||
|
|||||||
Reference in New Issue
Block a user