Another jQuery UI issue
Hello, all,
Same project as my earlier post about jQuery UI, same section of code. But a different problem.
I decided that I wanted to be tricky about opening the dialogs. I wanted to check for the existence of a dialog, first.
IF there is no dialog, immediately open one.
ELSE, close the currently open one, and open the new one in it's place. My logic suggested that since .dialog("close") doesn't have a callback, I'll have to use setTimeout() to delay opening the second dialog. I don't want to have both of them open at the same time, and they use the same z-index, so closing the first then delaying the open of the second seems (to me) logical.
But it isn't co-operating with me. ![]()
If there are no dialogs open and I click the top button, this alerts "false" and immediately opens the first dialog. If I click the second button without closing the first, it alerts "true", closes the first dialog, then opens the second after the first is gone. From this point, if I click the first button, again, it alerts "false" and opens the second dialog at the bottom of the page. The first dialog will never detect the second dialog.
<div class="rmh button"><a href="javascript:void(0);" title="Report an Event" id="rmn_rae">Report an Event</a></div>
<div class="rmh button"><a href="javascript:void(0);" title="Update Contacts" id="rmn_uc">Update Contacts</a></div><div id="dialog1" title="Report An Event" class="dialog">
<p>This is the first dialog. This is just placement text. Whoa.</p>
</div>
<div id="dialog2" title="Update Contacts" class="dialog">
<p>This is the second dialog. It's not closing the first dialog (if open) before opening when I click the button. Joy.</p>
</div><script>
$(document).ready(function(){
const rae = $('#rmn_rae'), uc = $('#rmn_uc');
var isOpen;
$(".dialog").dialog({
resizable: false,
autoOpen: false,
width: 800,
height: 500,
show: {
effect: "explode",
duration: 500
},
hide: {
effect: "explode",
duration: 500
}
});
rae.on('click',function(){
isOpen = $(".dialog").dialog("isOpen"); alert(isOpen);
switch(isOpen){
case true:
$(".dialog").dialog("close");
setTimeout(function(){
$("#dialog1").dialog("open");
},1200);
break;
default:
$("#dialog1").dialog("open");
break;
}
});
uc.on('click',function(){
isOpen = $(".dialog").dialog("isOpen"); alert(isOpen);
switch(isOpen){
case true:
$(".dialog").dialog("close");
setTimeout(function(){$("#dialog2").dialog("open");},1200);
break;
default:
$("#dialog2").dialog("open");
break;
}
});
});
</script>
What could I be missing, now?? ![]()
V/r,
^ _ ^
