I'm using the leanModal http://leanmodal.finelysliced.com.au need to initiate it to open a div but without the .click() method. Basically I'm trying to do this..
if(cartItems === 0){
$("#cartEmpty").leanModal(); // #cartEmpty is my div with the message that needs to be initiated.
} else {
$("#nextStep").leanModal(); // #nextStep is my div is the form
}
Any ideas on this one?
I took a poke through the source code for leanmodal, looks like you can't. You'll still have to have a link to trigger it. But, you should be able to do something like the following untested top-of-my-head code
Add a couple of invisible links in. Inline styles are a Bad Thing, only doing it inline to simplify
<a href="#cartEmpty" id="showCartEmpty" style="display:none" rel="leanModal" name="cartEmpty">empty cart</a>
<a href="#nextStep" id="showNextStep" style="display:none" rel="leanModal" name="nextStep">next step</a>
Do the normal setup for leanmodal
$(function() {
$('a[rel*=leanModal]').leanModal();
});
Call the click method on your dummy invisible link
if(cartItems === 0){
$("#showCartEmpty").click(); // in theory this'll cause the modal to be shown
} else {
$("#showNextStep").click(); // in theory this'll cause the modal to be shown
}
Failing that, the source is pretty small, you should be able to wrangle it into your own project and modify it to be callable on the thing to modalise, not the thing to launch the modal
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