Skip to content

Commit

Permalink
Merge pull request #70 from stealjs/slim-href
Browse files Browse the repository at this point in the history
Refine logic to detect whether link exists already
  • Loading branch information
m-mujica authored Jan 25, 2018
2 parents f0fb5ff + 1d84d18 commit 3eeef49
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,24 @@ function CssModule(address) {
// timeout in seconds
CssModule.waitTimeout = 60;

CssModule.prototype.linkExists = function() {
var styleSheets = document.styleSheets;
// The slim build does not resolve to URLs, so this trick is needed
// to get the url and use it to check if the link was already added
// to the head
CssModule.prototype.getLinkUrl = function() {
var anchor = document.createElement("a");
anchor.href = this.address;
var href = anchor.href;
return anchor.href;
};

for (var i = 0; i < styleSheets.length; ++i) {
if (href === styleSheets[i].href) {
return true;
CssModule.prototype.linkExists = function() {
var styleSheets = document.querySelectorAll('[rel="stylesheet"]');

if (styleSheets != null) {
var href = this.getLinkUrl();
for (var i = 0; i < styleSheets.length; ++i) {
if (href === styleSheets[i].href) {
return true;
}
}
}

Expand Down

0 comments on commit 3eeef49

Please sign in to comment.