From ee4d12bd573842261d8a3a63441fbf49e3a855e9 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 28 Feb 2018 18:15:33 +0100 Subject: [PATCH] abstract repeated call --- www/common/onlyoffice/inner.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index e95ebd64c..a324c5606 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -66,12 +66,18 @@ define([ config.onRemote(); } + var getContent = function () { + try { + return window.frames[0].frames[0].editor.asc_nativeGetFile(); + } catch (e) { return null; } + }; + var saveDocument = APP.saveDocument = function () { var defaultName = "text.oot"; UI.prompt(Messages.exportPrompt, defaultName, function (filename) { if (!(typeof(filename) === 'string' && filename)) { return; } console.log("In saveDocument"); - var content = window.frames[0].frames[0].editor.asc_nativeGetFile(); + var content = getContent(); var blob = new Blob([content], {type: "text/plain;charset=utf-8"}); saveAs(blob, filename); }); @@ -132,7 +138,7 @@ define([ console.log("Cannot access editor"); return; } - var data = window.frames[0].frames[0].editor.asc_nativeGetFile(); + var data = getContent(); console.log('onLocal, data avalable'); data = ''; var content = stringifyInner(data); @@ -240,7 +246,7 @@ define([ // force readonly to prevent interlacing readOnly = true; - var previousData = window.frames[0].frames[0].editor.asc_nativeGetFile(); + var previousData = getContent(); var userDoc = APP.realtime.getUserDoc(); var json = JSON.parse(userDoc);