Skip to content

Commit 1dbb64d

Browse files
author
crisbeto
committed
fix issues with referenced resources if the page has a <base> tag
1 parent 445e8fc commit 1dbb64d

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/roundProgress.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ angular.module('angular-svg-round-progress')
8282
});
8383

8484
ring.css({
85-
"stroke": options.color,
85+
"stroke": service.resolveColor(options.color),
8686
"stroke-width": stroke,
8787
"stroke-linecap": options.rounded ? "round": "butt"
8888
});
@@ -98,7 +98,7 @@ angular.module('angular-svg-round-progress')
9898
"cy": radius,
9999
"r": backgroundSize >= 0 ? backgroundSize : 0
100100
}).css({
101-
"stroke": options.bgcolor,
101+
"stroke": service.resolveColor(options.bgcolor),
102102
"stroke-width": stroke
103103
});
104104
};
@@ -182,7 +182,7 @@ angular.module('angular-svg-round-progress')
182182
'<svg class="'+ directiveName +'" xmlns="http://www.w3.org/2000/svg">',
183183
'<circle fill="none"/>',
184184
'<path fill="none"/>',
185-
'<g ng-transclude width></g>',
185+
'<g ng-transclude></g>',
186186
'</svg>'
187187
];
188188

src/roundProgressService.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33
angular.module('angular-svg-round-progress').service('roundProgressService', [function(){
44
var service = {};
55
var isNumber = angular.isNumber;
6+
var base = document.head.querySelector('base');
7+
8+
// fixes issues if the document has a <base> element
9+
service.resolveColor = base && base.href ? function(value){
10+
var hashIndex = value.indexOf('#');
11+
12+
if(hashIndex > -1 && value.indexOf('url') > -1){
13+
return value.slice(0, hashIndex) + window.location.href + value.slice(hashIndex);
14+
}
15+
16+
return value;
17+
} : function(value){
18+
return value;
19+
};
620

721
// credits to http://modernizr.com/ for the feature test
822
service.isSupported = !!(document.createElementNS && document.createElementNS('http://www.w3.org/2000/svg', "svg").createSVGRect);

0 commit comments

Comments
 (0)