From a121f2261d0e62fa9b0ff3b1d614322bf8c55895 Mon Sep 17 00:00:00 2001 From: Nik Rolls Date: Tue, 28 Feb 2017 19:19:00 +1300 Subject: [PATCH] DOM Inspector: Fallback to .childNodes when .children not present (#2242) When the browser does not support .children on the svgRoot element (MS Edge, for example), filter childNodes for elements and use that list instead. --- src/js/scriptlets/dom-inspector.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/js/scriptlets/dom-inspector.js b/src/js/scriptlets/dom-inspector.js index 5ef7658b6..ce8a4632d 100644 --- a/src/js/scriptlets/dom-inspector.js +++ b/src/js/scriptlets/dom-inspector.js @@ -810,6 +810,17 @@ var elementsFromSpecialSelector = function(selector) { /******************************************************************************/ +var getSvgRootChildren = function() { + if ( svgRoot.children ) { + return svgRoot.children; + } else { + var childNodes = Array.prototype.slice.apply(svgRoot.childNodes); + return childNodes.filter(function(node) { + return node.nodeType === Node.ELEMENT_NODE; + }); + } +}; + var highlightElements = function(scrollTo) { var wv = pickerRoot.contentWindow.innerWidth; var hv = pickerRoot.contentWindow.innerHeight; @@ -818,6 +829,7 @@ var highlightElements = function(scrollTo) { var xl, xr, yt, yb, w, h, ws; var xlu = Number.MAX_VALUE, xru = 0, ytu = Number.MAX_VALUE, ybu = 0; var lists = highlightedElementLists; + var svgRootChildren = getSvgRootChildren(); for ( var i = 0; i < lists.length; i++ ) { elems = lists[i]; @@ -857,7 +869,7 @@ var highlightElements = function(scrollTo) { if ( yt < ytu ) { ytu = yt; } if ( yb > ybu ) { ybu = yb; } } - svgRoot.children[i+1].setAttribute('d', islands.join('') || 'M0 0'); + svgRootChildren[i+1].setAttribute('d', islands.join('') || 'M0 0'); } svgRoot.firstElementChild.setAttribute('d', ocean.join(''));