From 0d21141479d1d102c48c24ccaa795637173238c8 Mon Sep 17 00:00:00 2001 From: amacado Date: Mon, 4 Jan 2021 01:55:11 +0100 Subject: [PATCH] fix bug where the content of svg could not be extracted when there was a comment above --- docs/assets/js/script.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/assets/js/script.js b/docs/assets/js/script.js index f26373446..e85d13e99 100644 --- a/docs/assets/js/script.js +++ b/docs/assets/js/script.js @@ -118,11 +118,30 @@ devicon.controller('IconListCtrl', function($scope, $http, $compile) { $http.get(baseUrl + '/icons/' + $scope.selectedIcon.name + '/' + $scope.selectedIcon.name + '-' + svgVersion + '.svg').success(function(data){ - var svg = angular.element(data); - var innerSVG = (svg[0].innerHTML); + var svgElement = angular.element(data); + var innerSvgElement = null; + + /** + * Loop trough svg image to find + * the actual svg content (not any comments or stuff + * we don't care for). + * See https://github.com/devicons/devicon/issues/444#issuecomment-753699913 + */ + for (const [key, value] of Object.entries(svgElement)) { + /** [object SVGSVGElement] ensures we have the actual svg content */ + if(value.toString() == '[object SVGSVGElement]') { + innerSvgElement = value; + break; + } + } - $scope.selectedSvgIcon = innerSVG; - $scope.selectedSvgIndex = index; + if(innerSvgElement === null) { + console.error('Could not find content of given SVG.') + } else { + var innerSVG = (innerSvgElement.innerHTML); + $scope.selectedSvgIcon = innerSVG; + $scope.selectedSvgIndex = index; + } }); } /*---- End of "Change selected svg icon" ----*/