"show.dialog" Dialog event is not fired

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!

1 answer

This widget could not be displayed.
David Boyd Atlassian Team Nov 15, 2016

It looks like AJS is undefined 

I suggest including AUI resources in your html and then you can just do this in your javascript:

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

 

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:

<!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">
		<link rel="stylesheet" href="/lib/aui/css/aui.min.css" media="all">
		<link rel="stylesheet" href="/lib/aui/css/aui-experimental.min.css" media="all">
		<script src="/lib/aui/js/aui.min.js"></script>
		<script src="/lib/aui/js/aui-experimental.min.js"></script>
		<script src="/lib/aui/js/aui-soy.min.js"></script>
		<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>
	</head>
	<body style="background-color: #FFF">
		<p>Zzz dialog is here.</p>
	</body>
	<script src="/js/zzz-dialog.js"></script>	
</html>
David Boyd Atlassian Team Nov 16, 2016

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. 

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

Still cannot make this sample work sad

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

Thanks!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

477 views 6 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you