From 58215e573fec44fe9cadf09909b44007ef5c18e6 Mon Sep 17 00:00:00 2001
From: enahum <nahumhbl@gmail.com>
Date: Tue, 29 Nov 2016 12:16:21 -0300
Subject: Fix Theme in safari (#4668)

---
 webapp/utils/utils.jsx | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

(limited to 'webapp/utils/utils.jsx')

diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx
index 5c2823f41..b6d3b076f 100644
--- a/webapp/utils/utils.jsx
+++ b/webapp/utils/utils.jsx
@@ -687,18 +687,25 @@ export function applyFont(fontName) {
 }
 
 export function changeCss(className, classValue) {
-    let styleEl = document.querySelector('style[data-class="' + className + classValue + '"]');
+    let styleEl = document.querySelector('style[data-class="' + className + '"]');
     if (!styleEl) {
         styleEl = document.createElement('style');
         styleEl.setAttribute('data-class', className);
-    }
 
-    // Append style element to head
-    document.head.appendChild(styleEl);
+        // Append style element to head
+        document.head.appendChild(styleEl);
+    }
 
     // Grab style sheet
-    var styleSheet = styleEl.sheet;
-    styleSheet.insertRule(className + '{' + classValue + '}', styleSheet.cssRules.length);
+    const styleSheet = styleEl.sheet;
+    let mediaQuery = '';
+    if (className.indexOf('@media') >= 0) {
+        mediaQuery = '}';
+    }
+    if (styleSheet.cssRules.length > 0) {
+        styleSheet.deleteRule(0);
+    }
+    styleSheet.insertRule(className + '{' + classValue + '}' + mediaQuery, 0);
 }
 
 export function updateCodeTheme(userTheme) {
-- 
cgit v1.2.3-1-g7c22

