User Story
As an developper, I want to unsubscribe or update elements located on my outer page when i replace an embedded instance by a different one.
This could be a callback or a listener to be triggered by the the zEmbedded.load method on the old desktop before cleaning up the page.
Acceptance Criteria
Developer can execute an action before the old desktop is unloaded.
Details
POC:
var originalDestroy = zEmbedded.destroy; zEmbedded.destroy = function (domId, skipError) { if (typeof zk === 'undefined') { if (skipError) return; else throw new Error('zk is not loaded.'); } var n = document.getElementById(domId); if (n) { var page = n.hasChildNodes() ? zk.$(n.firstChild) : null; if (page) { page.desktop.fire("onBeforeDestroy"); } } var result = originalDestroy.apply(this,arguments); return result; } function loadZk(){ zEmbedded.load('zkapp', 'http://localhost:8080/zkembedded-app/index.zul?myparam=init-from-client-side') .then(function(result) { var myWin = result.widget; myWin.desktop.listen({onBeforeDestroy:function(){ console.log("before destroy this desktop") }}); }) .catch(function(error) { console.error(error); }); } clientSideButton.addEventListener('click', function() { loadZk(); });