diff options
author | mert <mert.tumer@collabora.com> | 2020-06-24 19:39:32 +0300 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2020-06-29 08:33:27 +0200 |
commit | f8f6189bdd0c75b86d12268cfa97a7090ddbbe4d (patch) | |
tree | 6a09ac4f606ee68d8b63a7751d444a28114c6900 | |
parent | 552462cecd225b5d12f40fea410686a2f3a40ba0 (diff) |
Fix url errors on backgroundImage in css files for proxy
Current replacing url strings method works fine,
however, it does not cover all the rules
for cases like when @media or @import are used.
They have a subset of their own rules which must
be covered as well.
Change-Id: Ib10f7cc361aea5cd3b855f64e3a64566a6c51a12
Signed-off-by: mert <mert.tumer@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/97071
Tested-by: Jenkins
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r-- | loleaflet/js/global.js | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/loleaflet/js/global.js b/loleaflet/js/global.js index 3420b9c13..0ed660e69 100644 --- a/loleaflet/js/global.js +++ b/loleaflet/js/global.js @@ -571,20 +571,16 @@ { // re-write relative URLs in CSS - somewhat grim. window.addEventListener('load', function() { - var sheets = document.styleSheets; - for (var i = 0; i < sheets.length; ++i) { - var relBases = sheets[i].href.split('/'); - relBases.pop(); // bin last - css name. - var replaceBase = 'url("' + relBases.join('/') + '/images/'; + var replaceUrls = function(rules, replaceBase) { + if (!rules) + return; - var rules; - try { - rules = sheets[i].cssRules || sheets[i].rules; - } catch (err) { - console.log('Missing CSS from ' + sheets[i].href); - continue; - } for (var r = 0; r < rules.length; ++r) { + // check subset of rules like @media or @import + if (rules[r] && rules[r].type != 1) { + replaceUrls(rules[r].cssRules || rules[r].rules, replaceBase); + continue; + } if (!rules[r] || !rules[r].style) continue; var img = rules[r].style.backgroundImage; @@ -596,6 +592,21 @@ img.replace('url("images/', replaceBase); } } + }; + var sheets = document.styleSheets; + for (var i = 0; i < sheets.length; ++i) { + var relBases = sheets[i].href.split('/'); + relBases.pop(); // bin last - css name. + var replaceBase = 'url("' + relBases.join('/') + '/images/'; + + var rules; + try { + rules = sheets[i].cssRules || sheets[i].rules; + } catch (err) { + console.log('Missing CSS from ' + sheets[i].href); + continue; + } + replaceUrls(rules, replaceBase); } }, false); } |