Skip to content

Commit

Permalink
Merge pull request #455 from devicons/amacado/feature/444-svg-bash-plain
Browse files Browse the repository at this point in the history
fix displaying svg code in devicon.dev
  • Loading branch information
Thomas-Boi authored Jan 4, 2021
2 parents d16d894 + 0d21141 commit 00b6cc8
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 00b6cc8

Please sign in to comment.