I have 12 dialogs on one page. I only want them to open if neither of the other 12 dialogs are open. I don't want it to close the existing and open a new one, I simply want it to only open one dialog at a time, and stop the user from being able to open two at a time.
Sample HTML:
<div id="thumb2" class="suiting-thumb">
<img src="img/gallery/suit1-thumb.jpg" alt="" title="" />
</div>
<div id="galleryDialog2" class="galleryDialog">
<a id="prev-arrow" href="#"></a>
<a id="next-arrow" href="#"></a>
<div class="text">
text and link
</div>
<div class="dialog-slider">
<img src="img/suiting-details/custom-suiting-vent-styles.jpg" alt="" title="" />
<img src="img/suiting-details/custom-suit-coat-lining.jpg" alt="" title="" />
</div>
</div>
JS:
/* Gallery Dialog Settings */
$('[id^=galleryDialog]').dialog({
width: 480,
height:479, /* 479 seems to be the magic number to get the box to fit vertically on the slider */
show: 'fade',
hide: 'fade',
autoOpen: false,
draggable: false,
open: function() {
$('#four').stop().fadeTo("fast", 0.3);
$('.suiting-thumb').stop().fadeTo("fast", 1.0);
$("a#prev").attr("id","prev-false");
$("a#next").attr("id", "next-false");
$('.suiting-thumb').attr('class', 'suiting-thumb-false');
},
close: function() {
$('#four').stop().fadeTo("normal", 1);
$("a#prev-false").attr("id","prev");
$("a#next-false").attr("id", "next");
$('.suiting-thumb-false').attr('class', 'suiting-thumb');
}
});
$('.suiting-thumb').click(function() {
//strip off prefix of thumb id to get number for dialog
var thumbBtnIdPrefix = 'thumb';
var thumbBtnNum = $(this).attr('id').substring((thumbBtnIdPrefix.length));
if(!$('.galleryDialog').dialog("isOpen")) {
$('#galleryDialog' + thumbBtnNum).dialog('open').dialog('widget').position({
at: 'center center',
of: $('#slider'),
offset: "75 0"
});
}
});
I'm trying to use an if statemenet that checka to see if ".galleryDialog", a class applied to all dialog divs, is not open. If not open, then open the clicked dialog. This works properly whenever you open "galleryDialog1", but when I close the first and open a different one, you can then open as many as you'd like, all at once.
Any help would be amazing. Thanks!
Why don't you add modal: true
to the dialog calls, that way you can only view one at a time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With