From 693698c5142080859ac0f99921766eca4fd5a5bd Mon Sep 17 00:00:00 2001 From: Tim Mickel Date: Thu, 24 Mar 2016 14:05:45 -0400 Subject: [PATCH] SVG2Canvas.processXMLnode to not getElementById This addresses #29 in iOS, which was causing photos in thumbnails to not crop. A note about what was going on is included in the code. --- src/utils/SVG2Canvas.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/utils/SVG2Canvas.js b/src/utils/SVG2Canvas.js index 2174b35..7ae5eca 100644 --- a/src/utils/SVG2Canvas.js +++ b/src/utils/SVG2Canvas.js @@ -264,7 +264,21 @@ export default class SVG2Canvas { while (p.tagName != 'svg') { p = p.parentNode; } - SVGImage.draw(elem, p.getElementById('pathborder_' + elem.id), ctx); + // Note: previously, we used only p.getElementById(targetPath) + // In iOS 9, this broke and started returning null. + // getElementsByTagName('path') includes the right element, so we + // iterate through those and find the one with the matching ID. + var targetPathId = 'pathborder_' + elem.id; + var targetPathElement = p.getElementById(targetPathId); + if (!targetPathElement) { + var paths = p.getElementsByTagName('path'); + for (var i = 0; i < paths.length; i++) { + if (paths[i].id == targetPathId) { + targetPathElement = paths[i]; + } + } + } + SVGImage.draw(elem, targetPathElement, ctx); break; case 'clipPath': break;