I don't want to have the dialog centered on the screen so I'm setting the top and left coordinates of the box. I'm positioning it so that it appears next to a link and won't initially be open until a click.
$("#error").dialog({
bgiframe: true,
autoOpen: false,
width: 'auto',
height: 'auto',
hide: 'slide',
show: 'clip'
});
and
<div id="error" title="Error">
<div id="errorText"> </div>
</div>
From here I want to display an error message on the screen. For instance if I'm at the bottom of the page, I don't want the user to have to scroll down to see the dialog. Same thing if the error message is all the way on the right, I'd want to display it on the left side of the clicked element. The only problem with this since I have auto width and height it doesn't seem to know the height/width of the div before I show the dialog; with either $('#error').height() or $('#error').width().
$("#errorText").html(request.responseText + '<p>(Esc or click to close)</p>');
var x = el.position().left + el.outerWidth();
var y = el.position().top - $(document).scrollTop();
var position = el.position();
var bottomOfDialog = position.top + heightOfTheDialog;
if(bottomOfDialog > document.height)
{
y -= heightOfTheDialog;
}
var rightSideOfDialog = position.left + widthOfTheDialog;
if(rightSideOfDialog > document.width)
{
x -= (widthOfTheDialog + el.outerWidth());
}
$("#error").dialog('option', 'position', [x, y]).dialog('open');
How do I get a proper heightOfTheDialog and widthOfTheDialog before the actual dialog is opened? Or should I be using something else?