2018-07-26 23:16:50 -05:00
|
|
|
<!DOCTYPE html>
|
|
|
|
|
2021-10-26 08:23:28 -05:00
|
|
|
<!-- Proof of concept of running cool.html in an iframe. Also
|
2018-07-26 23:16:50 -05:00
|
|
|
shows how to, from outside the iframe, invoke Python scripting in
|
|
|
|
the underlying LibreOffice instance that manipulates the document
|
|
|
|
being edited.
|
|
|
|
|
|
|
|
This demonstrates using the Python InsertText.py and Capitalise.py
|
|
|
|
scripts from javascript across iframes.
|
|
|
|
-->
|
|
|
|
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
|
|
<title>Online Editor</title>
|
|
|
|
|
2020-11-14 09:03:16 -06:00
|
|
|
<style>
|
|
|
|
.alert {
|
|
|
|
font-size: large;
|
|
|
|
padding: 20px;
|
|
|
|
background-color: #f44336;
|
|
|
|
color: white;
|
|
|
|
margin-bottom: 15px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2018-07-26 23:16:50 -05:00
|
|
|
<script>
|
|
|
|
|
2019-06-16 12:28:58 -05:00
|
|
|
function post(msg) {
|
|
|
|
window.frames[0].postMessage(JSON.stringify(msg), '*');
|
|
|
|
}
|
|
|
|
|
2018-07-26 23:16:50 -05:00
|
|
|
function insertText(text) {
|
2019-06-16 12:28:58 -05:00
|
|
|
post({'MessageId': 'CallPythonScript',
|
|
|
|
'SendTime': Date.now(),
|
|
|
|
'ScriptFile': 'InsertText.py',
|
|
|
|
'Function': 'InsertText',
|
|
|
|
'Values': { 'text': {'type': 'string', 'value': text}}
|
|
|
|
});
|
2018-07-26 23:16:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function capitalize() {
|
2019-06-16 12:28:58 -05:00
|
|
|
post({'MessageId': 'CallPythonScript',
|
|
|
|
'SendTime': Date.now(),
|
|
|
|
'ScriptFile': 'Capitalise.py',
|
|
|
|
'Function': 'capitalisePython',
|
|
|
|
'Values': null
|
|
|
|
});
|
2018-07-26 23:16:50 -05:00
|
|
|
}
|
|
|
|
|
2019-06-15 19:56:28 -05:00
|
|
|
function save() {
|
|
|
|
post({'MessageId': 'Action_Save',
|
2019-11-16 10:59:39 -06:00
|
|
|
'Values': { 'Notify': true, 'ExtendedData': 'CustomFlag=Custom Value;AnotherFlag=AnotherValue' }
|
2019-06-15 19:56:28 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-15 19:58:49 -05:00
|
|
|
function closeDocument() {
|
|
|
|
post({'MessageId': 'Action_Close',
|
|
|
|
'Values': null
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-15 19:56:28 -05:00
|
|
|
function hide_commands(id) {
|
|
|
|
post({'MessageId': 'Hide_Menu_Item',
|
|
|
|
'Values': { 'id': id, }
|
|
|
|
});
|
|
|
|
post({'MessageId': 'Hide_Button',
|
|
|
|
'Values': { 'id': id, }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_commands(id) {
|
|
|
|
post({'MessageId': 'Show_Menu_Item',
|
|
|
|
'Values': { 'id': id, }
|
|
|
|
});
|
|
|
|
post({'MessageId': 'Show_Button',
|
|
|
|
'Values': { 'id': id, }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-16 12:16:20 -05:00
|
|
|
function disable_default_uiaction(action, disable) {
|
|
|
|
post({'MessageId': 'Disable_Default_UIAction',
|
|
|
|
'Values': { 'action': action, 'disable': disable }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-14 10:54:08 -06:00
|
|
|
function ShowMenubar(visible) {
|
|
|
|
var messageId = visible ? 'Show_Menubar' : 'Hide_Menubar';
|
2022-05-05 04:32:12 -05:00
|
|
|
post({'MessageId': 'Host_PostmessageReady'});
|
|
|
|
post({'MessageId': messageId});
|
2020-01-14 10:54:08 -06:00
|
|
|
}
|
|
|
|
|
2022-02-18 05:16:20 -06:00
|
|
|
function ShowInsertButton() {
|
|
|
|
post({'MessageId': 'Insert_Button',
|
|
|
|
'Values': { 'id': 'Save', 'imgurl': 'images/lc_save.svg', 'hint': '', 'mobile': false, 'label': 'Show additional btns via Insert_Button', 'insertBefore': 'Save', 'unoCommand': '.uno:Save'}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-27 10:37:24 -06:00
|
|
|
function ShowNotebookbar(notebookbar) {
|
|
|
|
var value = notebookbar ? 'notebookbar' : 'classic';
|
2022-05-05 04:32:12 -05:00
|
|
|
post({'MessageId': 'Host_PostmessageReady'});
|
2022-05-05 17:17:38 -05:00
|
|
|
post({'MessageId': 'Action_ChangeUIMode',
|
|
|
|
'Values': {'Mode': value}});
|
|
|
|
}
|
|
|
|
|
|
|
|
function reset_access_token(accesstoken) {
|
|
|
|
post({'MessageId': 'Reset_Access_Token',
|
|
|
|
'Values': { 'token': accesstoken, }
|
|
|
|
});
|
2021-02-27 10:37:24 -06:00
|
|
|
}
|
|
|
|
|
2018-07-26 23:16:50 -05:00
|
|
|
// This function is invoked when the iframe posts a message back.
|
|
|
|
|
|
|
|
function receiveMessage(event) {
|
2019-06-16 12:28:58 -05:00
|
|
|
console.log('==== framed.doc.html receiveMessage: ' + event.data);
|
2018-07-26 23:16:50 -05:00
|
|
|
var msg = JSON.parse(event.data);
|
2019-06-29 09:52:11 -05:00
|
|
|
if (!msg) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (msg.MessageId == 'App_LoadingStatus') {
|
2019-06-16 12:28:58 -05:00
|
|
|
if (msg.Values) {
|
|
|
|
if (msg.Values.Status == 'Document_Loaded') {
|
2022-05-05 04:32:12 -05:00
|
|
|
post({'MessageId': 'Host_PostmessageReady'});
|
2019-06-16 12:28:58 -05:00
|
|
|
}
|
|
|
|
}
|
2019-06-29 09:52:11 -05:00
|
|
|
} else if (msg.MessageId == 'Doc_ModifiedStatus') {
|
|
|
|
if (msg.Values) {
|
|
|
|
if (msg.Values.Modified == true) {
|
|
|
|
document.getElementById("ModifiedStatus").innerHTML = "Modified";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("ModifiedStatus").innerHTML = "Saved";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (msg.MessageId == 'Action_Save_Resp') {
|
|
|
|
if (msg.Values) {
|
|
|
|
if (msg.Values.success == true) {
|
|
|
|
document.getElementById("ModifiedStatus").innerHTML = "Saved";
|
2020-05-19 04:45:04 -05:00
|
|
|
} else {
|
|
|
|
document.getElementById("ModifiedStatus").innerHTML = "Error during save";
|
2019-06-29 09:52:11 -05:00
|
|
|
}
|
|
|
|
}
|
2019-06-16 12:28:58 -05:00
|
|
|
}
|
2018-07-26 23:16:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// 'main' code of this <script> block, run when page is being
|
|
|
|
// rendered. Install the message listener.
|
|
|
|
window.addEventListener("message", receiveMessage, false);
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
</head>
|
|
|
|
|
2020-11-14 09:03:16 -06:00
|
|
|
<body>
|
|
|
|
<div id="usage" class="alert" style="display:none">
|
|
|
|
<h2>Usage</h2>
|
|
|
|
<p>
|
|
|
|
Load this page via https or http, depending on whether SSL is enabled or not, from the Online server directly.</br>
|
|
|
|
The document to load must be given as a query parameter called file_path. The document can be any accessible URL, including on disk, via file://.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<h4>Example</h4>
|
|
|
|
<p>
|
2021-11-03 09:07:20 -05:00
|
|
|
http://localhost:9980/browser/dist/framed.doc.html?file_path=file:///path/to/document/hello-world.odt
|
2020-11-14 09:03:16 -06:00
|
|
|
</p>
|
|
|
|
</div>
|
2018-07-26 23:16:50 -05:00
|
|
|
|
2020-01-14 10:54:08 -06:00
|
|
|
<h3>PostMessage test harness</h3>
|
|
|
|
|
2022-02-18 05:40:19 -06:00
|
|
|
<h4>Run python scripts</h4>
|
2018-07-26 23:16:50 -05:00
|
|
|
<form id="insert-text-form">
|
2022-02-18 05:40:19 -06:00
|
|
|
<label for="fname"><b>InsertText.py</b>: inserts text into the document</label><br>
|
|
|
|
<textarea name="source" value="" rows="5" cols="50">Type your text and press Insert text</textarea><br>
|
|
|
|
<button onclick="insertText(document.forms['insert-text-form'].elements['source'].value); return false;">Insert text</button>
|
2018-07-26 23:16:50 -05:00
|
|
|
</form>
|
2022-02-18 05:40:19 -06:00
|
|
|
<br>
|
2018-07-26 23:16:50 -05:00
|
|
|
<form id="insert-text-form">
|
2022-02-18 05:40:19 -06:00
|
|
|
<label for="fname"><b>Capitalize.py</b>: capitalize selected text in the document</label><br>
|
|
|
|
<button onclick="capitalize(); return false;">Capitalize selected text</button></br></br>
|
2020-01-14 10:54:08 -06:00
|
|
|
</form>
|
|
|
|
|
|
|
|
<h4>Various other messages to post</h4>
|
|
|
|
<form>
|
2019-06-15 19:58:49 -05:00
|
|
|
<button onclick="save(); return false;">Save</button>
|
|
|
|
<button onclick="closeDocument(); return false;">Close</button></br></br>
|
2019-06-15 19:56:28 -05:00
|
|
|
<button onclick="hide_commands('save'); return false;">Hide Save Commands</button>
|
|
|
|
<button onclick="show_commands('save'); return false;">Show Save Commands</button></br>
|
|
|
|
<button onclick="hide_commands('print'); return false;">Hide Print Commands</button>
|
|
|
|
<button onclick="show_commands('print'); return false;">Show Print Commands</button></br></br>
|
2019-06-16 12:16:20 -05:00
|
|
|
<button onclick="disable_default_uiaction('UI_Save', true); return false;">Disable default save action</button></br>
|
|
|
|
<button onclick="disable_default_uiaction('UI_Save', false); return false;">Enable default save action</button></br></br>
|
2022-05-05 17:17:38 -05:00
|
|
|
<label for="new-access-token"><b>New Access-Token</b>: </label><br>
|
|
|
|
<textarea name="new-access-token" id="new-access-token" value="" rows="1" cols="30">123456789AA</textarea><br>
|
|
|
|
<button onclick="reset_access_token(document.getElementById('new-access-token').value); return false;">Reset Access-Token</button>
|
2018-07-26 23:16:50 -05:00
|
|
|
</form>
|
|
|
|
|
2020-01-14 10:54:08 -06:00
|
|
|
<h3>Modified Status: <span id="ModifiedStatus">Saved</span></h3>
|
|
|
|
|
|
|
|
<h3>UI modification</h3>
|
|
|
|
<form id="menubar-toggle">
|
|
|
|
<button onclick="ShowMenubar(false); return false;">Hide Menubar</button>
|
|
|
|
<button onclick="ShowMenubar(true); return false;">Show Menubar</button>
|
2022-02-18 05:16:20 -06:00
|
|
|
<button onclick="ShowInsertButton(); return false;" title="via Insert_Button">Insert custom button</button>
|
2021-02-27 10:37:24 -06:00
|
|
|
<p>
|
2022-04-22 05:00:00 -05:00
|
|
|
<button onclick="ShowNotebookbar(false); return false;">Compact Toolbar</button>
|
|
|
|
<button onclick="ShowNotebookbar(true); return false;">Tabbed Toolbar</button>
|
2020-01-14 10:54:08 -06:00
|
|
|
</form>
|
2019-06-29 09:52:11 -05:00
|
|
|
|
2020-01-14 10:54:08 -06:00
|
|
|
<h3>Document frame</h3>
|
2020-01-14 11:48:26 -06:00
|
|
|
<h4>If the frame fails to load click <a id="link">here and accept security bits</a></h4>
|
2021-11-18 06:08:14 -06:00
|
|
|
<h4>If the frame still fails to load ensure you have <code>localhost:*</code> included in your <code>net.frame_ancestors</code> in coolwsd.xml</h4>
|
2020-01-14 10:54:08 -06:00
|
|
|
<iframe id="frame" height="1000" width="1000"></iframe>
|
2018-07-26 23:16:50 -05:00
|
|
|
|
2020-01-14 10:54:08 -06:00
|
|
|
<script>
|
2020-11-14 09:03:16 -06:00
|
|
|
if (document.location.protocol == 'file:' || window.location.search == '') {
|
|
|
|
document.getElementById("usage").style.display = "block";
|
|
|
|
alert('Incorrect usage, please follow the instructions at the top of this page.');
|
|
|
|
}
|
|
|
|
|
|
|
|
var query = '?';
|
|
|
|
if (window.location.search !== '')
|
|
|
|
query = window.location.search + '&';
|
|
|
|
query += 'NotWOPIButIframe=true';
|
|
|
|
|
2021-10-26 08:23:28 -05:00
|
|
|
var path = window.location.pathname.substr(0, window.location.pathname.lastIndexOf('/') + 1) + 'cool.html';
|
2020-11-14 09:03:16 -06:00
|
|
|
var uriBase = window.location.protocol + '//' + window.location.host + path + query;
|
2020-01-14 10:54:08 -06:00
|
|
|
var iframe = document.getElementById("frame");
|
2020-11-14 09:03:16 -06:00
|
|
|
iframe.src = uriBase;
|
2020-01-14 11:48:26 -06:00
|
|
|
link.href = uriBase;
|
2020-01-14 10:54:08 -06:00
|
|
|
</script>
|
2018-07-26 23:16:50 -05:00
|
|
|
</body>
|
|
|
|
</html>
|