Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 7cde443

Browse files
Splaktarjelbourn
authored andcommitted
fix(icon): SVG elements are not loaded from the cache properly on IE11 (#11635)
preserve the outer SVG element and its attributes Fixes #11603. Relates to #11545. Closes #11604.
1 parent 22d7739 commit 7cde443

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/components/icon/js/iconService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ function MdIconService(config, $templateRequest, $q, $log, $mdUtil, $sce) {
503503
});
504504
// innerHTML of SVG elements is not supported by IE11
505505
if (clone.innerHTML === undefined) {
506-
svgElement = $mdUtil.getInnerHTML(clone);
506+
svgElement = $mdUtil.getOuterHTML(clone);
507507
svgElement = svgElement.replace(/(.*url\(#)(\w*)(\).*)/g, addCacheSuffixToId);
508508
svgElement = svgElement.replace(/(.*xlink:href="#)(\w*)(".*)/g, addCacheSuffixToId);
509509
clone = angular.element(svgElement)[0];

src/core/util/util.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,21 +864,38 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
864864
},
865865

866866
/**
867-
* Function to get innerHTML of SVG and Symbol elements in IE11
867+
* Gets the inner HTML content of the given HTMLElement.
868+
* Only intended for use with SVG or Symbol elements in IE11.
868869
* @param {Element} element
869-
* @returns {string} the innerHTML of the element passed in
870+
* @returns {string} the inner HTML of the element passed in
870871
*/
871872
getInnerHTML: function(element) {
873+
// For SVG or Symbol elements, innerHTML returns `undefined` in IE.
874+
// Reference: https://stackoverflow.com/q/28129956/633107
875+
// The XMLSerializer API is supported on IE11 and is the recommended workaround.
872876
var serializer = new XMLSerializer();
873877

874878
return Array.prototype.map.call(element.childNodes, function (child) {
875879
return serializer.serializeToString(child);
876880
}).join('');
881+
},
882+
883+
/**
884+
* Gets the outer HTML content of the given HTMLElement.
885+
* Only intended for use with SVG or Symbol elements in IE11.
886+
* @param {Element} element
887+
* @returns {string} the outer HTML of the element passed in
888+
*/
889+
getOuterHTML: function(element) {
890+
// For SVG or Symbol elements, outerHTML returns `undefined` in IE.
891+
// Reference: https://stackoverflow.com/q/29888050/633107
892+
// The XMLSerializer API is supported on IE11 and is the recommended workaround.
893+
var serializer = new XMLSerializer();
894+
return serializer.serializeToString(element);
877895
}
878896
};
879897

880-
881-
// Instantiate other namespace utility methods
898+
// Instantiate other namespace utility methods
882899

883900
$mdUtil.dom.animator = $$mdAnimate($mdUtil);
884901

@@ -887,7 +904,6 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
887904
function getNode(el) {
888905
return el[0] || el;
889906
}
890-
891907
}
892908

893909
/*

0 commit comments

Comments
 (0)