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 = {
|
|
|
|
type: 'desktop or mobile',
|
|
|
|
width: '100% by default',
|
|
|
|
height: '100% by default',
|
|
|
|
documentType: 'text' | 'spreadsheet' | 'presentation',
|
|
|
|
document: {
|
|
|
|
title: 'document title',
|
|
|
|
url: 'document url'
|
|
|
|
fileType: 'document file type',
|
|
|
|
options: <advanced options>,
|
|
|
|
key: 'key',
|
|
|
|
vkey: 'vkey',
|
|
|
|
info: {
|
|
|
|
author: 'author name',
|
|
|
|
folder: 'path to document',
|
|
|
|
created: '<creation date>',
|
|
|
|
sharingSettings: [
|
|
|
|
{
|
|
|
|
user: 'user name',
|
|
|
|
permissions: '<permissions>',
|
|
|
|
isLink: false
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
|
|
|
},
|
|
|
|
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
|
|
|
|
rename: <can rename>, // default = false
|
|
|
|
changeHistory: <can change history>, // default = false
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
editorConfig: {
|
|
|
|
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>,
|
|
|
|
canAutosave: <can autosave documents>,
|
|
|
|
canBackToFolder: <can return to folder> - deprecated. use "customization.goback" parameter,
|
|
|
|
createUrl: 'create document url',
|
|
|
|
sharingSettingsUrl: 'document sharing settings url',
|
|
|
|
fileChoiceUrl: 'mail merge sources url',
|
|
|
|
callbackUrl: <url for connection between sdk and portal>,
|
|
|
|
mergeFolderUrl: 'folder for saving merged file',
|
|
|
|
licenseUrl: <url for license>,
|
|
|
|
customerId: <customer id>,
|
|
|
|
|
|
|
|
user: {
|
|
|
|
id: 'user id',
|
2016-11-18 11:48:24 +00:00
|
|
|
name: 'user name'
|
2016-03-11 00:48:53 +00:00
|
|
|
},
|
|
|
|
recent: [
|
|
|
|
{
|
|
|
|
title: 'document title',
|
|
|
|
url: 'document url',
|
|
|
|
folder: 'path to document'
|
|
|
|
},
|
|
|
|
...
|
|
|
|
],
|
|
|
|
templates: [
|
|
|
|
{
|
|
|
|
name: 'template name',
|
|
|
|
icon: 'template icon url',
|
|
|
|
url: 'http://...'
|
|
|
|
},
|
|
|
|
...
|
|
|
|
],
|
|
|
|
customization: {
|
|
|
|
logo: {
|
|
|
|
image: url,
|
|
|
|
imageEmbedded: url,
|
|
|
|
url: http://...
|
|
|
|
},
|
|
|
|
backgroundColor: 'header background color',
|
|
|
|
textColor: 'header text color',
|
|
|
|
customer: {
|
|
|
|
name: 'SuperPuper',
|
|
|
|
address: 'New-York, 125f-25',
|
|
|
|
mail: 'support@gmail.com',
|
|
|
|
www: 'www.superpuper.com',
|
|
|
|
info: 'Some info',
|
|
|
|
logo: ''
|
|
|
|
},
|
|
|
|
about: false,
|
|
|
|
feedback: {
|
|
|
|
visible: false,
|
|
|
|
url: http://...
|
|
|
|
},
|
|
|
|
goback: {
|
|
|
|
url: 'http://...',
|
|
|
|
text: 'Go to London'
|
|
|
|
},
|
|
|
|
chat: false,
|
2016-09-13 08:28:21 +00:00
|
|
|
comments: false,
|
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,
|
2016-10-28 13:38:33 +00:00
|
|
|
toolbar: true,
|
2016-11-17 11:13:33 +00:00
|
|
|
header: true,
|
|
|
|
autosave: true
|
2016-05-17 15:38:54 +00:00
|
|
|
},
|
2016-05-19 09:46:21 +00:00
|
|
|
plugins: {
|
2016-10-21 14:09:58 +00:00
|
|
|
autoStartGuid: 'asc.{FFE1F462-1EA2-4391-990D-4CC84940B754}',
|
2016-05-19 09:46:21 +00:00
|
|
|
url: '../../../../sdkjs-plugins/',
|
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: {
|
|
|
|
'onReady': <document ready callback>,
|
|
|
|
'onBack': <back to folder callback>,
|
|
|
|
'onDocumentStateChange': <document state changed callback>,
|
|
|
|
'onSave': <save request callback>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Embedded #
|
|
|
|
|
|
|
|
config = {
|
|
|
|
type: 'embedded',
|
|
|
|
width: '100% by default',
|
|
|
|
height: '100% by default',
|
|
|
|
documentType: 'text' | 'spreadsheet' | 'presentation',
|
|
|
|
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: {
|
|
|
|
'onReady': <document ready callback>,
|
|
|
|
'onBack': <back to folder callback>,
|
|
|
|
'onError': <error 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;
|
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;
|
2016-12-14 11:20:18 +00:00
|
|
|
_config.frameEditorId = placeholderId;
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var _onReady = function() {
|
|
|
|
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) {
|
2016-12-14 11:20:18 +00:00
|
|
|
if (msg && msg.frameEditorId == placeholderId) {
|
2016-03-11 00:48:53 +00:00
|
|
|
var events = _config.events || {},
|
|
|
|
handler = events[msg.event],
|
|
|
|
res;
|
|
|
|
|
|
|
|
if (msg.event === 'onRequestEditRights' && !handler) {
|
|
|
|
_applyEditRights(false, 'handler is\'n defined');
|
|
|
|
} else
|
|
|
|
if (msg.event === 'onInternalMessage' && msg.data && msg.data.type == 'localstorage') {
|
|
|
|
_callLocalStorage(msg.data.data);
|
|
|
|
} else {
|
|
|
|
if (msg.event === 'onReady') {
|
|
|
|
_onReady();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handler) {
|
|
|
|
res = handler.call(_self, { target: _self, data: msg.data });
|
|
|
|
if (msg.event === 'onSave' && res !== false) {
|
|
|
|
_processSaveResult(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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'
|
|
|
|
}, app;
|
|
|
|
|
|
|
|
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 != '') {
|
|
|
|
var type = /^(?:(xls|xlsx|ods|csv|xlst|xlsy|gsheet)|(pps|ppsx|ppt|pptx|odp|pptt|ppty|gslides)|(doc|docx|doct|odt|gdoc|txt|rtf|pdf|mht|htm|html|epub|djvu|xps))$/
|
|
|
|
.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 = 'spreadsheet'; else
|
|
|
|
if (typeof type[2] === 'string') _config.documentType = 'presentation'; else
|
|
|
|
if (typeof type[3] === 'string') _config.documentType = 'text';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var type = /^(?:(pdf|djvu|xps))$/.exec(_config.document.fileType);
|
|
|
|
if (type && typeof type[1] === 'string') {
|
|
|
|
if (!_config.document.permissions)
|
|
|
|
_config.document.permissions = {};
|
|
|
|
_config.document.permissions.edit = 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);});
|
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
|
|
|
|
|
|
|
_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];
|
|
|
|
_config.editorConfig.canBackToFolder = false;
|
|
|
|
_config.editorConfig.canUseHistory = false;
|
|
|
|
if (!_config.editorConfig.customization) _config.editorConfig.customization = {};
|
|
|
|
_config.editorConfig.customization.about = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
var target = document.getElementById(placeholderId),
|
|
|
|
iframe;
|
|
|
|
|
|
|
|
if (target && _checkConfigParams()) {
|
|
|
|
iframe = createIframe(_config);
|
|
|
|
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
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var _showError = function(title, msg) {
|
|
|
|
_showMessage(title, msg, "error");
|
|
|
|
};
|
|
|
|
|
|
|
|
// severity could be one of: "error", "info" or "warning"
|
|
|
|
var _showMessage = function(title, msg, severity) {
|
|
|
|
if (typeof severity !== 'string') {
|
|
|
|
severity = "info";
|
|
|
|
}
|
|
|
|
_sendCommand({
|
|
|
|
command: 'showMessage',
|
|
|
|
data: {
|
|
|
|
title: title,
|
|
|
|
msg: msg,
|
|
|
|
severity: severity
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var _processMailMerge = function(enabled, message) {
|
|
|
|
_sendCommand({
|
|
|
|
command: 'processMailMerge',
|
|
|
|
data: {
|
|
|
|
enabled: enabled,
|
|
|
|
message: message
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var _downloadAs = function() {
|
|
|
|
_sendCommand({
|
|
|
|
command: 'downloadAs'
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var _processMouse = function(evt) {
|
|
|
|
var r = iframe.getBoundingClientRect();
|
|
|
|
var data = {
|
|
|
|
type: evt.type,
|
|
|
|
x: evt.x - r.left,
|
|
|
|
y: evt.y - r.top
|
|
|
|
};
|
|
|
|
|
|
|
|
_sendCommand({
|
|
|
|
command: 'processMouse',
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var _serviceCommand = function(command, data) {
|
|
|
|
_sendCommand({
|
|
|
|
command: 'internalCommand',
|
|
|
|
data: {
|
|
|
|
command: command,
|
|
|
|
data: data
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
showError : _showError,
|
|
|
|
showMessage : _showMessage,
|
|
|
|
applyEditRights : _applyEditRights,
|
|
|
|
processSaveResult : _processSaveResult,
|
|
|
|
processRightsChange : _processRightsChange,
|
|
|
|
denyEditingRights : _denyEditingRights,
|
|
|
|
refreshHistory : _refreshHistory,
|
|
|
|
setHistoryData : _setHistoryData,
|
|
|
|
setEmailAddresses : _setEmailAddresses,
|
|
|
|
processMailMerge : _processMailMerge,
|
|
|
|
downloadAs : _downloadAs,
|
|
|
|
serviceCommand : _serviceCommand,
|
|
|
|
attachMouseEvents : _attachMouseEvents,
|
2017-01-17 07:00:12 +00:00
|
|
|
detachMouseEvents : _detachMouseEvents,
|
|
|
|
destroyEditor : _destroyEditor
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DocsAPI.DocEditor.defaultConfig = {
|
|
|
|
type: 'desktop',
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
editorConfig: {
|
|
|
|
lang: 'en',
|
|
|
|
canCoAuthoring: true,
|
|
|
|
customization: {
|
|
|
|
about: false,
|
|
|
|
feedback: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DocsAPI.DocEditor.version = function() {
|
2017-01-09 09:39:04 +00:00
|
|
|
return '4.3.0';
|
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
|
|
|
|
if (msg && window.JSON) {
|
|
|
|
|
|
|
|
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',
|
|
|
|
'presentation': 'presentationeditor'
|
|
|
|
},
|
|
|
|
app = appMap['text'];
|
|
|
|
|
|
|
|
if (typeof config.documentType === 'string') {
|
|
|
|
app = appMap[config.documentType.toLowerCase()];
|
|
|
|
} else
|
|
|
|
if (!!config.document && typeof config.document.fileType === 'string') {
|
|
|
|
var type = /^(?:(xls|xlsx|ods|csv|xlst|xlsy|gsheet)|(pps|ppsx|ppt|pptx|odp|pptt|ppty|gslides))$/
|
|
|
|
.exec(config.document.fileType);
|
|
|
|
if (type) {
|
|
|
|
if (typeof type[1] === 'string') app = appMap['spreadsheet']; else
|
|
|
|
if (typeof type[2] === 'string') app = appMap['presentation'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
path += app + "/";
|
|
|
|
path += config.type === "mobile"
|
|
|
|
? "mobile"
|
|
|
|
: config.type === "embedded"
|
|
|
|
? "embed"
|
|
|
|
: "main";
|
|
|
|
path += "/index.html";
|
|
|
|
|
|
|
|
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
|
|
|
|
params += "&customer=ONLYOFFICE";
|
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;
|
|
|
|
}
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
2016-12-14 11:20:18 +00:00
|
|
|
|
|
|
|
if (config.frameEditorId)
|
|
|
|
params += "&frameEditorId=" + config.frameEditorId;
|
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
|
|
|
|
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);
|
|
|
|
|