Skip to content

Commit

Permalink
Client: Avoid JavaScript error when styleSheet.cssRules is null for s…
Browse files Browse the repository at this point in the history
…ome reason (observed in Chrome 21/Linux).
  • Loading branch information
papandreou committed Dec 11, 2012
1 parent d44befe commit 70fdac3
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions livestyle-client.js
Expand Up @@ -104,22 +104,24 @@
ownerNode = styleSheet.owningElement || styleSheet.ownerNode;
if (styleSheet.href) {
var cssRules = styleSheet.rules || styleSheet.cssRules; // IE8 and below use .rules
for (var j = 0 ; j < cssRules.length ; j += 1) {
cssRule = cssRules[j];
if (/^\.compilessinclude$/.test(cssRule.selectorText)) {
var backgroundImage = cssRule.style.backgroundImage || (cssRule.style.getPropertyValue && cssRule.style.getPropertyValue('background-image')) || cssRule.style.cssText,
matchBackgroundImage = backgroundImage && backgroundImage.match(/url\((['"]|)(.*?)\1\)/);
if (matchBackgroundImage) {
href = cleanHref(styleSheet.href);
var backgroundImageUrl = URI(matchBackgroundImage[2]).absoluteTo(ownerNode.getAttribute('href')).absoluteTo(location.href).toString(),
watchHref = cleanHref(backgroundImageUrl);
if (href && watchHref) {
cssIncludes.push({type: 'link', href: href, watchHref: watchHref, node: ownerNode});
if (cssRules) {
for (var j = 0 ; j < cssRules.length ; j += 1) {
cssRule = cssRules[j];
if (/^\.compilessinclude$/.test(cssRule.selectorText)) {
var backgroundImage = cssRule.style.backgroundImage || (cssRule.style.getPropertyValue && cssRule.style.getPropertyValue('background-image')) || cssRule.style.cssText,
matchBackgroundImage = backgroundImage && backgroundImage.match(/url\((['"]|)(.*?)\1\)/);
if (matchBackgroundImage) {
href = cleanHref(styleSheet.href);
var backgroundImageUrl = URI(matchBackgroundImage[2]).absoluteTo(ownerNode.getAttribute('href')).absoluteTo(location.href).toString(),
watchHref = cleanHref(backgroundImageUrl);
if (href && watchHref) {
cssIncludes.push({type: 'link', href: href, watchHref: watchHref, node: ownerNode});
}
}
} else {
// These .compilessinclude rules always come first, so break on the first non-matching one:
break;
}
} else {
// These .compilessinclude rules always come first, so break on the first non-matching one:
break;
}
}
}
Expand Down

1 comment on commit 70fdac3

@Munter
Copy link
Collaborator

@Munter Munter commented on 70fdac3 Jan 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just got that error as well because I was on an old livestyle version.
The stylesheet in question was this:

@font-face {
  font-family: 'Bree Serif';
  font-style: normal;
  font-weight: 400;
  src: local('Bree Serif'), local('BreeSerif-Regular'), url(http://themes.googleusercontent.com/static/fonts/breeserif/v2/LQ7WLTaITDg4OSRuOZCpsxsxEYwM7FgeyaSgU71cLG0.woff) format('woff');
}

Apparently @font-face doesn't register as a rule.

Just FYI

Please sign in to comment.