Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

leanModal initiate without .click()

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?

like image 364
Braunson Avatar asked Jul 15 '11 05:07

Braunson


1 Answers

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

like image 139
Dan F Avatar answered Nov 20 '22 09:11

Dan F