[Libreoffice-commits] online.git: Branch 'feature/proxyhack' - loleaflet/js

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Fri Mar 20 19:06:27 UTC 2020


 loleaflet/js/global.js |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

New commits:
commit 2a8ce570ce1d47ab249ad5ee0676b68c110fcfca
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Fri Mar 20 19:05:48 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Mar 20 19:05:48 2020 +0000

    Proxy: re-write css image URLs to handle the proxy.
    
    Change-Id: I09f3dea2f5e3a51869d5b0aa3f473d8f3ba75f44

diff --git a/loleaflet/js/global.js b/loleaflet/js/global.js
index 78bceaa9c..24cc2f77f 100644
--- a/loleaflet/js/global.js
+++ b/loleaflet/js/global.js
@@ -317,6 +317,32 @@
 		}, 250);
 	};
 
+	if (global.socketProxy)
+	{
+		// re-write relative URLs in CSS - somewhat grim.
+		window.addEventListener('load', function() {
+			var sheets = document.styleSheets;
+			var replaceBase = 'url("' + global.host.replace(/^ws/, 'http') +
+			    global.serviceRoot + '/loleaflet/1235/images/';
+
+			for (var i = 0; i < sheets.length; ++i) {
+				var rules = sheets[i].cssRules || sheets[i].rules;
+				for (var r = 0; r < rules.length; ++r) {
+					if (!rules[r] || !rules[r].style)
+						continue;
+					var img = rules[r].style.backgroundImage;
+					if (img === '' || img === undefined)
+						continue;
+					if (img.startsWith('url("images/'))
+					{
+						rules[r].style.backgroundImage =
+							img.replace('url("images/', replaceBase);
+					}
+				}
+			}
+		}, false);
+	}
+
 	global.createWebSocket = function(uri) {
 		if (global.socketProxy) {
 			return new global.ProxySocket(uri);


More information about the Libreoffice-commits mailing list