-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapi.js
More file actions
1339 lines (1205 loc) · 61.5 KB
/
api.js
File metadata and controls
1339 lines (1205 loc) · 61.5 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
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) Ascensio System SIA 2013. All rights reserved
*
* http://www.onlyoffice.com
*/
;(function(DocsAPI, window, document, undefined) {
/*
# Full #
config = {
type: 'desktop or mobile or embedded',
width: '100% by default',
height: '100% by default',
documentType: 'word' | 'cell' | 'slide' | 'pdf' | 'diagram' ,// deprecate 'text' | 'spreadsheet' | 'presentation',
token: <string> encrypted signature
document: {
title: 'document title',
url: 'document url'
fileType: 'document file type',
options: <advanced options>,
key: 'key',
vkey: 'vkey',
referenceData: 'data for external paste',
info: {
owner: 'owner name',
folder: 'path to document',
uploaded: '<uploaded date>',
sharingSettings: [
{
user: 'user name',
permissions: '<permissions>',
isLink: false
},
...
],
favorite: '<file is favorite>' // true/false/undefined (undefined - don't show fav. button)
},
permissions: {
edit: <can edit>, // default = true
download: <can download>, // default = true
reader: <can view in readable mode>,
review: <can review>, // default = edit
print: <can print>, // default = true
comment: <can comment in view mode> // default = edit,
modifyFilter: <can add, remove and save filter in the spreadsheet> // default = true
modifyContentControl: <can modify content controls in documenteditor> // default = true
fillForms: <can edit forms in view mode> // default = edit || review,
copy: <can copy data> // default = true,
editCommentAuthorOnly: <can edit your own comments only> // default = false
deleteCommentAuthorOnly: <can delete your own comments only> // default = false,
reviewGroups: ["Group1", ""] // current user can accept/reject review changes made by users from Group1 and users without a group. [] - use groups, but can't change any group's changes
commentGroups: { // {} - use groups, but can't view/edit/delete any group's comments
view: ["Group1", ""] // current user can view comments made by users from Group1 and users without a group.
edit: ["Group1", ""] // current user can edit comments made by users from Group1 and users without a group.
remove: ["Group1", ""] // current user can remove comments made by users from Group1 and users without a group.
},
userInfoGroups: ["Group1", ""], // show tooltips/cursors/info in header only for users in userInfoGroups groups. [""] - means users without group, [] - don't show any users, null/undefined/"" - show all users
protect: <can protect document> // default = true. show/hide protect tab or protect buttons,
chat: <true>
}
},
editorConfig: {
actionLink: { // open file and scroll to data, used with onMakeActionLink or the onRequestSendNotify event
action: {
type: "bookmark", // or type="comment"
data: <bookmark name> // or comment id
}
},
mode: 'view or edit',
lang: <language code>,
location: <location>,
canCoAuthoring: <can coauthoring documents>,
canBackToFolder: <can return to folder> - deprecated. use "customization.goback" parameter,
createUrl: 'create document url',
sharingSettingsUrl: 'document sharing settings url',
fileChoiceUrl: 'source url', // for mail merge or image from storage
callbackUrl: <url for connection between sdk and portal>,
mergeFolderUrl: 'folder for saving merged file', // must be deprecated, use saveAsUrl instead
saveAsUrl: 'folder for saving files'
licenseUrl: <url for license>,
customerId: <customer id>,
region: <regional settings> // can be 'en-us' or lang code
user: {
id: 'user id',
name: 'user name',
group: 'group name' // for customization.reviewPermissions or permissions.reviewGroups or permissions.commentGroups. Can be multiple groups separated by commas (,) : 'Group1' or 'Group1,Group2'
image: 'image url',
roles: ['Role1'] // used for pdf-forms, fill form with Role1
},
recent: [
{
title: 'document title',
url: 'document url',
folder: 'path to document',
},
...
],
templates: [
{
title: 'template name', // name - is deprecated
image: 'template icon url',
url: 'http://...'
},
...
],
customization: {
logo: {
image: url,
imageDark: url, // logo for dark theme
imageLight: url, // logo for light header
imageEmbedded: url, // deprecated, use image instead
url: http://...,
visible: true // hide logo if visible=false
},
customer: {
name: 'SuperPuper',
address: 'New-York, 125f-25',
mail: 'support@gmail.com',
www: 'www.superpuper.com',
phone: '1234567890',
info: 'Some info',
logo: '',
logoDark: '', // logo for dark theme
},
about: true,
feedback: {
visible: false,
url: http://...
},
goback: {
url: 'http://...',
text: 'Go to London',
blank: true,
requestClose: false // if true - goback send onRequestClose event instead opening url, deprecated, use customization.close instead
},
close: {
visible: true,
text: 'Close file'
},
reviewPermissions: {
"Group1": ["Group2"], // users from Group1 can accept/reject review changes made by users from Group2
"Group2": ["Group1", "Group2"] // users from Group2 can accept/reject review changes made by users from Group1 and Group2
"Group3": [""] // users from Group3 can accept/reject review changes made by users without a group
},
anonymous: { // set name for anonymous user
request: bool (default: true), // enable set name
label: string (default: "Guest") // postfix for user name
},
review: {
hideReviewDisplay: false, // hide button Review mode
hoverMode: false, // true - show review balloons on mouse move, not on click on text
showReviewChanges: false,
reviewDisplay: 'original', // original for viewer, markup for editor
trackChanges: undefined // true/false - open editor with track changes mode on/off,
},
layout: { // hide elements, but don't disable feature
toolbar: {
file: { // menu file
close: false / true, // close menu button
settings: false / true, // advanced settings
info: false / true // document info
save: false/true // save button
} / false / true,
home: {
mailmerge: false/true // mail merge button // deprecated, button is moved to collaboration tab. use toolbar->collaboration->mailmerge instead
},
insert: {
file: false/true // text from file button in de
field: false/true // field button in de
}, false / true, // insert tab
layout: {
pagecolor: false/true // page color button in de
}, false / true, // layout tab
references: false / true, // de references tab
collaboration: {
mailmerge: false/true // mail merge button in de
} / false / true, // collaboration tab
draw: false / true // draw tab
protect: false / true, // protect tab
plugins: false / true // plugins tab
view: {
navigation: false/true // navigation button in de
} / false / true, // view tab
save: false/true // save button on toolbar in
} / false / true, // use instead of customization.toolbar,
header: {
users: false/true // users list button
save: false/true // save button
editMode: false/true // change mode button
user: false/true // icon of current user
},
leftMenu: {
navigation: false/true,
spellcheck: false/true // spellcheck button in sse,
mode: false/true // init value for left panel, true - is visible, false - is hidden, used for option "Left panel" on the View Tab
} / false / true, // use instead of customization.leftMenu
rightMenu: {
mode: false/true // init value for right panel, true - is visible, false - is hidden, used for option "Right panel" on the View Tab
} / false/true, // use instead of customization.rightMenu
statusBar: {
textLang: false/true // text language button in de/pe
docLang: false/true // document language button in de/pe
actionStatus: false/true // status of operation
} / false / true, // use instead of customization.statusBar
},
features: { // disable feature
spellcheck: {
mode: false/true // init value in de/pe
change: false/true // hide/show feature in de/pe/sse
} / false / true // if false/true - use as init value in de/pe. use instead of customization.spellcheck parameter
roles: false/true // hide/show Roles manager, roles settings in right panel and roles in View form button in de
tabStyle: {
mode: 'fill'/'line' // init value, 'fill' by default,
change: true/false // show/hide feature
} / 'fill'/'line' // if string - use as init value
tabBackground: {
mode: 'header'/'toolbar' // init value, 'header' by default
change: true/false // show/hide feature
} / 'header'/'toolbar' // if string - use as init value,
featuresTips: false/true // show tips about new feature
},
font: {
name: "Arial",
size: "11px";
},
chat: true, // deprecated 7.1, use permissions.chat
comments: true,
zoom: 100,
compactToolbar: false,
leftMenu: true, // must be deprecated. use layout.leftMenu instead
rightMenu: true, // must be deprecated. use layout.rightMenu instead
hideRightMenu: true, // hide or show right panel on first loading !! default value changed in 8.1
toolbar: true, // must be deprecated. use layout.toolbar instead
statusBar: true, // must be deprecated. use layout.statusBar instead
autosave: true,
forcesave: false,
commentAuthorOnly: false, // must be deprecated. use permissions.editCommentAuthorOnly and permissions.deleteCommentAuthorOnly instead
showReviewChanges: false, // must be deprecated. use customization.review.showReviewChanges instead
help: true,
compactHeader: false,
toolbarNoTabs: false, // must be deprecated. use features.tabStyle.mode='line' && features.tabBackground='toolbar' instead
toolbarHideFileName: false,
reviewDisplay: 'original', // must be deprecated. use customization.review.reviewDisplay instead
spellcheck: true, // must be deprecated. use customization.features.spellcheck instead
compatibleFeatures: false,
unit: 'cm' // cm, pt, inch,
mentionShare : true // customize tooltip for mention,
macros: true // can run macros in document
plugins: true // can run plugins in document
macrosMode: 'warn' // warn about automatic macros, 'enable', 'disable', 'warn',
trackChanges: undefined // true/false - open editor with track changes mode on/off, // must be deprecated. use customization.review.trackChanges instead
hideRulers: false // hide or show rulers on first loading (presentation or document editor)
hideNotes: false // hide or show notes panel on first loading (presentation editor)
uiTheme: 'theme-dark' // set interface theme: id or default-dark/default-light
integrationMode: "embed" // turn off scroll to frame
pointerMode: 'select'/'hand' // set cursor mode in presentation/document viewer, select by default
mobile: {
forceView: true/false (default: true) // turn on/off the 'reader' mode on launch. for mobile document editor only
standardView: true/false (default: false) // open editor in 'Standard view' instead of 'Mobile view'
disableForceDesktop: false // hide or show UI option to switch editor in 'Desktop' type
},
submitForm: {
visible: true/false (default: true)
resultMessage: 'text'/''/null/undefined // if '' - don't show a message after submitting form, null/undefined - show the default message
},
forceWesternFontSize: false/true, // used only in the document editor with lang=zh, Chinese by default
slidePlayerBackground: '#000000', // background color for slide show in presentation editor
wordHeadingsColor: '#00ff00' // set color for default heading styles in document editor
showVerticalScroll: true/false, // show/hide scroll in the spreadsheet editor by default
showHorizontalScroll: true/false, // show/hide scroll in the spreadsheet editor by default
startFillingForm: {
text: 'Share & collect' // caption of the start filling button, used for pdf-forms
},
suggestFeature: true/false
},
coEditing: {
mode: 'fast', // <coauthoring mode>, 'fast' or 'strict'. if 'fast' and 'customization.autosave'=false -> set 'customization.autosave'=true. 'fast' - default for editor
// for viewer: 'strict' is default, offline viewer; 'fast' - live viewer, show changes from other users
change: true, // can change co-authoring mode. true - default for editor, false - default for viewer
},
plugins: {
autostart: ['asc.{FFE1F462-1EA2-4391-990D-4CC84940B754}'],
pluginsData: [
"helloworld/config.json",
"chess/config.json",
"speech/config.json",
"clipart/config.json",
]
},
wopi: { // only for wopi
FileNameMaxLength: 250 // max filename length for rename, 250 by default
}
},
events: {
'onAppReady': <application ready callback>,
'onDocumentStateChange': <document state changed callback>
'onDocumentReady': <document ready callback>
'onRequestEditRights': <request rights for switching from view to edit>,
'onRequestHistory': <request version history>,// must call refreshHistory method
'onRequestHistoryData': <request version data>,// must call setHistoryData method
'onRequestRestore': <try to restore selected version>,
'onRequestHistoryClose': <request closing history>,
'onError': <error callback>,
'onWarning': <warning callback>,
'onInfo': <document open callback>,// send view or edit mode
'onOutdatedVersion': <outdated version callback>,// send when previous version is opened, deprecated: use onRequestRefreshFile/refreshFile instead
'onDownloadAs': <download as callback>,// send url of downloaded file as a response for downloadAs method
'onRequestSaveAs': <try to save copy of the document>,
'onCollaborativeChanges': <co-editing changes callback>,// send when other user co-edit document
'onRequestRename': <try to rename document>,
'onMetaChange': // send when meta information changed
'onRequestClose': <request close editor>,
'onMakeActionLink': <request link to document with bookmark, comment...>,// must call setActionLink method
'onRequestUsers': <request users list for mentions>,// must call setUsers method
'onRequestSendNotify': //send when user is mentioned in a comment,
'onRequestInsertImage': <try to insert image>,// must call insertImage method
'onRequestCompareFile': <request file to compare>,// must call setRevisedFile method. must be deprecated
'onRequestSharingSettings': <request sharing settings>,// must call setSharingSettings method
'onRequestCreateNew': <try to create document>,
'onRequestReferenceData': <try to refresh external data>,
'onRequestOpen': <try to open external link>,
'onRequestSelectDocument': <try to open document>, // used for compare and combine documents. must call setRequestedDocument method. use instead of onRequestCompareFile/setRevisedFile
'onRequestSelectSpreadsheet': <try to open spreadsheet>, // used for mailmerge id de. must call setRequestedSpreadsheet method. use instead of onRequestMailMergeRecipients/setMailMergeRecipients
'onRequestReferenceSource': <try to change source for external link>, // used for external links in sse. must call setReferenceSource method,
'onSaveDocument': 'save document from binary',
'onRequestStartFilling': <try to start filling forms> // used in pdf-form edit mode. must call startFilling method
'onSubmit': <filled form is submitted> // send when filled form is submitted successfully
'onRequestRefreshFile': <request new file version> // send when file version is updated. use instead of onOutdatedVersion
'onUserActionRequired': <user action callback> // send if the user needs to enter a password or select encoding/delimiters when opening a file
'onRequestFillingStatus': <request filling status for current role> // used in pdf-form fill forms mode
'onRequestSmartPicker': <request to open the Nextcloud Smart Picker>
'onStartFilling': <send when can start filling (form is completed and users are disconnected)> // send after startFilling method, used in pdf-form editing
}
}
# Embedded #
config = {
type: 'embedded',
width: '100% by default',
height: '100% by default',
documentType: 'word' | 'cell' | 'slide',// deprecate 'text' | 'spreadsheet' | 'presentation',
document: {
title: 'document title',
url: 'document url',
fileType: 'document file type',
key: 'key',
vkey: 'vkey',
isForm: 'pdf form' / false/true
},
editorConfig: {
licenseUrl: <url for license>,
customerId: <customer id>,
autostart: 'document', // action for app's autostart. for presentations default value is 'player'
embedded: {
embedUrl: 'url',
fullscreenUrl: 'url',
saveUrl: 'url',
shareUrl: 'url',
toolbarDocked: 'top or bottom'
}
},
events: {
'onAppReady': <application ready callback>,
'onBack': <back to folder callback>,
'onError': <error callback>,
'onDocumentReady': <document ready callback>,
'onWarning': <warning callback>
}
}
*/
// TODO: allow several instances on one page simultaneously
DocsAPI.DocEditor = function(placeholderId, config) {
var _self = this,
_config = config || {};
extend(_config, DocsAPI.DocEditor.defaultConfig);
_config.editorConfig.canUseHistory = _config.events && !!_config.events.onRequestHistory;
_config.editorConfig.canHistoryClose = _config.events && !!_config.events.onRequestHistoryClose;
_config.editorConfig.canHistoryRestore = _config.events && !!_config.events.onRequestRestore;
_config.editorConfig.canSendEmailAddresses = _config.events && !!_config.events.onRequestEmailAddresses;
_config.editorConfig.canRequestEditRights = _config.events && !!_config.events.onRequestEditRights;
_config.editorConfig.canRequestClose = _config.events && !!_config.events.onRequestClose;
_config.editorConfig.canRename = _config.events && !!_config.events.onRequestRename;
_config.editorConfig.canMakeActionLink = _config.events && !!_config.events.onMakeActionLink;
_config.editorConfig.canRequestUsers = _config.events && !!_config.events.onRequestUsers;
_config.editorConfig.canRequestSendNotify = _config.events && !!_config.events.onRequestSendNotify;
_config.editorConfig.mergeFolderUrl = _config.editorConfig.mergeFolderUrl || _config.editorConfig.saveAsUrl;
_config.editorConfig.canRequestSaveAs = _config.events && !!_config.events.onRequestSaveAs;
_config.editorConfig.canRequestInsertImage = _config.events && !!_config.events.onRequestInsertImage;
_config.editorConfig.canRequestMailMergeRecipients = _config.events && !!_config.events.onRequestMailMergeRecipients;
_config.editorConfig.canRequestCompareFile = _config.events && !!_config.events.onRequestCompareFile;
_config.editorConfig.canRequestSharingSettings = _config.events && !!_config.events.onRequestSharingSettings;
_config.editorConfig.canRequestCreateNew = _config.events && !!_config.events.onRequestCreateNew;
_config.editorConfig.canRequestReferenceData = _config.events && !!_config.events.onRequestReferenceData;
_config.editorConfig.canRequestOpen = _config.events && !!_config.events.onRequestOpen;
_config.editorConfig.canRequestSelectDocument = _config.events && !!_config.events.onRequestSelectDocument;
_config.editorConfig.canRequestSelectSpreadsheet = _config.events && !!_config.events.onRequestSelectSpreadsheet;
_config.editorConfig.canRequestReferenceSource = _config.events && !!_config.events.onRequestReferenceSource;
_config.editorConfig.canSaveDocumentToBinary = _config.events && !!_config.events.onSaveDocument;
_config.editorConfig.canStartFilling = _config.events && !!_config.events.onRequestStartFilling;
_config.editorConfig.canRequestRefreshFile = _config.events && !!_config.events.onRequestRefreshFile;
_config.editorConfig.canUpdateVersion = _config.events && !!_config.events.onOutdatedVersion;
_config.editorConfig.canRequestFillingStatus = _config.events && !!_config.events.onRequestFillingStatus;
_config.frameEditorId = placeholderId;
_config.parentOrigin = window.location.origin;
var onMouseUp = function (evt) {
_processMouse(evt);
};
var _attachMouseEvents = function() {
if (window.addEventListener) {
window.addEventListener("mouseup", onMouseUp, false)
} else if (window.attachEvent) {
window.attachEvent("onmouseup", onMouseUp);
}
};
var _detachMouseEvents = function() {
if (window.removeEventListener) {
window.removeEventListener("mouseup", onMouseUp, false)
} else if (window.detachEvent) {
window.detachEvent("onmouseup", onMouseUp);
}
};
var _onAppReady = function() {
_attachMouseEvents();
if (_config.editorConfig) {
_init(_config.editorConfig);
}
if (_config.document) {
_openDocument(_config.document);
}
};
var _onMessage = function(msg) {
if ( msg ) {
if ( msg.type === "onExternalPluginMessage" ) {
_sendCommand(msg);
} else if ((window.parent !== window) && msg.type === "onExternalPluginMessageCallback") {
postMessage(window.parent, msg);
} else
if ( msg.frameEditorId == placeholderId ) {
var events = _config.events || {},
handler = events[msg.event],
res;
if (msg.event === 'onRequestEditRights' && !handler) {
_applyEditRights(false, 'handler isn\'t defined');
} else
if (msg.event === 'onSwitchEditorType' && !handler) {
if ( msg.data ) {
if ( typeof msg.data.type == 'string' )
localStorage.setItem('asc-force-editor-type', msg.data.type);
if ( msg.data.restart )
window.location.reload();
}
} else {
if (msg.event === 'onAppReady') {
_onAppReady();
}
if (handler && typeof handler == "function") {
res = handler.call(_self, {target: _self, data: msg.data});
}
}
}
}
};
var _checkConfigParams = function() {
if (_config.document) {
if (!_config.document.url || ((typeof _config.document.fileType !== 'string' || _config.document.fileType=='') &&
(typeof _config.documentType !== 'string' || _config.documentType==''))) {
window.alert("One or more required parameter for the config object is not set");
return false;
}
var appMap = {
'text': 'docx',
'text-pdf': 'pdf',
'spreadsheet': 'xlsx',
'presentation': 'pptx',
'word': 'docx',
'cell': 'xlsx',
'slide': 'pptx',
'pdf': 'pdf',
'diagram': 'vsdx'
}, app;
if (_config.documentType=='text' || _config.documentType=='spreadsheet' ||_config.documentType=='presentation')
console.warn("The \"documentType\" parameter for the config object must take one of the values word/cell/slide/pdf/diagram.");
if (typeof _config.documentType === 'string' && _config.documentType != '') {
app = appMap[_config.documentType.toLowerCase()];
if (!app) {
window.alert("The \"documentType\" parameter for the config object is invalid. Please correct it.");
return false;
} else if (typeof _config.document.fileType !== 'string' || _config.document.fileType == '') {
_config.document.fileType = app;
}
}
if (typeof _config.document.fileType === 'string' && _config.document.fileType != '') {
_config.document.fileType = _config.document.fileType.toLowerCase();
var type = /^(?:(xls|xlsx|ods|csv|gsheet|xlsm|xlt|xltm|xltx|fods|ots|xlsb|sxc|et|ett|numbers)|(pps|ppsx|ppt|pptx|odp|gslides|pot|potm|potx|ppsm|pptm|fodp|otp|sxi|dps|dpt|key|odg)|(pdf|djvu|xps|oxps)|(doc|docx|odt|gdoc|txt|rtf|mht|htm|html|mhtml|epub|docm|dot|dotm|dotx|fodt|ott|fb2|xml|oform|docxf|sxw|stw|wps|wpt|pages|hwp|hwpx|md|hml)|(vsdx|vssx|vstx|vsdm|vssm|vstm))$/
.exec(_config.document.fileType);
if (!type) {
window.alert("The \"document.fileType\" parameter for the config object is invalid. Please correct it.");
return false;
} else if (typeof _config.documentType !== 'string' || _config.documentType == ''){
if (typeof type[1] === 'string') _config.documentType = 'cell'; else
if (typeof type[2] === 'string') _config.documentType = 'slide'; else
if (typeof type[3] === 'string') _config.documentType = 'pdf'; else
if (typeof type[4] === 'string') _config.documentType = 'word'; else
if (typeof type[5] === 'string') _config.documentType = 'diagram';
}
}
var type = /^(?:(djvu|xps|oxps))$/.exec(_config.document.fileType);
if (type && typeof type[1] === 'string') {
_config.editorConfig.canUseHistory = false;
}
if (!_config.document.title || _config.document.title=='')
_config.document.title = 'Unnamed.' + _config.document.fileType;
if (!_config.document.key) {
_config.document.key = 'xxxxxxxxxxxxxxxxxxxx'.replace(/[x]/g, function (c) {var r = Math.random() * 16 | 0; return r.toString(16);});
} else if (typeof _config.document.key !== 'string') {
window.alert("The \"document.key\" parameter for the config object must be string. Please correct it.");
return false;
}
if (_config.editorConfig.user && _config.editorConfig.user.id && (typeof _config.editorConfig.user.id == 'number')) {
_config.editorConfig.user.id = _config.editorConfig.user.id.toString();
console.warn("The \"id\" parameter for the editorConfig.user object must be a string.");
}
_config.document.token = _config.token;
}
return true;
};
(function() {
var result = /[\?\&]placement=(\w+)&?/.exec(window.location.search);
if (!!result && result.length && result[1] == 'desktop' ) {
console.warn('some errors occurred in the desktop app while document opening. please, contact with support team');
}
if (!!window.AscDesktopEditor)
{
_config.editorConfig.targetApp = 'desktop';
// _config.editorConfig.canBackToFolder = false;
if (!_config.editorConfig.customization) _config.editorConfig.customization = {};
_config.editorConfig.customization.about = false;
_config.editorConfig.customization.compactHeader = false;
}
})();
var target = document.getElementById(placeholderId),
iframe;
getShardkey(_config);
if (target && _checkConfigParams()) {
iframe = createIframe(_config);
if (_config.editorConfig.customization && _config.editorConfig.customization.integrationMode==='embed')
window.AscEmbed && window.AscEmbed.initWorker(iframe);
if (_config.document && (_config.document.isForm!==true && _config.document.isForm!==false)) {
iframe.onload = function() {
_sendCommand({
command: 'checkParams',
data: {
url: _config.document.url,
directUrl: _config.document.directUrl,
token: _config.document.token,
key: _config.document.key
}
})
};
}
if (iframe.src) {
var pathArray = iframe.src.split('/');
this.frameOrigin = pathArray[0] + '//' + pathArray[2];
}
target.parentNode && target.parentNode.replaceChild(iframe, target);
var _msgDispatcher = new MessageDispatcher(_onMessage, this);
}
/*
cmd = {
command: 'commandName',
data: <command specific data>
}
*/
var _destroyEditor = function(cmd) {
var target = document.createElement("div");
target.setAttribute('id', placeholderId);
if (iframe) {
_msgDispatcher && _msgDispatcher.unbindEvents();
_detachMouseEvents();
iframe.parentNode && iframe.parentNode.replaceChild(target, iframe);
}
};
var _sendCommand = function(cmd, buffer) {
if (iframe && iframe.contentWindow)
postMessage(iframe.contentWindow, cmd, buffer);
};
var _init = function(editorConfig) {
_sendCommand({
command: 'init',
data: {
config: editorConfig
}
});
};
var _openDocument = function(doc) {
_sendCommand({
command: 'openDocument',
data: {
doc: doc
}
});
};
var _openDocumentFromBinary = function(doc) {
doc && _sendCommand({
command: 'openDocumentFromBinary',
data: doc.buffer
}, doc.buffer);
};
var _showMessage = function(title, msg) {
msg = msg || title;
_sendCommand({
command: 'showMessage',
data: {
msg: msg
}
});
};
var _applyEditRights = function(allowed, message) {
_sendCommand({
command: 'applyEditRights',
data: {
allowed: allowed,
message: message
}
});
};
// TODO: remove processRightsChange, use denyEditingRights
var _processRightsChange = function(enabled, message) {
_sendCommand({
command: 'processRightsChange',
data: {
enabled: enabled,
message: message
}
});
};
var _denyEditingRights = function(message) {
_sendCommand({
command: 'processRightsChange',
data: {
enabled: false,
message: message
}
});
};
var _refreshHistory = function(data, message) {
_sendCommand({
command: 'refreshHistory',
data: {
data: data,
message: message
}
});
};
var _setHistoryData = function(data, message) {
_sendCommand({
command: 'setHistoryData',
data: {
data: data,
message: message
}
});
};
var _setEmailAddresses = function(data) {
_sendCommand({
command: 'setEmailAddresses',
data: {
data: data
}
});
};
var _setActionLink = function (data) {
_sendCommand({
command: 'setActionLink',
data: {
url: data
}
});
};
var _processMailMerge = function(enabled, message) {
_sendCommand({
command: 'processMailMerge',
data: {
enabled: enabled,
message: message
}
});
};
var _downloadAs = function(data) {
_sendCommand({
command: 'downloadAs',
data: data
});
};
var _setUsers = function(data) {
_sendCommand({
command: 'setUsers',
data: data
});
};
var _showSharingSettings = function(data) {
_sendCommand({
command: 'showSharingSettings',
data: data
});
};
var _setSharingSettings = function(data) {
_sendCommand({
command: 'setSharingSettings',
data: data
});
};
var _insertImage = function(data) {
_sendCommand({
command: 'insertImage',
data: data
});
};
var _insertLink = function(data) {
_sendCommand({
command: 'insertLink',
data: data
});
};
var _insertPlainText = function(data) {
_sendCommand({
command: 'insertPlainText',
data: data
});
};
var _setMailMergeRecipients = function(data) {
_sendCommand({
command: 'setMailMergeRecipients',
data: data
});
};
var _setRevisedFile = function(data) {
_sendCommand({
command: 'setRevisedFile',
data: data
});
};
var _setRequestedDocument = function(data) {
_sendCommand({
command: 'setRequestedDocument',
data: data
});
};
var _setRequestedSpreadsheet = function(data) {
_sendCommand({
command: 'setRequestedSpreadsheet',
data: data
});
};
var _setReferenceSource = function(data) {
_sendCommand({
command: 'setReferenceSource',
data: data
});
};
var _setFavorite = function(data) {
_sendCommand({
command: 'setFavorite',
data: data
});
};
var _requestClose = function(data) {
_sendCommand({
command: 'requestClose',
data: data
});
};
var _startFilling = function(data) {
_sendCommand({
command: 'startFilling',
data: data
});
};
var _requestRoles = function(data) {
_sendCommand({
command: 'requestRoles',
data: data
});
};
var _processMouse = function(evt) {
var r = iframe.getBoundingClientRect();
var data = {
type: evt.type,
x: evt.x - r.left,
y: evt.y - r.top,
event: evt
};
_sendCommand({
command: 'processMouse',
data: data
});
};
var _grabFocus = function(data) {
setTimeout(function(){
_sendCommand({
command: 'grabFocus',
data: data
});
}, 10);
};
var _blurFocus = function(data) {
_sendCommand({
command: 'blurFocus',
data: data
});
};
var _setReferenceData = function(data) {
_sendCommand({
command: 'setReferenceData',
data: data
});
};
var _refreshFile = function(data) {
_sendCommand({
command: 'refreshFile',
data: data
});
};
var _serviceCommand = function(command, data) {
_sendCommand({
command: 'internalCommand',
data: {
command: command,
data: data
}
});
};
return {
showMessage : _showMessage,
processRightsChange : _processRightsChange,
denyEditingRights : _denyEditingRights,
refreshHistory : _refreshHistory,
setHistoryData : _setHistoryData,
setEmailAddresses : _setEmailAddresses,
setActionLink : _setActionLink,
processMailMerge : _processMailMerge,
downloadAs : _downloadAs,
serviceCommand : _serviceCommand,
attachMouseEvents : _attachMouseEvents,
detachMouseEvents : _detachMouseEvents,
destroyEditor : _destroyEditor,
setUsers : _setUsers,
showSharingSettings : _showSharingSettings,
setSharingSettings : _setSharingSettings,
insertImage : _insertImage,
insertLink : _insertLink,
insertPlainText : _insertPlainText,
setMailMergeRecipients: _setMailMergeRecipients,
setRevisedFile : _setRevisedFile,
setFavorite : _setFavorite,
requestClose : _requestClose,
grabFocus : _grabFocus,
blurFocus : _blurFocus,
setReferenceData : _setReferenceData,
refreshFile : _refreshFile,
setRequestedDocument: _setRequestedDocument,
setRequestedSpreadsheet: _setRequestedSpreadsheet,
setReferenceSource: _setReferenceSource,
openDocument: _openDocumentFromBinary,
startFilling: _startFilling,
requestRoles: _requestRoles
}
};
DocsAPI.DocEditor.defaultConfig = {
type: 'desktop',
width: '100%',
height: '100%',
editorConfig: {
lang: 'en',
canCoAuthoring: true,
customization: {
about: true,
feedback: false
}
}
};
DocsAPI.DocEditor.version = function() {
return '{{PRODUCT_VERSION}}';
};
DocsAPI.DocEditor.warmUp = function(id) {
var target = document.getElementById(id);
if ( target ) {
var path = extendAppPath({}, getBasePath());
path += 'api/documents/preload.html';
var iframe = document.createElement("iframe");
iframe.width = 0;
iframe.height = 0;
iframe.style = 'border:0 none;';
iframe.src = path;
target.parentNode && target.parentNode.replaceChild(iframe, target);
}
}
MessageDispatcher = function(fn, scope) {
var _fn = fn,
_scope = scope || window,
eventFn = function(msg) {
_onMessage(msg);
};
var _bindEvents = function() {
if (window.addEventListener) {
window.addEventListener("message", eventFn, false)
}
else if (window.attachEvent) {
window.attachEvent("onmessage", eventFn);
}
};
var _unbindEvents = function() {
if (window.removeEventListener) {
window.removeEventListener("message", eventFn, false)
}