From fb258e1514bca6eff7e19d827be4bd717ea592a8 Mon Sep 17 00:00:00 2001
From: uhensler <urs.hensler@frentix.com>
Date: Wed, 9 Sep 2020 09:30:48 +0200
Subject: [PATCH] OO-4878: Make sure the OnlyOffice JS-Library is loaded and
 ready before invoked

---
 .../onlyoffice/ui/_content/editor.html         | 18 +++++++++++++++---
 .../doceditor/ui/_content/standalone_open.html |  8 +-------
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/_content/editor.html b/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/_content/editor.html
index f2e5b7d0e73..a960879da4d 100644
--- a/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/_content/editor.html
+++ b/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/_content/editor.html
@@ -8,9 +8,21 @@
 		<script src="$apiUrl"></script>
 		<script>
 		/* <![CDATA[ */
-			jQuery('$id').ready(function(){
-				new DocsAPI.DocEditor("$id", $apiConfig);
-			});
+		## Make sure the OnlyOffice JS-Library is loaded and ready.
+		function loadEditor() {
+			var waitForLoad = function() {
+				if (typeof DocsAPI != "undefined") {
+					new DocsAPI.DocEditor("$id", $apiConfig);
+				} else {
+					window.setTimeout(waitForLoad, 500);
+				}
+			};
+			window.setTimeout(waitForLoad, 500);
+		}
+
+		jQuery("$id").ready(function() {
+			loadEditor();
+		});
 		/* ]]> */
 		</script>
 	#end
diff --git a/src/main/java/org/olat/core/commons/services/doceditor/ui/_content/standalone_open.html b/src/main/java/org/olat/core/commons/services/doceditor/ui/_content/standalone_open.html
index 52f265c911b..5ca5713486e 100644
--- a/src/main/java/org/olat/core/commons/services/doceditor/ui/_content/standalone_open.html
+++ b/src/main/java/org/olat/core/commons/services/doceditor/ui/_content/standalone_open.html
@@ -3,10 +3,4 @@
 	<div class="o_button_group">
 		$r.render("open.button")
 	</div>
-</div>
-<script>
-/* <![CDATA[ */
-##jQuery(document).ready(function() { $r.backgroundCommand("open"); })
-##jQuery(document).ready(function() { $r.openJavaScriptCommand("open")); })
-/* ]]> */
-</script>
\ No newline at end of file
+</div>
\ No newline at end of file
-- 
GitLab