Skip to content

Commit 0d21141

Browse files
committed
fix bug where the content of svg could not be extracted when there was a comment above
1 parent 6f94a07 commit 0d21141

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

docs/assets/js/script.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,30 @@ devicon.controller('IconListCtrl', function($scope, $http, $compile) {
118118

119119
$http.get(baseUrl + '/icons/' + $scope.selectedIcon.name + '/' + $scope.selectedIcon.name + '-' + svgVersion + '.svg').success(function(data){
120120

121-
var svg = angular.element(data);
122-
var innerSVG = (svg[0].innerHTML);
121+
var svgElement = angular.element(data);
122+
var innerSvgElement = null;
123+
124+
/**
125+
* Loop trough svg image to find
126+
* the actual svg content (not any comments or stuff
127+
* we don't care for).
128+
* See https://github.com/devicons/devicon/issues/444#issuecomment-753699913
129+
*/
130+
for (const [key, value] of Object.entries(svgElement)) {
131+
/** [object SVGSVGElement] ensures we have the actual svg content */
132+
if(value.toString() == '[object SVGSVGElement]') {
133+
innerSvgElement = value;
134+
break;
135+
}
136+
}
123137

124-
$scope.selectedSvgIcon = innerSVG;
125-
$scope.selectedSvgIndex = index;
138+
if(innerSvgElement === null) {
139+
console.error('Could not find content of given SVG.')
140+
} else {
141+
var innerSVG = (innerSvgElement.innerHTML);
142+
$scope.selectedSvgIcon = innerSVG;
143+
$scope.selectedSvgIndex = index;
144+
}
126145
});
127146
}
128147
/*---- End of "Change selected svg icon" ----*/

0 commit comments

Comments
 (0)