[Common] refactored plugin's messages

This commit is contained in:
Maxim Kadushkin 2017-03-03 12:45:37 +03:00
parent 0cc19d4640
commit a715009eee

View file

@ -258,30 +258,29 @@
}; };
var _onMessage = function(msg) { var _onMessage = function(msg) {
if (msg && msg.frameEditorId == placeholderId) { if ( msg ) {
var events = _config.events || {}, if ( msg.type === "onExternalPluginMessage" ) {
handler = events[msg.event], _sendCommand(msg);
res;
if (msg.event === 'onRequestEditRights' && !handler) {
_applyEditRights(false, 'handler is\'n defined');
} else } else
if (msg.event === 'onInternalMessage' && msg.data && msg.data.type == 'localstorage') { if ( msg.frameEditorId == placeholderId ) {
_callLocalStorage(msg.data.data); var events = _config.events || {},
} else { handler = events[msg.event],
if (msg.type === "onExternalPluginMessage") { res;
_sendCommand(msg);
return;
}
if (msg.event === 'onReady') { if (msg.event === 'onRequestEditRights' && !handler) {
_onReady(); _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) { if (handler) {
res = handler.call(_self, { target: _self, data: msg.data }); res = handler.call(_self, {target: _self, data: msg.data});
if (msg.event === 'onSave' && res !== false) { if (msg.event === 'onSave' && res !== false) {
_processSaveResult(true); _processSaveResult(true);
}
} }
} }
} }