1
0
mirror of https://github.com/konpa/devicon.git synced 2025-08-09 08:06:32 +02:00

fix bug where the content of svg could not be extracted when there was a comment above

This commit is contained in:
amacado
2021-01-04 01:55:11 +01:00
parent 6f94a07577
commit 0d21141479

View File

@@ -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){ $http.get(baseUrl + '/icons/' + $scope.selectedIcon.name + '/' + $scope.selectedIcon.name + '-' + svgVersion + '.svg').success(function(data){
var svg = angular.element(data); var svgElement = angular.element(data);
var innerSVG = (svg[0].innerHTML); 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;
}
}
if(innerSvgElement === null) {
console.error('Could not find content of given SVG.')
} else {
var innerSVG = (innerSvgElement.innerHTML);
$scope.selectedSvgIcon = innerSVG; $scope.selectedSvgIcon = innerSVG;
$scope.selectedSvgIndex = index; $scope.selectedSvgIndex = index;
}
}); });
} }
/*---- End of "Change selected svg icon" ----*/ /*---- End of "Change selected svg icon" ----*/