tags:

views:

72

answers:

2

EDIT: rewrote this to be html only

In the following code, why is the jquery dialog that's displayed not centered? The dialog is opened by clicking the "test" button on the page.

<html>
<head>
    <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="ui/jquery.ui.core.js"></script>
    <script type="text/javascript" src="ui/jquery.ui.widget.js"></script>
    <script type="text/javascript" src="ui/jquery.ui.dialog.js"></script>
    <link type="text/css" href="themes/base/jquery.ui.all.css" rel="stylesheet" />

<script>
  function showDialog() {
    $("#dialog-modal").dialog({
        resizable: true,
        height: 140,
        modal: true,
        position: 'center',
        buttons: {
            'Yes': function () {
                $(this).dialog("close");
                return true;
            },
            'No': function () {
                $(this).dialog("close");
                return false;
            }
        }
    });
  }
</script>

</head>
<body>

<div style="width:800px; height:800px; border:solid 1px red;">

<div id="dialog-modal" title="Basic dialog"></div>

<input type="button" value="test" onclick="showDialog();"></input>

</div><!-- End demo -->


</body>

</html>
A: 

Hi dcp,

I have recreated your scenario at http://jsfiddle.net/zjRga/1/. I have tested it a few times and I cannot reproduce what you state. Can you double check it? Can you confirm us that you are not using any extra CSS?

Note: I have made some minor (non-crucial) changes to make it works.

Hope it helps.

Rubens Mariuzzo
It's something with the js files for jquery that are being included. You really need to try it standalone (i.e outside of a site like jsfiddle) so I can see what files are being included. JQuery seems to be extremely picky about this.
dcp
A: 

I solved it by adding these includes:

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/jquery-ui.min.js"
    type="text/javascript"></script>
<script src="http://jquery-ui.googlecode.com/svn/tags/latest/external/jquery.bgiframe-2.1.1.js"
    type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/i18n/jquery-ui-i18n.min.js"
    type="text/javascript"></script>
dcp