Editor.getModalDialog
Description
Retrieve the modalDialog object, to show a generic dialog.
ModalDialog vs Lookup
Modal dialogs can be opened at any time, unlike lookups which are always attached to a node, and more importantly, attached to a (trans)-action.
A transaction 'locks' the node that was used for the lookup. In other words, you cannot open a lookup for an image source attribute, and then delete the image from the lookup. Lookups handle this in their own way.
When you want to do more things with the XML from the dialog, a ModalDialog works better, since it allows you to change the XML as you would from regular API scripts.
Example
First we want to open a dialog:
var m = null; //create a global variable to use later
function openDialog()
{
m = Editor.getModalDialog();
m.
open("dialogpage.html");
}
However most likely you will either want to do something with a CMS, in which case the dialog really behaves like any other dialog or popup window, or you will want to do something with the XML. In that case you want to pass a specific node as the argument.
function openDialog(node)
{
...
This might be called from a button, or from XSL in ribbon-normalbutton :
<xsl:template match="img">
<img src="{@src}" onclick="openDialog(node);"/>
</xsl:template>
This node argument cannot be directly passed to the modal dialog in the open function. With a lookup the node is part of the transaction, and available through the dialog arguments. The ModalDialog has no dialogArguments. The best way to put the node in a variable:
var dialogNode = null
function openDialog(node)
{
dialogNode = node;
...
It is pretty tricky at this point to retrieve the node from inside the dialog page. Most likely the above script was added in the configuration directives contained in an island/Xopus Canvas, and as such the dialogNode variable is set in that window/frame.
In the dialog page you can access this window/frame with the following code:
//get the island
var canvas = parent.Editor.getActiveCanvas();
//get the the HTML of the island
var doc = canvas.getCanvasElement().ownerDocument;
//get the window for that HTML document (differs per browser)
w = doc.parentWindow || doc.defaultView
//get the node
var node = w.dialogNode;
Note the use of parent.Editor to get the Editor object which provides access to the XML document, as well as the canvas. If you save the window/frame as a global variable, you can use it later to close the dialog:
function close()
{
w.closeDialog();
}
Which calls a function in the island window/frame:
function closeDialog()
{
m.
close();
}
With this round trip you have access to the node that we opened the dialog for at all times.
Syntax
Editor.getModalDialog () : modalDialog
Return Value
modalDialog. The ModalDialog object.