JQUERY, before you go to bed, put your toys AWAY! 8
So, I have some code that creates a jquery dialog, and inside the dialog, there is a set of tabs.
This dialog is inserted into the page via an ajax call, and after the elements defining the dialog and tabs, I have a section that builds up the dialog. Something like this. Note, these files are dummy ones, mocked up just to explore the issue.
<html>
<head>
<script type="text/javascript" src="/media/scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/media/scripts/jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript" src="/media/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="/media/tinymce/jscripts/tiny_mce/jquery-tinymce.js"></script>
<link rel="stylesheet" type="text/css" href="/media/stylesheet.css" />
<link rel="stylesheet" type="text/css" href="/media/styles/jquery-ui-1.7.2.custom.css" />
</head>
<body>
<h1>Test scaffold</h1>
<button onclick='load_dialog()'>Hi There</button>
<div id='dialog-area'>
<p>This is the dialog area, it will be replaced when you click the button</p>
</div>
<script language='javascript'>
function load_dialog()
{
$('#dialog-area').load('/media/dialog.html', function(){
});
}
</script>
</body>
</html>
and the dialog.html file looks like this.
<div id='dialog' title='Dialog Title'>
This is the dialog area.
<div id='tabs'>
<ul>
<li><a href='#tabs-1'>First</a></li>
<li><a href='#tabs-2'>Second</a></li>
<li><a href='#tabs-3'>Third</a></li>
</ul>
<div id='tabs-1'>
<h1>Tab One</h1>
<p>This is the content for tab one</p>
</div>
<div id='tabs-2'>
<h1>Tab Two</h1>
<p>This is the content for tab two</p>
</div>
<div id='tabs-3'>
<h1>Tab Three</h1>
<p>This is the content for tab three</p>
</div>
</div>
</div>
<script language='javascript'>
$(function(){
alert('in prep dialog');
$('#dialog-area > #dialog').dialog({modal: true,
width: 500,
height: 400,
autoOpen: false,
buttons: {'ok': function(){$(this).dialog('close');
}}});
$("#dialog").bind('dialogopen', function() {
/* init tabs, when dialog is opened */
$("#tabs").tabs();
});
$("#dialog").bind('dialogclose', function() {
$("#tabs").tabs('destroy');
$("#dialog").dialog('destroy');
$('#dialog').remove();
});
/* your function to open the dialog */
$("#dialog").dialog('open');
});
</script>
Now, previously I did not have that $('#dialog').remove(); line in there. the dialog was inside the area that was going to get replaced by the ajax call right? so no problem!
But NO, it turns out that when jquery creates the dialog it repositions the dialog element within the DOM of the document, and so it is OUTSIDE of the area being replaced by the ajax. So, when I do it AGAIN, the page now has two dialog elements. Having two confuses jquery and breaks all sorts of things. So, removing the dialog after it has been 'destroyed' fixes the issue.
l8VA8x polgluapvuzk, [url=http://uvdavlsveqqw.com/]uvdavlsveqqw[/url], [link=http://rfwypcuoaofv.com/]rfwypcuoaofv[/link], http://zbpsmdifdnhe.com/
SH8UG2 cidngzavcqwk, [url=http://wmgqckdsbebv.com/]wmgqckdsbebv[/url], [link=http://ptnvaxhoidey.com/]ptnvaxhoidey[/link], http://aekoqrpaiiwf.com/
KGrKLE klcfqfotyegq, [url=http://boyfncdaaahg.com/]boyfncdaaahg[/url], [link=http://rvwwlgovzxra.com/]rvwwlgovzxra[/link], http://ntrvlfgtweel.com/