Permalink
Browse files

Client: Avoid JavaScript error when styleSheet.cssRules is null for s…

…ome reason (observed in Chrome 21/Linux).
  • Loading branch information...
1 parent d44befe commit 70fdac3c243677ebc063bbfbc14ee075f5ea496c @papandreou papandreou committed Dec 11, 2012
Showing with 16 additions and 14 deletions.
  1. +16 −14 livestyle-client.js
View
@@ -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;
}
}
}

1 comment on commit 70fdac3

@Munter
Member
Munter commented on 70fdac3 Jan 4, 2013

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.