From 9d2811389a264c9c38fbfbdf162aa52231351c1d Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 11 Apr 2017 15:04:24 +0300 Subject: [PATCH] send message to frameEditor (for plugins only). refactored plugin's messages. --- apps/api/documents/api.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index 7853efe00..8426c9be9 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -258,25 +258,29 @@ }; var _onMessage = function(msg) { - if (msg && msg.frameEditorId == placeholderId) { - var events = _config.events || {}, - handler = events[msg.event], - res; - - if (msg.event === 'onRequestEditRights' && !handler) { - _applyEditRights(false, 'handler is\'n defined'); + if ( msg ) { + if ( msg.type === "onExternalPluginMessage" ) { + _sendCommand(msg); } else - if (msg.event === 'onInternalMessage' && msg.data && msg.data.type == 'localstorage') { - _callLocalStorage(msg.data.data); - } else { - if (msg.event === 'onReady') { - _onReady(); - } + if ( msg.frameEditorId == placeholderId ) { + var events = _config.events || {}, + handler = events[msg.event], + res; - if (handler) { - res = handler.call(_self, { target: _self, data: msg.data }); - if (msg.event === 'onSave' && res !== false) { - _processSaveResult(true); + 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); + } } } }