-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathframed.doc.html
More file actions
732 lines (644 loc) · 25.6 KB
/
framed.doc.html
File metadata and controls
732 lines (644 loc) · 25.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
<!DOCTYPE html>
<!-- Proof of concept of running cool.html in an iframe. Also
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>
<style>
:root {
font-family: "sans-serif";
}
.alert {
font-size: large;
padding: 20px;
background-color: #f44336;
color: white;
margin-bottom: 15px;
}
.framed {
padding: 15px;
border: 1px black dashed;
border-radius: 6px;
}
.vbox {
display: flex;
flex-direction: column;
gap: 0.5em;
}
.hbox {
display: flex;
flex-direction: row;
gap: 0.5em;
}
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 0.5em;
gap: 0.5em;
}
.spaced {
gap: 15px;
grid-gap: 15px;
}
h3 {
margin: 0.2em 0px;
}
pre {
margin: 0px;
}
#messages {
height: 5vh;
overflow: scroll;
}
#messages > p {
margin: 0;
font-family: monospace;
}
</style>
<script>
function post(msg) {
window.frames[0].postMessage(JSON.stringify(msg), '*');
}
function sendBoldUNOCommand() {
post({'MessageId': 'Send_UNO_Command',
'Values': { 'Command': '.uno:Bold' }
});
}
function sendInsertBookMarkUNOCommand() {
post({'MessageId': 'Send_UNO_Command',
'Values': {
'Command': '.uno:InsertBookmark',
'Args': {
Bookmark: {
type: 'string',
value: 'Test Insert BookMark'
},
BookmarkText: {
type: 'string',
value: 'Text of the Test Insert BookMark'
}
}
}
});
}
function insertText(text) {
post({'MessageId': 'CallPythonScript',
'SendTime': Date.now(),
'ScriptFile': 'InsertText.py',
'Function': 'InsertText',
'Values': { 'text': {'type': 'string', 'value': text}}
});
}
function insertGraphic(text) {
post({'MessageId': 'Action_InsertGraphic',
'Values': {'filename': 'date.png', 'url': 'https://sdk.collaboraonline.com/_static/collabora.svg'}
});
}
function capitalize() {
post({'MessageId': 'CallPythonScript',
'SendTime': Date.now(),
'ScriptFile': 'Capitalise.py',
'Function': 'capitalisePython',
'Values': null
});
}
function save() {
post({'MessageId': 'Action_Save',
'Values': { 'Notify': true, 'ExtendedData': 'CustomFlag=Custom Value;AnotherFlag=AnotherValue' }
});
}
function closeDocument() {
post({'MessageId': 'Action_Close',
'Values': null
});
}
function closeSession() {
post({'MessageId': 'Close_Session',
'Values': null
});
}
function fullscreenDocument() {
post({'MessageId': 'Action_Fullscreen',
'Values': null
});
}
function startPresentation() {
post({'MessageId': 'Action_FullscreenPresentation',
'Values': null
});
}
function exportAsHtml() {
post({'MessageId': 'Action_Export',
'Values': { 'Format': 'html', }
});
}
function exportAsPdfWithNotify() {
post({'MessageId': 'Action_Export',
'Values': { 'Format': 'pdf', Notify: true }
});
}
function getExportFormats() {
post({'MessageId': 'Get_Export_Formats',
'Values': null
});
}
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, }
});
}
function disable_default_uiaction(action, disable) {
post({'MessageId': 'Disable_Default_UIAction',
'Values': { 'action': action, 'disable': disable }
});
}
function ShowSave(show) {
if (show) {
show_commands('save');
show_commands('file-save');
} else {
hide_commands('save');
hide_commands('file-save');
}
}
function HintOnscreenKeyboard(hint) {
post({'MessageId': hint ? 'Hint_OnscreenKeyboard' : 'Hint_NoOnscreenKeyboard',
'Values': null
});
}
function ShowMenubar(visible) {
var messageId = visible ? 'Show_Menubar' : 'Hide_Menubar';
post({'MessageId': messageId});
}
function ShowRuler(visible) {
var messageId = visible ? 'Show_Ruler' : 'Hide_Ruler';
post({'MessageId': messageId});
}
function ShowSidebar(visible) {
let messageId = visible ? 'Show_Sidebar' : 'Hide_Sidebar';
post({'MessageId': messageId});
}
function ShowNavigator(visible) {
if (visible) {
post({
'MessageId': 'Show_Navigator',
'Values': { 'id': 'Navigator' }
});
} else {
post({'MessageId': 'Hide_Sidebar'});
}
}
function ShowStatusBar(visible) {
var messageId = visible ? 'Show_StatusBar' : 'Hide_StatusBar';
post({'MessageId': messageId});
}
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'}
});
}
function ShowInsertContextualButton() {
post({'MessageId': 'Insert_ContextualButton',
'Values': { 'id': 'context-cut', 'imgurl': 'lc_cut.svg', 'hint': 'Cut (added via postmessage)', 'unoCommand': '.uno:Cut'}
});
}
function ShowNotebookbar(notebookbar) {
var value = notebookbar ? 'notebookbar' : 'classic';
post({'MessageId': 'Action_ChangeUIMode',
'Values': {'Mode': value}});
}
function CollapseNotebookbar(collapse) {
post({'MessageId': collapse ? 'Collapse_Notebookbar' : 'Extend_Notebookbar',
'Values': null
});
}
// Wrap the message execution to catch exceptions
function executeMessage() {
let paramArea = document.getElementById('execute-param');
if (!paramArea.checkValidity()) {
paramArea.reportValidity();
return;
}
try {
Execute(
document.getElementById('execute-message').value,
JSON.parse(paramArea.value)
);
} catch(e) {
console.error("Execute message error:", e);
}
}
function Execute(messageId, values) {
post({'MessageId': messageId, 'Values': values});
}
function reset_access_token(accesstoken, ttl) {
post({'MessageId': 'Reset_Access_Token',
'Values': { 'token': accesstoken, 'ttl': ttl }
});
}
function GetUserState() {
post({'MessageId': 'Get_User_State',
'Values': null
});
}
function DisplayUserState(msg) {
var display = document.getElementById("DisplayUserState");
display.querySelector("#UserState_State").textContent = msg.Values.State;
display.querySelector("#UserState_Elapsed").textContent = msg.Values.Elapsed;
}
function ClearMessages() {
let messageOut = document.getElementById("messages");
let child;
while (child = messageOut.firstChild) {
child.remove();
}
}
// 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);
if (!msg) {
return;
}
let messageOut = document.getElementById("messages");
let line = document.createElement("p");
line.textContent = JSON.stringify(msg);
messageOut.append(line);
if (msg.MessageId == 'App_LoadingStatus') {
if (msg.Values) {
if (msg.Values.Status == 'Document_Loaded') {
post({'MessageId': 'Host_PostmessageReady'});
}
}
} 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 == 'Get_User_State_Resp') {
DisplayUserState(msg);
} else if (msg.MessageId == 'Action_Save_Resp') {
if (msg.Values) {
if (msg.Values.success == true) {
document.getElementById("ModifiedStatus").innerHTML = "Saved";
} else {
document.getElementById("ModifiedStatus").innerHTML = "Error during save";
}
}
} else if (msg.MessageId === 'UI_Mention') {
var dummyUserDatabase = [ {
username:'Abigail',
profile: 'Abigail profile link'
},
{
username: 'Alexandra',
profile: 'Alexandra profile link'
},
{
username: 'Alison',
profile: 'Alison profile link'
},
{
username: 'Amanda',
profile: 'Amanda profile link'
},
{
username: 'Amelia',
profile: 'Amelia profile link'
},
{
username: 'Amy',
profile: 'Amy profile link'
},
{
username: 'Andrea',
profile: 'Andrea profile link'
},
{
username: 'Angela',
profile: 'Angela profile link'
},
{
username: 'Anna',
profile: 'Anna profile link'
},
{
username: 'Anne',
profile: 'Anne profile link'
},
{
username: 'Audrey',
profile: 'Audrey profile link'
},
{
username: 'Ava',
profile: 'Ava profile link'
},
{
username: 'Bella',
profile: 'Bella profile link'
},
{
username: 'Bernadette',
profile: 'Bernadette profile link'
},
{
username: 'Carol',
profile: 'Carol profile link'
},
{
username: 'Caroline',
profile: 'Caroline profile link'
},
{
username: 'Carolyn',
profile: 'Carolyn profile link'
},
{
username: 'xyz abc',
profile: 'xyz abc profile link'
} ];
if (msg.Values) {
var type = msg.Values.type;
var text = msg.Values.text;
var users = [];
dummyUserDatabase.forEach(element => {
if (element.username.includes(text))
users.push(element);
});
if (type === 'autocomplete')
{
setTimeout(post, 0,
{
'MessageId': 'Action_Mention',
'SendTime': Date.now(),
'Values': {
'list': users,
}
});
}
}
} else if (msg.MessageId == 'Get_Export_Formats_Resp') {
if (msg.Values) {
alert(JSON.stringify(msg.Values));
} else {
alert('Response is empty');
}
}
}
// 'main' code of this <script> block, run when page is being
// rendered. Install the message listener.
window.addEventListener("message", receiveMessage, false);
var frameUrl = new URL(window.location);
frameUrl.pathname = frameUrl.pathname.substr(0, window.location.pathname.lastIndexOf('/') + 1) + 'cool.html';
frameUrl.searchParams.append('NotWOPIButIframe', 'true');
function startCool(url, file_path) {
var coolUrl = new URL(url);
if (file_path) {
coolUrl.searchParams.set('file_path', file_path);
}
var iframe = document.getElementById('frame');
iframe.src = coolUrl.href;
link.href = coolUrl.href;
}
// Select the app with extension.
function selectApp(ext) {
let filename;
switch (ext) {
case 'fodt':
filename = 'writer-edit.fodt';
break;
case 'ods':
filename = 'calc-edit.ods';
break;
case 'fodp':
filename = 'impress-edit.fodp';
break;
case 'odg':
filename = 'draw-edit.odg';
break;
default:
console.error('Invalid app ', ext);
return;
}
let params = frameUrl.searchParams;
let file_path = params.get('file_path');
let index = file_path.lastIndexOf('/');
file_path = file_path.substr(0, index + 1) + filename;
startCool(frameUrl, file_path);
}
document.addEventListener("DOMContentLoaded", function(event) {
let paramArea = document.getElementById('execute-param');
paramArea.checkValidity = () => {
let valid = true;
try {
JSON.parse(paramArea.value);
paramArea.setCustomValidity('');
} catch(e) {
paramArea.setCustomValidity("Not valid json : \n" + e);
valid = false;
}
return valid;
};
});
</script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<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>
http://localhost:9980/browser/dist/framed.doc.html?file_path=file:///path/to/document/hello-world.odt
</p>
</div>
<div id="post-message-test-harness" class="vbox">
<h2>PostMessage test harness</h2>
<div class="grid spaced">
<div class="vbox framed">
<h3>Run python scripts</h3>
<form id="insert-text-form" class="vbox">
<label for="fname"><b>InsertText.py</b>: inserts text into the document</label>
<textarea name="source" value="" rows="5" cols="50">Type your text and press Insert text</textarea>
<div>
<button onclick="insertText(document.forms['insert-text-form'].elements['source'].value); return false;">Insert text</button>
</div>
</form>
<form id="insert-text-form" class="vbox">
<label for="fname"><b>Capitalize.py</b>: capitalize selected text in the document</label>
<div>
<button onclick="capitalize(); return false;">Capitalize selected text</button>
</div>
</form>
</div>
<div class="vbox framed">
<h3>Various other messages to post</h3>
<div class="grid">
<button onclick="save(); return false;">Save</button>
<div></div>
<button onclick="closeDocument(); return false;">Close</button>
<button onclick="closeSession(); return false;">Close Session</button>
<button onclick="fullscreenDocument(); return false;">Fullscreen</button>
<button onclick="startPresentation(); return false;">Start presentation</button>
<button onclick="exportAsHtml(); return false;">Export as HTML</button>
<button onclick="exportAsPdfWithNotify(); return false;">Export as PDF with Notify set</button>
<button onclick="getExportFormats(); return false;">Get export formats</button>
<div></div>
<button onclick="ShowSave(false); return false;">Hide Save Commands</button>
<button onclick="ShowSave(true); return false;">Show Save Commands</button>
<button onclick="hide_commands('print'); return false;">Hide Print Commands</button>
<button onclick="show_commands('print'); return false;">Show Print Commands</button>
<button onclick="disable_default_uiaction('UI_Save', true); return false;">Disable default save action</button>
<button onclick="disable_default_uiaction('UI_Save', false); return false;">Enable default save action</button>
<button onclick="HintOnscreenKeyboard(true); return false;">Hint that there is an onscreen keyboard</button>
<button onclick="HintOnscreenKeyboard(false); return false;">Hint that there is not an onscreen keyboard</button>
</div>
</div>
<form class="vbox framed">
<h3>New Access-Token</h3>
<label for="new-access-token"><b>Access Token:</b></label>
<textarea name="new-access-token" id="new-access-token" value="" rows="1" cols="30">123456789AA</textarea>
<label for="new-access-token-ttl"><b>Access Token TTL (millis since epoch when the token will expire):</b></label>
<textarea name="new-access-token-ttl" id="new-access-token-ttl" value="" rows="1" cols="30"></textarea>
<div>
<button
onclick="reset_access_token(document.getElementById('new-access-token').value, document.getElementById('new-access-token-ttl').value); return false;">Reset
Access-Token</button>
</div>
<h3>User State</h3>
<div class="hbox">
<button onclick="GetUserState(); return false;">Get User State</button>
<div id="DisplayUserState">
<p>State: <span id="UserState_State">unknown</span>
Elapsed: <span id="UserState_Elapsed">0</span> sec.</p>
</div>
</div>
</form>
<div class="vbox framed">
<h3>Send a message</h3>
<form>
<div class="hbox">
<div>
<label for="execute-message"><b>Message</b>: </label><br>
<input type="text" name="execute-message" id="execute-message" />
</div>
<div>
<label for="execute-param"><b>Values</b>: </label>
<p>This is the JSON format 'Values'.</p>
<textarea name="execute-param" id="execute-param">{}</textarea>
</div>
</div>
<button onclick="executeMessage(); return false;">Execute</button>
</form>
</div>
</div>
<div class="framed hbox">
<div class="vbox">
<h3>Messages from editor <button onclick="ClearMessages();">Clear</button></h3>
<div id="messages"></div>
</div>
</div>
<div class="vbox">
<h3>Modified Status: <span id="ModifiedStatus">Saved</span></h3>
</div>
<div class="grid spaced">
<div class="framed">
<h3>UI modification</h3>
<div class="hbox">
<div class="vbox">
<button onclick="ShowMenubar(false); return false;">Hide Menubar</button>
<button onclick="ShowMenubar(true); return false;">Show Menubar</button>
</div>
<div class="vbox">
<button onclick="ShowInsertButton(); return false;" title="via Insert_Button">Insert custom button</button>
<button onclick="ShowInsertContextualButton(); return false;" title="via Insert_ContextualButton">Insert custom button to contextual toolbar</button>
<button onclick="insertGraphic(); return false;">Sent InsertGraphic post message</button>
</div>
<div class="vbox">
<button onclick="ShowNotebookbar(false); return false;">Compact Toolbar</button>
<button onclick="ShowNotebookbar(true); return false;">Tabbed Toolbar</button>
</div>
<div class="vbox">
<button onclick="CollapseNotebookbar(true); return false;">Collapse Tabbed Toolbar</button>
<button onclick="CollapseNotebookbar(false); return false;">Extend Tabbed Toolbar</button>
</div>
<div class="vbox">
<button onclick="ShowStatusBar(false); return false;">Hide Status Bar</button>
<button onclick="ShowStatusBar(true); return false;">Show Status Bar</button>
</div>
<div class="vbox">
<button onclick="ShowRuler(false); return false;">Hide Ruler</button>
<button onclick="ShowRuler(true); return false;">Show Ruler</button>
</div>
<div class="vbox">
<button onclick="ShowSidebar(false); return false;">Hide Sidebar</button>
<button onclick="ShowSidebar(true); return false;">Show Sidebar</button>
</div>
<div class="vbox">
<button onclick="ShowNavigator(false); return false;">Hide Navigator</button>
<button onclick="ShowNavigator(true); return false;">Show Navigator</button>
</div>
</div>
</div>
<div class="vbox framed">
<h3>Send UNO Commands</h3>
<div class="hbox">
<button onclick="sendBoldUNOCommand(); return false;">Send Bold UNO Command (an example without args)</button>
<button onclick="sendInsertBookMarkUNOCommand(); return false;">Send InsertBookmark UNO Command (an example with args)</button>
</div>
</div>
</div>
<div class="vbox">
<h3>Document type</h3>
</div>
<div class="vbox framed">
<div class="hbox">
<button onclick="selectApp('fodt');">Writer</button>
<button onclick="selectApp('ods');">Calc</button>
<button onclick="selectApp('fodp');">Impress</button>
<button onclick="selectApp('odg');">Draw</button>
</div>
</div>
<h3>Document frame</h3>
<h4>If the frame fails to load click <a id="link">here and accept security bits</a></h4>
<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>
<div class="vbox">
<iframe id="frame" height="1000" allow="fullscreen"></iframe>
</div>
<script>
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 url = new URL(window.location);
var params = url.searchParams;
startCool(frameUrl, params.get("file_path"));
</script>
</body>
</html>