@@ -350,14 +350,14 @@ MdIconProvider.prototype = {
350
350
/**
351
351
* Configuration item stored in the Icon registry; used for lookups
352
352
* to load if not already cached in the `loaded` cache
353
- * @param url
354
- * @param viewBoxSize
353
+ * @param { string } url
354
+ * @param { =number } viewBoxSize
355
355
* @constructor
356
356
*/
357
357
function ConfigurationItem ( url , viewBoxSize ) {
358
- this . url = url ;
359
- this . viewBoxSize = viewBoxSize || config . defaultViewBoxSize ;
360
- }
358
+ this . url = url ;
359
+ this . viewBoxSize = viewBoxSize || config . defaultViewBoxSize ;
360
+ }
361
361
362
362
/**
363
363
* @ngdoc service
@@ -473,13 +473,13 @@ function MdIconService(config, $templateRequest, $q, $log, $mdUtil, $sce) {
473
473
}
474
474
475
475
/**
476
- * @param {Icon } cacheElement cached icon from the iconCache
476
+ * @param {! Icon } cacheElement cached icon from the iconCache
477
477
* @returns {Icon } cloned Icon element with unique ids
478
478
*/
479
479
function transformClone ( cacheElement ) {
480
480
var clone = cacheElement . clone ( ) ;
481
481
var newUid = $mdUtil . nextUid ( ) ;
482
- var cacheSuffix ;
482
+ var cacheSuffix , svgElement ;
483
483
484
484
// Verify that the newUid only contains a number and not some XSS content.
485
485
if ( ! isFinite ( Number ( newUid ) ) ) {
@@ -501,11 +501,19 @@ function MdIconService(config, $templateRequest, $q, $log, $mdUtil, $sce) {
501
501
angular . forEach ( clone . querySelectorAll ( '[id]' ) , function ( descendantElem ) {
502
502
descendantElem . id += cacheSuffix ;
503
503
} ) ;
504
- // Inject the cacheSuffix into all instances of url(id) and xlink:href="#id".
505
- // This use of innerHTML should be safe from XSS attack since we are only injecting the
506
- // cacheSuffix with content from $mdUtil.nextUid which we verify is a finite number above.
507
- clone . innerHTML = clone . innerHTML . replace ( / ( .* u r l \( # ) ( \w * ) ( \) .* ) / g, addCacheSuffixToId ) ;
508
- clone . innerHTML = clone . innerHTML . replace ( / ( .* x l i n k : h r e f = " # ) ( \w * ) ( " .* ) / g, addCacheSuffixToId ) ;
504
+ // innerHTML of SVG elements is not supported by IE11
505
+ if ( clone . innerHTML === undefined ) {
506
+ svgElement = $mdUtil . getInnerHTML ( clone ) ;
507
+ svgElement = svgElement . replace ( / ( .* u r l \( # ) ( \w * ) ( \) .* ) / g, addCacheSuffixToId ) ;
508
+ svgElement = svgElement . replace ( / ( .* x l i n k : h r e f = " # ) ( \w * ) ( " .* ) / g, addCacheSuffixToId ) ;
509
+ clone = angular . element ( svgElement ) [ 0 ] ;
510
+ } else {
511
+ // Inject the cacheSuffix into all instances of url(id) and xlink:href="#id".
512
+ // This use of innerHTML should be safe from XSS attack since we are only injecting the
513
+ // cacheSuffix with content from $mdUtil.nextUid which we verify is a finite number above.
514
+ clone . innerHTML = clone . innerHTML . replace ( / ( .* u r l \( # ) ( \w * ) ( \) .* ) / g, addCacheSuffixToId ) ;
515
+ clone . innerHTML = clone . innerHTML . replace ( / ( .* x l i n k : h r e f = " # ) ( \w * ) ( " .* ) / g, addCacheSuffixToId ) ;
516
+ }
509
517
510
518
return clone ;
511
519
}
@@ -605,24 +613,37 @@ function MdIconService(config, $templateRequest, $q, $log, $mdUtil, $sce) {
605
613
606
614
/**
607
615
* Check target signature to see if it is an Icon instance.
616
+ * @param {Icon|Element } target
617
+ * @returns {boolean } true if the specified target is an Icon object, false otherwise.
608
618
*/
609
619
function isIcon ( target ) {
610
620
return angular . isDefined ( target . element ) && angular . isDefined ( target . config ) ;
611
621
}
612
622
613
623
/**
614
- * Define the Icon class
624
+ * Define the Icon class
625
+ * @param {Element } el
626
+ * @param {=ConfigurationItem } config
627
+ * @constructor
615
628
*/
616
629
function Icon ( el , config ) {
630
+ var elementContents ;
617
631
// If the node is a <symbol>, it won't be rendered so we have to convert it into <svg>.
618
632
if ( el && el . tagName . toLowerCase ( ) === 'symbol' ) {
619
633
var viewbox = el . getAttribute ( 'viewBox' ) ;
620
- el = angular . element ( '<svg xmlns="http://www.w3.org/2000/svg">' ) . html ( el . innerHTML ) [ 0 ] ;
634
+ // Check if innerHTML is supported as IE11 does not support innerHTML on SVG elements.
635
+ if ( el . innerHTML ) {
636
+ elementContents = el . innerHTML ;
637
+ } else {
638
+ elementContents = $mdUtil . getInnerHTML ( el ) ;
639
+ }
640
+ el = angular . element ( '<svg xmlns="http://www.w3.org/2000/svg">' ) . append ( elementContents ) [ 0 ] ;
621
641
if ( viewbox ) el . setAttribute ( 'viewBox' , viewbox ) ;
622
642
}
623
643
624
644
if ( el && el . tagName . toLowerCase ( ) !== 'svg' ) {
625
- el = angular . element ( '<svg xmlns="http://www.w3.org/2000/svg">' ) . append ( el . cloneNode ( true ) ) [ 0 ] ;
645
+ el = angular . element (
646
+ '<svg xmlns="http://www.w3.org/2000/svg">' ) . append ( el . cloneNode ( true ) ) [ 0 ] ;
626
647
}
627
648
628
649
// Inject the namespace if not available...
0 commit comments