loleaflet/html/framed.doc.html | 46 +++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 20 deletions(-)
New commits: commit 0b7cc06e602d8c45fc667d96b1c66ad17fee44bd Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> AuthorDate: Sun Jun 16 13:28:58 2019 -0400 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Jun 17 13:27:31 2019 +0200 Cleanup framed.doc.html sample Now Host_PostmessageReady is automatically issued upon loading and the postMessage calls are more modular, allowing for expansion with more functionality. Change-Id: I22b50f7228e0fd32c4cb880f4981c1a455038d48 Reviewed-on: https://gerrit.libreoffice.org/74129 Reviewed-by: Andras Timar <andras.ti...@collabora.com> Tested-by: Andras Timar <andras.ti...@collabora.com> diff --git a/loleaflet/html/framed.doc.html b/loleaflet/html/framed.doc.html index 8fa875db4..894bc1c8f 100644 --- a/loleaflet/html/framed.doc.html +++ b/loleaflet/html/framed.doc.html @@ -10,9 +10,9 @@ To test this, do 'make run', and then in your browser open the equivalent of - http://snorken.local:9980/loleaflet/3304e9093/framed.html if the + http://snorken.local:9980/loleaflet/3304e9093/framed.doc.html if the browser is running on a different machine, or - http://localhost:9980/loleaflet/3304e9093/framed.html if running + http://localhost:9980/loleaflet/3304e9093/framed.doc.html if running on the same machine. --> @@ -24,34 +24,40 @@ <script> + function post(msg) { + window.frames[0].postMessage(JSON.stringify(msg), '*'); + } + function insertText(text) { - window.frames[0].postMessage(JSON.stringify({'MessageId': 'Host_PostmessageReady'}), '*'); - window.frames[0].postMessage(JSON.stringify({'MessageId': 'CallPythonScript', - 'SendTime': Date.now(), - 'ScriptFile': 'InsertText.py', - 'Function': 'InsertText', - 'Values': { 'text': {'type': 'string', 'value': text}} - }), - '*'); + post({'MessageId': 'CallPythonScript', + 'SendTime': Date.now(), + 'ScriptFile': 'InsertText.py', + 'Function': 'InsertText', + 'Values': { 'text': {'type': 'string', 'value': text}} + }); } function capitalize() { - window.frames[0].postMessage(JSON.stringify({'MessageId': 'Host_PostmessageReady'}), '*'); - window.frames[0].postMessage(JSON.stringify({'MessageId': 'CallPythonScript', - 'SendTime': Date.now(), - 'ScriptFile': 'Capitalise.py', - 'Function': 'capitalisePython', - 'Values': null - }), - '*'); + post({'MessageId': 'CallPythonScript', + 'SendTime': Date.now(), + 'ScriptFile': 'Capitalise.py', + 'Function': 'capitalisePython', + 'Values': null + }); } // This function is invoked when the iframe posts a message back. function receiveMessage(event) { + console.log('==== framed.doc.html receiveMessage: ' + event.data); var msg = JSON.parse(event.data); - console.log('==== framed.html receiveMessage: ' + event.data); - console.log(' ' + msg); + if (msg && msg.MessageId == 'App_LoadingStatus') { + if (msg.Values) { + if (msg.Values.Status == 'Document_Loaded') { + window.frames[0].postMessage(JSON.stringify({'MessageId': 'Host_PostmessageReady'}), '*'); + } + } + } } // 'main' code of this <script> block, run when page is being _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits