Skip to content

Commit

Permalink
Image download issues fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaeverywhere committed Jan 4, 2017
1 parent 8c7dab9 commit 45a8f07
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CacheClassExplorer",
"version": "1.19.1",
"version": "1.19.2",
"description": "Class Explorer for InterSystems Caché",
"directories": { "test": "test" },
"dependencies": {},
25 changes: 18 additions & 7 deletions web/jsLib/ImageExporter.js
Original file line number Diff line number Diff line change
@@ -22,6 +22,9 @@ var enableSVGDownload = function (classView) {

var par = svg.parentNode;
svg = svg.cloneNode(true);
svg.style.position = "fixed";
svg.style.left = 0;
svg.style.top = 0;
par.appendChild(svg);
var gGroup = svg.childNodes[0];

@@ -40,9 +43,12 @@ var enableSVGDownload = function (classView) {
svg.setAttributeNS(prefix.xmlns, "xmlns:xlink", prefix.xlink);
}

svg.style.zIndex = 0;
gGroup.setAttribute("transform", "");
var gRect = gGroup.getBoundingClientRect();
gGroup.setAttribute("transform", "translate("+(-gRect.left)+","+(-gRect.top)+")");
svg.setAttribute("width", gGroup.getBBox().width);
svg.setAttribute("height", gGroup.getBBox().height);
gGroup.setAttribute("transform", "");

setInlineStyles(svg, emptySvgDeclarationComputed);

@@ -82,12 +88,17 @@ var enableSVGDownload = function (classView) {

img.onload = function () {
ctx.drawImage(img, 0, 0);
var dataURL = canvas.toDataURL("image/png");
var a = document.createElement("a");
a.setAttribute("download", filename + ".png");
a.setAttribute("href", dataURL/*url*/);
document.body.appendChild(a);
a.click();
try {
var a = document.createElement("a");
a.setAttribute("download", filename + ".png");
var dataURL = canvas.toDataURL("image/png");
a.setAttribute("href", dataURL/*url*/);
document.body.appendChild(a);
a.click();
} catch (e) {
alert("This browser does not allow usage of canvas.toDataURL function. Please,"
+ " use different browser to download the image.");
}
setTimeout(function () {
a.parentNode.removeChild(a);
document.body.removeChild(emptySvg);

0 comments on commit 45a8f07

Please sign in to comment.