diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2019-06-16 13:28:58 -0400 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2019-07-01 17:38:49 +0200 |
commit | a55f704b2177590d649bda68a7ac770ffbb7f74e (patch) | |
tree | 5d283a098bad2f201b851d9204392b7c7a63e8f6 | |
parent | fbb6e93d5711a71c5824dd4a718ca09be18ff0cd (diff) |
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.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit 0b7cc06e602d8c45fc667d96b1c66ad17fee44bd)
-rw-r--r-- | loleaflet/html/framed.doc.html | 46 |
1 files changed, 26 insertions, 20 deletions
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 |