Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update local link detection to account for relative links (e.g. css/screen.css) #5

Merged
merged 2 commits into from
Jul 25, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions livecss.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var livecss = {
var media = (linkElements[i].getAttribute("media") || "").toLowerCase(); var media = (linkElements[i].getAttribute("media") || "").toLowerCase();
if (linkElements[i].getAttribute("rel") == "stylesheet" if (linkElements[i].getAttribute("rel") == "stylesheet"
&& livecss.indexOf(validMediaTypes, media) >= 0 && livecss.indexOf(validMediaTypes, media) >= 0
&& this.isLocalUrl(linkElements[i].getAttribute("href"))) { && this.isLocalLink(linkElements[i])) {
this.refreshLinkElement(linkElements[i]); this.refreshLinkElement(linkElements[i]);
} }
} }
Expand Down Expand Up @@ -133,8 +133,11 @@ var livecss = {
return false; return false;
}, },


/* returns true for local urls such as: '/screen.css', 'http://mydomain.com/screen.css' */ /* returns true for local urls such as: '/screen.css', 'http://mydomain.com/screen.css', 'css/screen.css'
isLocalUrl: function(url) { */
isLocalLink: function(linkElement) {
//On all tested browsers, this javascript property returns a normalized URL
var url = linkElement.href;
var regexp = new RegExp("^\/|^" + var regexp = new RegExp("^\/|^" +
document.location.protocol + "//" + document.location.host); document.location.protocol + "//" + document.location.host);
return (url.search(regexp) == 0); return (url.search(regexp) == 0);
Expand Down