Bug 1516287 - Wait for stylesheet to load before adding category colours. r=philipp
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 26 Dec 2018 10:55:59 +1300
changeset 34062 e8fcc4360ac43ede46cca6d4a37dca4e8a502300
parent 34061 9211c27bcce17581159f187de803be96de9b7a95
child 34063 b3f44f8462f9d0e89e3967ebe01aca33081ee749
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersphilipp
bugs1516287
Bug 1516287 - Wait for stylesheet to load before adding category colours. r=philipp
calendar/base/content/calendar-views.js
--- a/calendar/base/content/calendar-views.js
+++ b/calendar/base/content/calendar-views.js
@@ -458,19 +458,26 @@ var categoryManagement = {
 
     categoryStyleCache: {},
 
     updateStyleSheetForCategory: function(aCatName) {
         if (!(aCatName in this.categoryStyleCache)) {
             // We haven't created a rule for this category yet, do so now.
             let sheet = getViewStyleSheet();
             let ruleString = '.category-color-box[categories~="' + aCatName + '"] {} ';
-            let ruleIndex = sheet.insertRule(ruleString, sheet.cssRules.length);
 
-            this.categoryStyleCache[aCatName] = sheet.cssRules[ruleIndex];
+            try {
+                let ruleIndex = sheet.insertRule(ruleString, sheet.cssRules.length);
+                this.categoryStyleCache[aCatName] = sheet.cssRules[ruleIndex];
+            } catch (ex) {
+                sheet.ownerNode.addEventListener("load",
+                                                 () => this.updateStyleSheetForCategory(aCatName),
+                                                 { once: true });
+                return;
+            }
         }
 
         let color = Preferences.get("calendar.category.color." + aCatName) || "";
         this.categoryStyleCache[aCatName].style.backgroundColor = color;
     }
 };
 
 /**