Added function for destroy editors.

This commit is contained in:
Julia Radzhabova 2017-01-17 10:00:12 +03:00
parent 0cf64ccd7b
commit 86ea2314a1

View file

@ -363,7 +363,7 @@
if (target && _checkConfigParams()) { if (target && _checkConfigParams()) {
iframe = createIframe(_config); iframe = createIframe(_config);
target.parentNode && target.parentNode.replaceChild(iframe, target); target.parentNode && target.parentNode.replaceChild(iframe, target);
this._msgDispatcher = new MessageDispatcher(_onMessage, this); var _msgDispatcher = new MessageDispatcher(_onMessage, this);
} }
/* /*
@ -372,6 +372,18 @@
data: <command specific data> data: <command specific data>
} }
*/ */
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);
}
};
var _sendCommand = function(cmd) { var _sendCommand = function(cmd) {
if (iframe && iframe.contentWindow) if (iframe && iframe.contentWindow)
postMessage(iframe.contentWindow, cmd); postMessage(iframe.contentWindow, cmd);
@ -538,7 +550,8 @@
downloadAs : _downloadAs, downloadAs : _downloadAs,
serviceCommand : _serviceCommand, serviceCommand : _serviceCommand,
attachMouseEvents : _attachMouseEvents, attachMouseEvents : _attachMouseEvents,
detachMouseEvents : _detachMouseEvents detachMouseEvents : _detachMouseEvents,
destroyEditor : _destroyEditor
} }
}; };
@ -563,18 +576,26 @@
MessageDispatcher = function(fn, scope) { MessageDispatcher = function(fn, scope) {
var _fn = fn, var _fn = fn,
_scope = scope || window; _scope = scope || window,
eventFn = function(msg) {
_onMessage(msg);
};
var _bindEvents = function() { var _bindEvents = function() {
if (window.addEventListener) { if (window.addEventListener) {
window.addEventListener("message", function(msg) { window.addEventListener("message", eventFn, false)
_onMessage(msg);
}, false)
} }
else if (window.attachEvent) { else if (window.attachEvent) {
window.attachEvent("onmessage", function(msg) { window.attachEvent("onmessage", eventFn);
_onMessage(msg); }
}); };
var _unbindEvents = function() {
if (window.removeEventListener) {
window.removeEventListener("message", eventFn, false)
}
else if (window.detachEvent) {
window.detachEvent("onmessage", eventFn);
} }
}; };
@ -592,6 +613,10 @@
}; };
_bindEvents.call(this); _bindEvents.call(this);
return {
unbindEvents: _unbindEvents
}
}; };
function getBasePath() { function getBasePath() {