Hello,
I'm writing a simple Confluence Cloud plugin, which has a web-item and a dialog. When Web item is pressed, a dialog is shown. When it is shown. some JS code should be evaluated. I'm trying to subscribe to "show.dialog" event, but my event handler is never run. What is wrong?
I'm sure I'm not the only one who has similar question. So I paste the code here to have a complete sample (when my question is answered) of how it should be done correctly.
Thanks!
atlassian-connect.json
{
"key": "zzz-key",
"name": "zzz plugin",
"description": "Zzz",
"baseUrl": "http://localhost:8889",
"vendor":
{
"name": "Zzz Labs",
"url": "http://www.zzz.com"
},
"authentication":
{
"type": "none"
},
"version": "0.1",
"modules":
{
"webItems":
[
{
"location": "system.attachment",
"weight": 20,
"styleClasses":
[
"webitem",
"system-present-webitem"
],
"context": "addon",
"target":
{
"type": "dialogmodule",
"options":
{
"key": "zzz-dialog"
}
},
"tooltip":
{
"value": "Zzz this file"
},
"icon":
{
"width": 16,
"height": 16,
"url": "/images/IconZzz.png"
},
"name":
{
"value": "Zzz this file"
},
"key": "zzz-link"
}
],
"dialogs":
[
{
"key": "zzz-dialog",
"url": "/zzz-dialog.html?content_id={content.id}&content_version={content.version}&content_type={content.type}&content_plugin={content.plugin}&page_id={page.id}&page_version={page.version}&space_id={space.id}&space_key={space.key}&page_id={page.id}",
"options":
{
"size": "small",
"header":
{
"value": "Zzz plugin"
}
}
}
]
},
"scopes":
[
"read",
"write"
]
}
zzz-dialog.html
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=EDGE">
<script id="connect-loader" data-options="sizeToParent:true;">
(function() {
var getUrlParam = function (param) {
var codedParam = (new RegExp(param + '=([^&]*)')).exec(window.location.search)[1];
return decodeURIComponent(codedParam);
};
var baseUrl = getUrlParam('xdm_e') + getUrlParam('cp');
var options = document.getElementById('connect-loader').getAttribute('data-options');
var script = document.createElement("script");
script.src = baseUrl + '/atlassian-connect/all.js';
if(options) {
script.setAttribute('data-options', options);
}
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
<script src="/js/zzz-dialog.js"></script>
</head>
<body style="background-color: #FFF">
<p>Zzz dialog is here.</p>
</body>
</html>
zzz-dialog.js
//AJS.$(document).ready(function($) { // this variant never worked as well
AJS.bind("show.dialog", function(e, data) {
alert("Dialog is initialized!"); // this alert is never shown
});
Thanks!