I use the SimpleModal plugin to display a dialog on a site. Inside this dialog, I have two links that will execute AJAX requests, and the response from these requests should replace the current contents of the dialog box. I try to keep everything as flexible as possible so that if I want to load various answers in the dialog box in the future, this will just work.
In one function, I open a dialog:
$('div.modal').modal(
{
minWidth: width,
minHeight: height,
onOpen: modal_onOpen,
onClose: modal_onClose
});
The onClose callback is as follows:
function modal_onClose(dialog)
{
dialog.container.fadeOut('slow', function()
{
dialog.data.hide();
if(reload_dialog)
{
data = ajax_page_load(reload_url, false, false);
if(data.statusText == 'OK')
{
dialog.container.width(reload_width);
dialog.container.height(reload_height);
$.modal.setPosition();
$('div.modal div.container').html(data.responseText);
dialog.data.show();
dialog.container.fadeIn('slow', function()
{
$('a.simplemodal-close').bind('click', function()
{
$.modal.close();
});
});
}
reload_dialog = false;
}
else
{
dialog.overlay.slideUp('slow', function()
{
$.modal.close();
});
}
});
}
And when I want to load something new into the dialog, I have the following:
var reload_dialog = false;
var reload_url;
var reload_width;
var reload_height;
function load_dialog(url, width, height)
{
reload_dialog = true;
reload_url = url;
reload_width = width;
reload_height = height;
$.modal.close();
}
Now all the functions are above code. But I am worried that I have a path to complex things. That's why:
modal_onClose . , AJAX, . , onClose, .
, .
- - ? ?
, , :)