define([ 'jquery', '/common/toolbar3.js', 'json.sortify', '/bower_components/nthen/index.js', '/common/sframe-common.js', '/common/common-interface.js', '/common/common-hash.js', '/common/common-util.js', '/api/config', '/customize/messages.js', '/customize/application_config.js', '/bower_components/chainpad/chainpad.dist.js', '/file/file-crypto.js', '/common/onlyoffice/oocell_base.js', '/common/onlyoffice/oodoc_base.js', '/common/onlyoffice/ooslide_base.js', '/common/outer/worker-channel.js', '/bower_components/tweetnacl/nacl-fast.min.js', '/bower_components/file-saver/FileSaver.min.js', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/common/onlyoffice/app-oo.less', ], function ( $, Toolbar, JSONSortify, nThen, SFCommon, UI, Hash, Util, ApiConfig, Messages, AppConfig, ChainPad, FileCrypto, EmptyCell, EmptyDoc, EmptySlide, Channel) { var saveAs = window.saveAs; var Nacl = window.nacl; var APP = window.APP = { $: $ }; var stringify = function (obj) { return JSONSortify(obj); }; var toolbar; var andThen = function (common) { var readOnly = false; var locked = false; var config = {}; var hashes = []; var getFileType = function () { var type = common.getMetadataMgr().getPrivateData().ooType; var title = common.getMetadataMgr().getMetadataLazy().title; var file = {}; switch(type) { case 'oodoc': file.type = 'docx'; file.title = title + '.docx' || 'document.docx'; file.doc = 'text'; break; case 'oocell': file.type = 'xlsx'; file.title = title + '.xlsx' || 'spreadsheet.xlsx'; file.doc = 'spreadsheet'; break; case 'ooslide': file.type = 'pptx'; file.title = title + '.pptx' || 'presentation.pptx'; file.doc = 'presentation'; break; } return file; }; var openRtChannel = function (data) { // XXX var channel = Hash.createChannelId(); ctx.sframeChan.query('Q_OO_OPENCHANNEL', channel, function (err, obj) { if (err || (obj && obj.error)) { console.error(err || (obj && obj.error)); } }); }; var mkChannel = function () { var msgEv = Util.mkEvent(); var iframe = $('#cp-app-oo-container > iframe')[0].contentWindow; window.addEventListener('message', function (msg) { if (msg.source !== iframe) { return; } msgEv.fire(msg); }); var postMsg = function (data) { iframe.postMessage(data, '*'); }; Channel.create(msgEv, postMsg, function (chan) { APP.chan = chan; chan.on('CMDFROMOO', function (data) { console.log('command from oo', data); setTimeout(function () { chan.event('RTMSG', 'Pewpewpew'); }, 2000); }); }); }; var startOO = function (blob, file) { if (APP.ooconfig) { return void console.error('already started'); } var url = URL.createObjectURL(blob); var lock = locked !== common.getMetadataMgr().getNetfluxId() || !common.isLoggedIn(); // Config APP.ooconfig = { "document": { "fileType": file.type, "key": "fresh", "title": file.title, "url": url, "permissions": { "download": false, // FIXME: download/export is not working, so we use false // to remove the button } }, "documentType": file.doc, "editorConfig": { customization: { chat: false, logo: { url: "/bounce/#" + encodeURIComponent('https://www.onlyoffice.com') } }, "user": { "id": "", //"c0c3bf82-20d7-4663-bf6d-7fa39c598b1d", "name": "", //"John Smith" }, "mode": readOnly || lock ? "view" : "edit" }, "events": { "onDocumentStateChange": function (evt) { if (evt.data) { console.log('in change (local)'); return; } console.log("in change (remote)"); }, "onReady": function(/*evt*/) { var $tb = $('iframe[name="frameEditor"]').contents().find('head'); var css = '#id-toolbar-full .toolbar-group:nth-child(2), #id-toolbar-full .separator:nth-child(3) { display: none; }' + '#fm-btn-save { display: none !important; }' + '#header { display: none !important; }'; $('