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

Fails if CSS file already has a query sting #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ You can paste this code snippet into your URL bar (or create a bookmark out of i
javascript:(function(){
var s=document.createElement('script');
s.type='text/javascript';
s.src='https://github.com/ooyala/livecss/raw/master/livecss.js';
s.src='https://github.com/kuddl/livecss/raw/master/livecss.js';
s.addEventListener('load', function() { livecss.watchAll(); }, false);
document.getElementsByTagName('head')[0].appendChild(s);
})()
Expand Down
14 changes: 9 additions & 5 deletions livecss.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* livecss.watch(linkElement) - start watching a single <link> element for changes.
* livecss.unwatchAll()
* livecss.unwatch(linkElement)
*
* asdasdasd
* For convenience, livecss will call watchAll() right away if the page has "startlivecss=true" in the URL's
* query string.
*/
Expand Down Expand Up @@ -136,8 +136,8 @@ var livecss = {
/* returns true for local urls such as: '/screen.css', 'http://mydomain.com/screen.css', 'css/screen.css'
*/
isLocalLink: function(linkElement) {
//On all tested browsers, this javascript property returns a normalized URL
var url = linkElement.href;
//On all tested browsers, this javascript property returns a normalized URL
var url = linkElement.href;
var regexp = new RegExp("^\/|^" +
document.location.protocol + "//" + document.location.host);
return (url.search(regexp) == 0);
Expand All @@ -147,8 +147,12 @@ var livecss = {
* Adds and removes a "cache_bust" querystring parameter to the given URLs. This is so we always bust
* through the browser's cache when checking for updated CSS.
*/
addCacheBust: function(url) { return this.removeCacheBust(url) + "?cache_bust=" + (new Date()).getTime(); },
removeCacheBust: function(url) { return url.replace(/\?cache_bust=[^&]+/, ""); },
addCacheBust: function(url) {
var newUrl=this.removeCacheBust(url);
return newUrl + this.checkQueryString(newUrl) + "cache_bust=" + (new Date()).getTime();
},
removeCacheBust: function(url) { return url.replace(/[\?|&]cache_bust=[^&]+/, ""); },
checkQueryString: function(url) { return url.indexOf('?') === -1 ? '?' : '&';},

/* A utility method to bind the value of "this". Equivalent to jQuery's proxy() function. */
proxy: function(fn) {
Expand Down
6 changes: 6 additions & 0 deletions test/css.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body{
background:#DDD;
border:1px solid #C0FFEE;
}


13 changes: 13 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test</title>
<link rel="stylesheet" href="css.css" type="text/css" media="screen" charset="utf-8">
<link rel="stylesheet" href="qcss.css?dummyquerystring=true&anotherone=false" type="text/css" media="screen" charset="utf-8">
<script src="../livecss.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<p>This is a Test Document
</body>
</html>
4 changes: 4 additions & 0 deletions test/qcss.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
p{
background:#BADA55;
border:5px solid papayawhip;
}