Skip to content

Commit

Permalink
fix bug where the content of svg could not be extracted when there wa…
Browse files Browse the repository at this point in the history
…s a comment above
  • Loading branch information
amacado committed Jan 4, 2021
1 parent 6f94a07 commit 0d21141
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions docs/assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" ----*/
Expand Down

0 comments on commit 0d21141

Please sign in to comment.