"show.dialog" Dialog event is not fired
Asked by CelesteCS:

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}&amp;content_version={content.version}&amp;content_type={content.type}&amp;content_plugin={content.plugin}&amp;page_id={page.id}&amp;page_version={page.version}&amp;space_id={space.id}&amp;space_key={space.key}&amp;page_id={page.id}",				"options": 				{					"size": "small",					"header": 					{						"value": "Zzz plugin"					}				}			}		]	},	"scopes":	[		"read",		"write"	]}
```

zzz-dialog.html

```
&lt;!DOCTYPE html&gt;&lt;html lang="en" xmlns="http://www.w3.org/1999/html"&gt;	&lt;head&gt;		&lt;meta charset="utf-8"&gt;		&lt;meta http-equiv="X-UA-Compatible" content="IE=EDGE"&gt;		&lt;script id="connect-loader" data-options="sizeToParent:true;"&gt;			(function() {			  var getUrlParam = function (param) {			    var codedParam = (new RegExp(param + '=([^&amp;]*)')).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);			})();		&lt;/script&gt;		&lt;script src="/js/zzz-dialog.js"&gt;&lt;/script&gt;	&lt;/head&gt;	&lt;body style="background-color: #FFF"&gt;		&lt;p&gt;Zzz dialog is here.&lt;/p&gt;	&lt;/body&gt;&lt;/html&gt;
```

zzz-dialog.js

```
//AJS.$(document).ready(function($) { // this variant never worked as wellAJS.bind("show.dialog", function(e, data) {        alert("Dialog is initialized!"); // this alert is never shown :(});
```

Thanks!


Answers:
author: boydo
body: It looks like AJS is undefined

I suggest [including AUI resources](https://docs.atlassian.com/aui/getting-started.html#serve-from-cdn) in your html and then you can just do this in your javascript:

```
AJS.$(document).ready(function() {   	alert("Dialog is initialized!");});
```

comments: author: CelesteCS
body: Hi David!

I've downloaded .ZIP archive from your article, copied it to /lib folder, updated my HTML, but still alert is not shown.

Here is an updated HTML:

```
&lt;!DOCTYPE html&gt;&lt;html lang="en" xmlns="http://www.w3.org/1999/html"&gt;	&lt;head&gt;		&lt;meta charset="utf-8"&gt;		&lt;meta http-equiv="X-UA-Compatible" content="IE=EDGE"&gt;		&lt;link rel="stylesheet" href="/lib/aui/css/aui.min.css" media="all"&gt;		&lt;link rel="stylesheet" href="/lib/aui/css/aui-experimental.min.css" media="all"&gt;		&lt;script src="/lib/aui/js/aui.min.js"&gt;&lt;/script&gt;		&lt;script src="/lib/aui/js/aui-experimental.min.js"&gt;&lt;/script&gt;		&lt;script src="/lib/aui/js/aui-soy.min.js"&gt;&lt;/script&gt;		&lt;script id="connect-loader" data-options="sizeToParent:true;"&gt;			(function() {			  var getUrlParam = function (param) {			    var codedParam = (new RegExp(param + '=([^&amp;]*)')).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);			})();		&lt;/script&gt;	&lt;/head&gt;	&lt;body style="background-color: #FFF"&gt;		&lt;p&gt;Zzz dialog is here.&lt;/p&gt;	&lt;/body&gt;	&lt;script src="/js/zzz-dialog.js"&gt;&lt;/script&gt;	&lt;/html&gt;
```


author: boydo
body: Hi Alexey,

Sorry, my answer above was dependant on serving AUI from CDN, to get your example to work with the downloaded AUI, you just need to include JQuery in your HTML.

```
&lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt;
```


author: CelesteCS
body: Still cannot make this sample work ![sad](/html/@C495B4504065515364EB1894F812B34C/images/emoticons/sad.png "sad")

Can anybody provide complete working code for everybody to use it?

Thanks!


Tags: cloud

confluence-cloud