ダイアログを画面の中央に配置したくないので、ボックスの上と左の座標を設定しています。リンクの横に表示され、クリックするまで最初は開かないように配置しています。
$("#error").dialog({
bgiframe: true,
autoOpen: false,
width: 'auto',
height: 'auto',
hide: 'slide',
show: 'clip'
});
と
<div id="error" title="Error">
<div id="errorText"> </div>
</div>
ここから、画面にエラーメッセージを表示したいと思います。たとえば、ページの下部にいる場合、ユーザーが下にスクロールしてダイアログを表示する必要はありません。エラーメッセージがずっと右側にある場合も同じです。クリックした要素の左側に表示したいと思います。これに関する唯一の問題は、幅と高さが自動であるため、ダイアログを表示する前に div の高さ/幅がわからないようです。$('#error').height() または $('#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');
実際のダイアログが開かれる前に適切な heightOfTheDialog と widthOfTheDialog を取得するにはどうすればよいですか? または、何か他のものを使用する必要がありますか?