2016-03-11 00:48:53 +00:00
/ * *
* Copyright ( c ) Ascensio System SIA 2013. All rights reserved
*
* http : //www.onlyoffice.com
* /
; ( function ( DocsAPI , window , document , undefined ) {
/ *
# Full #
config = {
2020-10-26 12:11:36 +00:00
type : 'desktop or mobile or embedded' ,
2016-03-11 00:48:53 +00:00
width : '100% by default' ,
height : '100% by default' ,
2020-09-11 13:34:29 +00:00
documentType : 'word' | 'cell' | 'slide' , // deprecate 'text' | 'spreadsheet' | 'presentation',
2020-10-26 12:11:36 +00:00
token : < string > encrypted signature
2016-03-11 00:48:53 +00:00
document : {
title : 'document title' ,
url : 'document url'
fileType : 'document file type' ,
options : < advanced options > ,
key : 'key' ,
vkey : 'vkey' ,
info : {
2019-07-30 10:51:36 +00:00
owner : 'owner name' ,
2016-03-11 00:48:53 +00:00
folder : 'path to document' ,
2019-07-30 10:51:36 +00:00
uploaded : '<uploaded date>' ,
2016-03-11 00:48:53 +00:00
sharingSettings : [
{
user : 'user name' ,
permissions : '<permissions>' ,
isLink : false
} ,
...
2020-12-14 19:45:30 +00:00
] ,
favorite : '<file is favorite>' // true/false/undefined (undefined - don't show fav. button)
2016-03-11 00:48:53 +00:00
} ,
permissions : {
edit : < can edit > , // default = true
2016-11-18 09:57:02 +00:00
download : < can download > , // default = true
reader : < can view in readable mode > ,
review : < can review > , // default = edit
print : < can print > , // default = true
2017-10-19 10:14:12 +00:00
comment : < can comment in view mode > // default = edit,
modifyFilter : < can add , remove and save filter in the spreadsheet > // default = true
2018-06-26 12:46:49 +00:00
modifyContentControl : < can modify content controls in documenteditor > // default = true
2020-07-13 11:23:43 +00:00
fillForms : < can edit forms in view mode > // default = edit || review,
2021-02-04 09:39:56 +00:00
copy : < can copy data > // default = true,
editCommentAuthorOnly : < can edit your own comments only > // default = false
2021-02-05 10:51:37 +00:00
deleteCommentAuthorOnly : < can delete your own comments only > // default = false,
2021-02-11 16:26:06 +00:00
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
2021-03-17 09:02:06 +00:00
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.
2021-04-02 08:08:36 +00:00
} ,
changeCoAuthoring : true // can change co-authoring mode
2016-03-11 00:48:53 +00:00
}
} ,
editorConfig : {
2020-10-26 12:11:36 +00:00
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
}
} ,
2016-03-11 00:48:53 +00:00
mode : 'view or edit' ,
lang : < language code > ,
2016-04-08 08:55:15 +00:00
location : < location > ,
2016-03-11 00:48:53 +00:00
canCoAuthoring : < can coauthoring documents > ,
canBackToFolder : < can return to folder > - deprecated . use "customization.goback" parameter ,
createUrl : 'create document url' ,
sharingSettingsUrl : 'document sharing settings url' ,
2018-10-03 11:00:08 +00:00
fileChoiceUrl : 'source url' , // for mail merge or image from storage
2016-03-11 00:48:53 +00:00
callbackUrl : < url for connection between sdk and portal > ,
2018-09-27 10:25:30 +00:00
mergeFolderUrl : 'folder for saving merged file' , // must be deprecated, use saveAsUrl instead
saveAsUrl : 'folder for saving files'
2016-03-11 00:48:53 +00:00
licenseUrl : < url for license > ,
customerId : < customer id > ,
2019-07-31 10:19:00 +00:00
region : < regional settings > // can be 'en-us' or lang code
2016-03-11 00:48:53 +00:00
user : {
id : 'user id' ,
2020-09-02 17:53:49 +00:00
name : 'user name' ,
group : 'group name' // for customization.reviewPermissions parameter
2016-03-11 00:48:53 +00:00
} ,
recent : [
{
title : 'document title' ,
url : 'document url' ,
2020-04-30 15:35:30 +00:00
folder : 'path to document' ,
2016-03-11 00:48:53 +00:00
} ,
...
] ,
templates : [
{
2020-04-30 15:35:30 +00:00
title : 'template name' , // name - is deprecated
image : 'template icon url' ,
2016-03-11 00:48:53 +00:00
url : 'http://...'
} ,
...
] ,
customization : {
logo : {
image : url ,
imageEmbedded : url ,
url : http : //...
} ,
customer : {
name : 'SuperPuper' ,
address : 'New-York, 125f-25' ,
mail : 'support@gmail.com' ,
www : 'www.superpuper.com' ,
info : 'Some info' ,
logo : ''
} ,
2017-04-11 12:24:07 +00:00
about : true ,
2016-03-11 00:48:53 +00:00
feedback : {
visible : false ,
url : http : //...
} ,
goback : {
url : 'http://...' ,
2018-02-14 14:11:28 +00:00
text : 'Go to London' ,
2019-11-27 07:22:25 +00:00
blank : true ,
requestClose : false // if true - goback send onRequestClose event instead opening url
2016-03-11 00:48:53 +00:00
} ,
2020-09-02 17:53:49 +00:00
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
} ,
2020-12-29 20:48:47 +00:00
anonymous : { // set name for anonymous user
request : bool ( default : true ) , // enable set name
label : string ( default : "Guest" ) // postfix for user name
}
2017-04-11 13:40:01 +00:00
chat : true ,
comments : true ,
2016-09-13 12:03:32 +00:00
zoom : 100 ,
2016-10-26 10:37:10 +00:00
compactToolbar : false ,
2016-10-21 13:47:46 +00:00
leftMenu : true ,
rightMenu : true ,
2018-10-26 09:49:11 +00:00
hideRightMenu : false , // hide or show right panel on first loading
2016-10-28 13:38:33 +00:00
toolbar : true ,
2017-04-12 07:59:28 +00:00
statusBar : true ,
2017-04-11 13:40:01 +00:00
autosave : true ,
2017-04-11 13:43:31 +00:00
forcesave : false ,
2021-02-04 09:39:56 +00:00
commentAuthorOnly : false , // must be deprecated. use permissions.editCommentAuthorOnly and permissions.deleteCommentAuthorOnly instead
2018-04-19 14:26:42 +00:00
showReviewChanges : false ,
2019-01-31 13:41:29 +00:00
help : true ,
2019-02-05 15:37:42 +00:00
compactHeader : false ,
2019-04-17 14:23:49 +00:00
toolbarNoTabs : false ,
2019-06-13 14:37:56 +00:00
toolbarHideFileName : false ,
2019-09-04 12:37:57 +00:00
reviewDisplay : 'original' ,
2019-11-01 07:36:21 +00:00
spellcheck : true ,
2019-12-16 11:02:22 +00:00
compatibleFeatures : false ,
2019-12-23 12:51:00 +00:00
unit : 'cm' // cm, pt, inch,
2020-05-21 16:30:57 +00:00
mentionShare : true // customize tooltip for mention,
macros : true // can run macros in document
plugins : true // can run plugins in document
2020-11-02 11:16:52 +00:00
macrosMode : 'warn' // warn about automatic macros, 'enable', 'disable', 'warn',
2021-02-11 17:13:47 +00:00
trackChanges : undefined // true/false - open editor with track changes mode on/off,
2021-04-01 10:36:08 +00:00
hideRulers : false , // hide or show rulers on first loading (presentation or document editor),
modeCoAuthoring : < coauthoring mode > , 'fast' ( default ) or 'strict' . if 'fast' and 'autosave' = false - > set 'autosave' = true
2016-05-17 15:38:54 +00:00
} ,
2016-05-19 09:46:21 +00:00
plugins : {
2017-09-13 10:32:01 +00:00
autostart : [ 'asc.{FFE1F462-1EA2-4391-990D-4CC84940B754}' ] ,
2016-10-21 14:09:58 +00:00
pluginsData : [
"helloworld/config.json" ,
"chess/config.json" ,
"speech/config.json" ,
"clipart/config.json" ,
]
2016-05-19 09:46:21 +00:00
}
2016-03-11 00:48:53 +00:00
} ,
events : {
2017-09-20 11:32:18 +00:00
'onAppReady' : < application ready callback > ,
2017-04-11 14:09:00 +00:00
'onDocumentStateChange' : < document state changed callback >
2017-09-20 11:32:18 +00:00
'onDocumentReady' : < document ready callback >
2020-10-26 12:11:36 +00:00
'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
'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
'onRequestSharingSettings' : < request sharing settings > , // must call setSharingSettings method
'onRequestCreateNew' : < try to create document > ,
2016-03-11 00:48:53 +00:00
}
}
# Embedded #
config = {
type : 'embedded' ,
width : '100% by default' ,
height : '100% by default' ,
2020-09-11 13:34:29 +00:00
documentType : 'word' | 'cell' | 'slide' , // deprecate 'text' | 'spreadsheet' | 'presentation',
2016-03-11 00:48:53 +00:00
document : {
title : 'document title' ,
url : 'document url' ,
fileType : 'document file type' ,
key : 'key' ,
vkey : 'vkey'
} ,
editorConfig : {
licenseUrl : < url for license > ,
customerId : < customer id > ,
2016-11-11 12:13:25 +00:00
autostart : 'document' , // action for app's autostart. for presentations default value is 'player'
2016-03-11 00:48:53 +00:00
embedded : {
embedUrl : 'url' ,
fullscreenUrl : 'url' ,
saveUrl : 'url' ,
shareUrl : 'url' ,
toolbarDocked : 'top or bottom'
}
} ,
events : {
2017-09-20 11:32:18 +00:00
'onAppReady' : < application ready callback > ,
2016-03-11 00:48:53 +00:00
'onBack' : < back to folder callback > ,
'onError' : < error callback > ,
2017-10-07 09:20:39 +00:00
'onDocumentReady' : < document ready callback > ,
'onWarning' : < warning callback >
2016-03-11 00:48:53 +00:00
}
}
* /
// 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 ;
2016-09-16 12:46:00 +00:00
_config . editorConfig . canHistoryRestore = _config . events && ! ! _config . events . onRequestRestore ;
2016-03-11 00:48:53 +00:00
_config . editorConfig . canSendEmailAddresses = _config . events && ! ! _config . events . onRequestEmailAddresses ;
_config . editorConfig . canRequestEditRights = _config . events && ! ! _config . events . onRequestEditRights ;
2018-02-06 10:54:40 +00:00
_config . editorConfig . canRequestClose = _config . events && ! ! _config . events . onRequestClose ;
2018-04-17 13:05:41 +00:00
_config . editorConfig . canRename = _config . events && ! ! _config . events . onRequestRename ;
2019-03-18 11:47:41 +00:00
_config . editorConfig . canMakeActionLink = _config . events && ! ! _config . events . onMakeActionLink ;
2019-04-23 11:41:35 +00:00
_config . editorConfig . canRequestUsers = _config . events && ! ! _config . events . onRequestUsers ;
2019-06-26 11:04:02 +00:00
_config . editorConfig . canRequestSendNotify = _config . events && ! ! _config . events . onRequestSendNotify ;
2018-09-27 10:25:30 +00:00
_config . editorConfig . mergeFolderUrl = _config . editorConfig . mergeFolderUrl || _config . editorConfig . saveAsUrl ;
2019-07-26 09:54:20 +00:00
_config . editorConfig . canRequestSaveAs = _config . events && ! ! _config . events . onRequestSaveAs ;
2019-07-26 11:49:53 +00:00
_config . editorConfig . canRequestInsertImage = _config . events && ! ! _config . events . onRequestInsertImage ;
2019-07-29 10:40:07 +00:00
_config . editorConfig . canRequestMailMergeRecipients = _config . events && ! ! _config . events . onRequestMailMergeRecipients ;
2019-10-11 12:12:59 +00:00
_config . editorConfig . canRequestCompareFile = _config . events && ! ! _config . events . onRequestCompareFile ;
2019-11-28 13:54:14 +00:00
_config . editorConfig . canRequestSharingSettings = _config . events && ! ! _config . events . onRequestSharingSettings ;
2020-06-15 17:05:19 +00:00
_config . editorConfig . canRequestCreateNew = _config . events && ! ! _config . events . onRequestCreateNew ;
2016-12-14 11:20:18 +00:00
_config . frameEditorId = placeholderId ;
2020-03-19 14:38:09 +00:00
_config . parentOrigin = window . location . origin ;
2016-03-11 00:48:53 +00:00
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 ) ;
}
} ;
2017-09-20 11:32:18 +00:00
var _onAppReady = function ( ) {
2016-03-11 00:48:53 +00:00
if ( _config . type === 'mobile' ) {
document . body . onfocus = function ( e ) {
setTimeout ( function ( ) {
iframe . contentWindow . focus ( ) ;
_sendCommand ( {
command : 'resetFocus' ,
data : { }
} )
} , 10 ) ;
} ;
}
_attachMouseEvents ( ) ;
if ( _config . editorConfig ) {
_init ( _config . editorConfig ) ;
}
if ( _config . document ) {
_openDocument ( _config . document ) ;
}
} ;
var _callLocalStorage = function ( data ) {
if ( data . cmd == 'get' ) {
if ( data . keys && data . keys . length ) {
var af = data . keys . split ( ',' ) , re = af [ 0 ] ;
for ( i = 0 ; ++ i < af . length ; )
re += '|' + af [ i ] ;
re = new RegExp ( re ) ; k = { } ;
for ( i in localStorage )
if ( re . test ( i ) ) k [ i ] = localStorage [ i ] ;
} else {
k = localStorage ;
}
_sendCommand ( {
command : 'internalCommand' ,
data : {
type : 'localstorage' ,
keys : k
}
} ) ;
} else
if ( data . cmd == 'set' ) {
var k = data . keys , i ;
for ( i in k ) {
localStorage . setItem ( i , k [ i ] ) ;
}
}
} ;
var _onMessage = function ( msg ) {
2017-04-11 12:04:24 +00:00
if ( msg ) {
if ( msg . type === "onExternalPluginMessage" ) {
_sendCommand ( msg ) ;
2020-11-12 15:52:43 +00:00
} else if ( msg . type === "onExternalPluginMessageCallback" ) {
2020-11-12 15:56:25 +00:00
postMessage ( window . parent , msg ) ;
2016-03-11 00:48:53 +00:00
} else
2017-04-11 12:04:24 +00:00
if ( msg . frameEditorId == placeholderId ) {
var events = _config . events || { } ,
handler = events [ msg . event ] ,
res ;
if ( msg . event === 'onRequestEditRights' && ! handler ) {
2017-04-11 13:52:31 +00:00
_applyEditRights ( false , 'handler isn\'t defined' ) ;
2017-04-11 12:04:24 +00:00
} else if ( msg . event === 'onInternalMessage' && msg . data && msg . data . type == 'localstorage' ) {
_callLocalStorage ( msg . data . data ) ;
} else {
2017-09-20 11:32:18 +00:00
if ( msg . event === 'onAppReady' ) {
_onAppReady ( ) ;
2017-04-11 12:04:24 +00:00
}
2016-03-11 00:48:53 +00:00
2017-09-22 13:35:16 +00:00
if ( handler && typeof handler == "function" ) {
2017-04-11 12:04:24 +00:00
res = handler . call ( _self , { target : _self , data : msg . data } ) ;
2016-03-11 00:48:53 +00:00
}
}
}
}
} ;
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' ,
2020-09-11 13:34:29 +00:00
'presentation' : 'pptx' ,
'word' : 'docx' ,
'cell' : 'xlsx' ,
'slide' : 'pptx'
2016-03-11 00:48:53 +00:00
} , app ;
2020-09-11 13:34:29 +00:00
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." ) ;
2016-03-11 00:48:53 +00:00
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 != '' ) {
2020-05-22 09:49:14 +00:00
_config . document . fileType = _config . document . fileType . toLowerCase ( ) ;
2021-03-01 18:09:38 +00:00
var type = /^(?:(xls|xlsx|ods|csv|xlst|xlsy|gsheet|xlsm|xlt|xltm|xltx|fods|ots)|(pps|ppsx|ppt|pptx|odp|pptt|ppty|gslides|pot|potm|potx|ppsm|pptm|fodp|otp)|(doc|docx|doct|odt|gdoc|txt|rtf|pdf|mht|htm|html|epub|djvu|xps|docm|dot|dotm|dotx|fodt|ott|fb2|xml))$/
2016-03-11 00:48:53 +00:00
. 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 == '' ) {
2020-09-11 13:34:29 +00:00
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 = 'word' ;
2016-03-11 00:48:53 +00:00
}
}
var type = /^(?:(pdf|djvu|xps))$/ . exec ( _config . document . fileType ) ;
if ( type && typeof type [ 1 ] === 'string' ) {
2017-05-19 11:54:28 +00:00
_config . editorConfig . canUseHistory = false ;
2016-03-11 00:48:53 +00:00
}
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 ) ; } ) ;
2016-09-22 13:27:52 +00:00
} 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 ;
2016-03-11 00:48:53 +00:00
}
2016-11-24 13:44:54 +00:00
2021-02-13 09:53:45 +00:00
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." ) ;
}
2016-11-24 13:44:54 +00:00
_config . document . token = _config . token ;
2016-03-11 00:48:53 +00:00
}
return true ;
} ;
( function ( ) {
var result = /[\?\&]placement=(\w+)&?/ . exec ( window . location . search ) ;
if ( ! ! result && result . length ) {
if ( result [ 1 ] == 'desktop' ) {
_config . editorConfig . targetApp = result [ 1 ] ;
2018-01-24 10:57:58 +00:00
// _config.editorConfig.canBackToFolder = false;
2016-03-11 00:48:53 +00:00
if ( ! _config . editorConfig . customization ) _config . editorConfig . customization = { } ;
_config . editorConfig . customization . about = false ;
2019-01-31 13:41:29 +00:00
_config . editorConfig . customization . compactHeader = false ;
2016-03-11 00:48:53 +00:00
}
}
} ) ( ) ;
var target = document . getElementById ( placeholderId ) ,
iframe ;
if ( target && _checkConfigParams ( ) ) {
iframe = createIframe ( _config ) ;
2020-03-19 14:38:09 +00:00
if ( iframe . src ) {
var pathArray = iframe . src . split ( '/' ) ;
this . frameOrigin = pathArray [ 0 ] + '//' + pathArray [ 2 ] ;
}
2016-03-11 00:48:53 +00:00
target . parentNode && target . parentNode . replaceChild ( iframe , target ) ;
2017-01-17 07:00:12 +00:00
var _msgDispatcher = new MessageDispatcher ( _onMessage , this ) ;
2016-03-11 00:48:53 +00:00
}
/ *
cmd = {
command : 'commandName' ,
data : < command specific data >
}
* /
2017-01-17 07:00:12 +00:00
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 ) ;
}
} ;
2016-03-11 00:48:53 +00:00
var _sendCommand = function ( cmd ) {
if ( iframe && iframe . contentWindow )
postMessage ( iframe . contentWindow , cmd ) ;
} ;
var _init = function ( editorConfig ) {
_sendCommand ( {
command : 'init' ,
data : {
config : editorConfig
}
} ) ;
} ;
var _openDocument = function ( doc ) {
_sendCommand ( {
command : 'openDocument' ,
data : {
doc : doc
}
} ) ;
} ;
2017-05-16 07:46:04 +00:00
var _showMessage = function ( title , msg ) {
msg = msg || title ;
2016-03-11 00:48:53 +00:00
_sendCommand ( {
command : 'showMessage' ,
data : {
2017-05-16 07:46:04 +00:00
msg : msg
2016-03-11 00:48:53 +00:00
}
} ) ;
} ;
var _applyEditRights = function ( allowed , message ) {
_sendCommand ( {
command : 'applyEditRights' ,
data : {
allowed : allowed ,
message : message
}
} ) ;
} ;
var _processSaveResult = function ( result , message ) {
_sendCommand ( {
command : 'processSaveResult' ,
data : {
result : result ,
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
}
} ) ;
} ;
2019-03-18 11:47:41 +00:00
var _setActionLink = function ( data ) {
_sendCommand ( {
command : 'setActionLink' ,
data : {
url : data
}
} ) ;
} ;
2016-03-11 00:48:53 +00:00
var _processMailMerge = function ( enabled , message ) {
_sendCommand ( {
command : 'processMailMerge' ,
data : {
enabled : enabled ,
message : message
}
} ) ;
} ;
2017-10-24 11:23:15 +00:00
var _downloadAs = function ( data ) {
2016-03-11 00:48:53 +00:00
_sendCommand ( {
2017-10-24 11:23:15 +00:00
command : 'downloadAs' ,
data : data
2016-03-11 00:48:53 +00:00
} ) ;
} ;
2019-04-23 11:41:35 +00:00
var _setUsers = function ( data ) {
_sendCommand ( {
command : 'setUsers' ,
2019-07-12 07:43:02 +00:00
data : data
2019-04-23 11:41:35 +00:00
} ) ;
} ;
var _showSharingSettings = function ( data ) {
_sendCommand ( {
command : 'showSharingSettings' ,
data : data
} ) ;
} ;
2019-07-11 15:00:11 +00:00
var _setSharingSettings = function ( data ) {
_sendCommand ( {
command : 'setSharingSettings' ,
2019-07-12 07:43:02 +00:00
data : data
2019-07-11 15:00:11 +00:00
} ) ;
} ;
2019-07-26 11:49:53 +00:00
var _insertImage = function ( data ) {
_sendCommand ( {
command : 'insertImage' ,
data : data
} ) ;
} ;
2019-07-29 10:40:07 +00:00
var _setMailMergeRecipients = function ( data ) {
_sendCommand ( {
command : 'setMailMergeRecipients' ,
data : data
} ) ;
} ;
2019-10-15 08:44:38 +00:00
var _setRevisedFile = function ( data ) {
_sendCommand ( {
command : 'setRevisedFile' ,
data : data
} ) ;
} ;
2020-12-14 19:45:30 +00:00
var _setFavorite = function ( data ) {
_sendCommand ( {
command : 'setFavorite' ,
data : data
} ) ;
} ;
2021-03-29 11:30:31 +00:00
var _requestClose = function ( data ) {
_sendCommand ( {
command : 'requestClose' ,
data : data
} ) ;
} ;
2016-03-11 00:48:53 +00:00
var _processMouse = function ( evt ) {
var r = iframe . getBoundingClientRect ( ) ;
var data = {
type : evt . type ,
x : evt . x - r . left ,
2017-04-11 12:25:20 +00:00
y : evt . y - r . top ,
event : evt
2016-03-11 00:48:53 +00:00
} ;
_sendCommand ( {
command : 'processMouse' ,
data : data
} ) ;
} ;
var _serviceCommand = function ( command , data ) {
_sendCommand ( {
command : 'internalCommand' ,
data : {
command : command ,
data : data
}
} ) ;
} ;
return {
showMessage : _showMessage ,
processSaveResult : _processSaveResult ,
processRightsChange : _processRightsChange ,
denyEditingRights : _denyEditingRights ,
refreshHistory : _refreshHistory ,
setHistoryData : _setHistoryData ,
setEmailAddresses : _setEmailAddresses ,
2019-03-18 11:47:41 +00:00
setActionLink : _setActionLink ,
2016-03-11 00:48:53 +00:00
processMailMerge : _processMailMerge ,
downloadAs : _downloadAs ,
serviceCommand : _serviceCommand ,
attachMouseEvents : _attachMouseEvents ,
2017-01-17 07:00:12 +00:00
detachMouseEvents : _detachMouseEvents ,
2019-04-23 11:41:35 +00:00
destroyEditor : _destroyEditor ,
setUsers : _setUsers ,
2019-07-11 15:00:11 +00:00
showSharingSettings : _showSharingSettings ,
2019-07-26 11:49:53 +00:00
setSharingSettings : _setSharingSettings ,
2019-07-29 10:40:07 +00:00
insertImage : _insertImage ,
2019-10-15 08:44:38 +00:00
setMailMergeRecipients : _setMailMergeRecipients ,
2020-12-14 19:45:30 +00:00
setRevisedFile : _setRevisedFile ,
2021-03-29 11:30:31 +00:00
setFavorite : _setFavorite ,
requestClose : _requestClose
2016-03-11 00:48:53 +00:00
}
} ;
DocsAPI . DocEditor . defaultConfig = {
type : 'desktop' ,
width : '100%' ,
height : '100%' ,
editorConfig : {
lang : 'en' ,
canCoAuthoring : true ,
customization : {
2017-04-11 12:24:07 +00:00
about : true ,
2016-03-11 00:48:53 +00:00
feedback : false
}
}
} ;
DocsAPI . DocEditor . version = function ( ) {
2017-01-25 16:30:08 +00:00
return '{{PRODUCT_VERSION}}' ;
2016-03-11 00:48:53 +00:00
} ;
MessageDispatcher = function ( fn , scope ) {
var _fn = fn ,
2017-01-17 07:00:12 +00:00
_scope = scope || window ,
eventFn = function ( msg ) {
_onMessage ( msg ) ;
} ;
2016-03-11 00:48:53 +00:00
var _bindEvents = function ( ) {
if ( window . addEventListener ) {
2017-01-17 07:00:12 +00:00
window . addEventListener ( "message" , eventFn , false )
2016-03-11 00:48:53 +00:00
}
else if ( window . attachEvent ) {
2017-01-17 07:00:12 +00:00
window . attachEvent ( "onmessage" , eventFn ) ;
}
} ;
var _unbindEvents = function ( ) {
if ( window . removeEventListener ) {
window . removeEventListener ( "message" , eventFn , false )
}
else if ( window . detachEvent ) {
window . detachEvent ( "onmessage" , eventFn ) ;
2016-03-11 00:48:53 +00:00
}
} ;
var _onMessage = function ( msg ) {
// TODO: check message origin
2020-03-19 14:38:09 +00:00
if ( msg && window . JSON && _scope . frameOrigin == msg . origin ) {
2016-03-11 00:48:53 +00:00
try {
var msg = window . JSON . parse ( msg . data ) ;
if ( _fn ) {
_fn . call ( _scope , msg ) ;
}
} catch ( e ) { }
}
} ;
_bindEvents . call ( this ) ;
2017-01-17 07:00:12 +00:00
return {
unbindEvents : _unbindEvents
}
2016-03-11 00:48:53 +00:00
} ;
function getBasePath ( ) {
var scripts = document . getElementsByTagName ( 'script' ) ,
match ;
for ( var i = scripts . length - 1 ; i >= 0 ; i -- ) {
match = scripts [ i ] . src . match ( /(.*)api\/documents\/api.js/i ) ;
if ( match ) {
return match [ 1 ] ;
}
}
return "" ;
}
function getExtensionPath ( ) {
if ( "undefined" == typeof ( extensionParams ) || null == extensionParams [ "url" ] )
return null ;
return extensionParams [ "url" ] + "apps/" ;
}
function getAppPath ( config ) {
var extensionPath = getExtensionPath ( ) ,
path = extensionPath ? extensionPath : getBasePath ( ) ,
appMap = {
'text' : 'documenteditor' ,
'text-pdf' : 'documenteditor' ,
'spreadsheet' : 'spreadsheeteditor' ,
2020-09-11 13:34:29 +00:00
'presentation' : 'presentationeditor' ,
'word' : 'documenteditor' ,
'cell' : 'spreadsheeteditor' ,
'slide' : 'presentationeditor'
2016-03-11 00:48:53 +00:00
} ,
2020-09-11 13:34:29 +00:00
app = appMap [ 'word' ] ;
2016-03-11 00:48:53 +00:00
if ( typeof config . documentType === 'string' ) {
app = appMap [ config . documentType . toLowerCase ( ) ] ;
} else
if ( ! ! config . document && typeof config . document . fileType === 'string' ) {
2019-02-20 13:29:24 +00:00
var type = /^(?:(xls|xlsx|ods|csv|xlst|xlsy|gsheet|xlsm|xlt|xltm|xltx|fods|ots)|(pps|ppsx|ppt|pptx|odp|pptt|ppty|gslides|pot|potm|potx|ppsm|pptm|fodp|otp))$/
2016-03-11 00:48:53 +00:00
. exec ( config . document . fileType ) ;
if ( type ) {
2020-09-11 13:34:29 +00:00
if ( typeof type [ 1 ] === 'string' ) app = appMap [ 'cell' ] ; else
if ( typeof type [ 2 ] === 'string' ) app = appMap [ 'slide' ] ;
2016-03-11 00:48:53 +00:00
}
}
2019-10-14 07:54:01 +00:00
var userAgent = navigator . userAgent . toLowerCase ( ) ,
check = function ( regex ) { return regex . test ( userAgent ) ; } ,
isIE = ! check ( /opera/ ) && ( check ( /msie/ ) || check ( /trident/ ) || check ( /edge/ ) ) ,
isChrome = ! isIE && check ( /\bchrome\b/ ) ,
isSafari _mobile = ! isIE && ! isChrome && check ( /safari/ ) && ( navigator . maxTouchPoints > 0 ) ;
2016-03-11 00:48:53 +00:00
path += app + "/" ;
2019-10-14 07:54:01 +00:00
path += ( config . type === "mobile" || isSafari _mobile )
2016-03-11 00:48:53 +00:00
? "mobile"
: config . type === "embedded"
? "embed"
: "main" ;
2019-07-22 14:04:24 +00:00
var index = "/index.html" ;
2019-10-04 07:36:10 +00:00
if ( config . editorConfig ) {
2019-07-22 14:04:24 +00:00
var customization = config . editorConfig . customization ;
2019-10-04 07:36:10 +00:00
if ( typeof ( customization ) == 'object' && ( customization . toolbarNoTabs ||
( config . editorConfig . targetApp !== 'desktop' ) && ( customization . loaderName || customization . loaderLogo ) ) ) {
2019-07-22 14:04:24 +00:00
index = "/index_loader.html" ;
2020-07-02 20:20:43 +00:00
} else if ( config . editorConfig . mode == 'editdiagram' || config . editorConfig . mode == 'editmerge' )
index = "/index_internal.html" ;
2019-07-22 14:04:24 +00:00
}
path += index ;
2016-03-11 00:48:53 +00:00
return path ;
}
function getAppParameters ( config ) {
var params = "?_dc=0" ;
if ( config . editorConfig && config . editorConfig . lang )
params += "&lang=" + config . editorConfig . lang ;
if ( config . editorConfig && config . editorConfig . targetApp !== 'desktop' ) {
if ( ( typeof ( config . editorConfig . customization ) == 'object' ) && config . editorConfig . customization . loaderName ) {
if ( config . editorConfig . customization . loaderName !== 'none' ) params += "&customer=" + config . editorConfig . customization . loaderName ;
} else
2020-02-19 17:04:10 +00:00
params += "&customer={{APP_CUSTOMER_NAME}}" ;
2016-09-14 09:45:10 +00:00
if ( ( typeof ( config . editorConfig . customization ) == 'object' ) && config . editorConfig . customization . loaderLogo ) {
if ( config . editorConfig . customization . loaderLogo !== '' ) params += "&logo=" + config . editorConfig . customization . loaderLogo ;
2019-07-22 14:04:24 +00:00
} else if ( ( typeof ( config . editorConfig . customization ) == 'object' ) && config . editorConfig . customization . logo ) {
2019-09-13 14:40:21 +00:00
if ( config . type == 'embedded' && config . editorConfig . customization . logo . imageEmbedded )
params += "&headerlogo=" + config . editorConfig . customization . logo . imageEmbedded ;
else if ( config . type != 'embedded' && config . editorConfig . customization . logo . image )
params += "&headerlogo=" + config . editorConfig . customization . logo . image ;
2016-09-14 09:45:10 +00:00
}
2016-03-11 00:48:53 +00:00
}
2016-12-14 11:20:18 +00:00
2019-10-08 12:12:15 +00:00
if ( config . editorConfig && ( config . editorConfig . mode == 'editdiagram' || config . editorConfig . mode == 'editmerge' ) )
params += "&internal=true" ;
2016-12-14 11:20:18 +00:00
if ( config . frameEditorId )
params += "&frameEditorId=" + config . frameEditorId ;
2019-11-25 08:02:50 +00:00
2019-11-25 11:23:27 +00:00
if ( config . editorConfig && config . editorConfig . mode == 'view' ||
2019-11-25 08:02:50 +00:00
config . document && config . document . permissions && ( config . document . permissions . edit === false && ! config . document . permissions . review ) )
params += "&mode=view" ;
2019-11-25 11:23:27 +00:00
if ( config . editorConfig && config . editorConfig . customization && ! ! config . editorConfig . customization . compactHeader )
params += "&compact=true" ;
2020-01-15 13:12:53 +00:00
if ( config . editorConfig && config . editorConfig . customization && ( config . editorConfig . customization . toolbar === false ) )
params += "&toolbar=false" ;
2021-02-11 12:52:38 +00:00
else if ( config . document && config . document . permissions && ( config . document . permissions . edit === false && config . document . permissions . fillForms ) )
params += "&toolbar=true" ;
2020-01-15 13:12:53 +00:00
2020-03-19 14:38:09 +00:00
if ( config . parentOrigin )
params += "&parentOrigin=" + config . parentOrigin ;
2021-02-02 12:37:00 +00:00
if ( config . editorConfig && config . editorConfig . customization && config . editorConfig . customization . uiTheme )
params += "&uitheme=" + config . editorConfig . customization . uiTheme ;
2016-03-11 00:48:53 +00:00
return params ;
}
function createIframe ( config ) {
var iframe = document . createElement ( "iframe" ) ;
iframe . src = getAppPath ( config ) + getAppParameters ( config ) ;
iframe . width = config . width ;
iframe . height = config . height ;
iframe . align = "top" ;
iframe . frameBorder = 0 ;
iframe . name = "frameEditor" ;
iframe . allowFullscreen = true ;
iframe . setAttribute ( "allowfullscreen" , "" ) ; // for IE11
iframe . setAttribute ( "onmousewheel" , "" ) ; // for Safari on Mac
2020-11-19 18:27:33 +00:00
iframe . setAttribute ( "allow" , "autoplay; camera; microphone; display-capture" ) ;
2019-11-07 15:49:33 +00:00
2018-12-24 15:09:11 +00:00
if ( config . type == "mobile" )
{
iframe . style . position = "fixed" ;
2019-04-02 14:15:07 +00:00
iframe . style . overflow = "hidden" ;
document . body . style . overscrollBehaviorY = "contain" ;
2018-12-24 15:09:11 +00:00
}
2016-03-11 00:48:53 +00:00
return iframe ;
}
function postMessage ( wnd , msg ) {
if ( wnd && wnd . postMessage && window . JSON ) {
// TODO: specify explicit origin
wnd . postMessage ( window . JSON . stringify ( msg ) , "*" ) ;
}
}
function extend ( dest , src ) {
for ( var prop in src ) {
if ( src . hasOwnProperty ( prop ) ) {
if ( typeof dest [ prop ] === 'undefined' ) {
dest [ prop ] = src [ prop ] ;
} else
if ( typeof dest [ prop ] === 'object' &&
typeof src [ prop ] === 'object' ) {
extend ( dest [ prop ] , src [ prop ] )
}
}
}
return dest ;
}
} ) ( window . DocsAPI = window . DocsAPI || { } , window , document ) ;