joaopereirawd / animatedModal.js

animatedModal.js is a jQuery plugin to create a fullscreen modal with CSS3 transitions. You can use the transitions from animate.css or create your own transitions.
MIT License
962 stars 207 forks source link

request: close modal programmatically #24

Open sunilw opened 8 years ago

sunilw commented 8 years ago

@adnasa has fork that provides a way to open the modal from js.

I'd love to see the ability to close the modal programmatically as well. This would allow a 'close' event to be invoked in a sequence of events with greater ease.

leoli-dev commented 8 years ago

+1

It's better to have some sort of API, at least, open() and close().

Please.

adnasa commented 8 years ago

It is fairly easy to do it. I've created a branch (my repo has diverged extensively from this one) feature/open-api where I implemented this for the sake of this issue.

feature/open-api

Please help yourselves to try it out and let me know how it works.


Note that feature/open-api branch diverges from my own master as well :joy:

Have fun

onetrev commented 8 years ago

Hey @adnasa thanks for forking this script and adding some open/close API functionality. Only thing is, and excuse my JS / jQuery noobness, but I'm trying to use the API like so:

  $(document).keyup(function(ev){
    if(ev.keyCode == 27) {
      $.animatedModal.close();
    }
  });

But I receive a TypeError: $.animatedModal is undefined error message. Any chance you can point me in the right direction?

adnasa commented 8 years ago

@onetrev ooooh, it's been a while since I wrote this but after a quick read on the code, this should work

var demo = $("#demo01").animatedModal();
demo.open()
demo.close()
onetrev commented 8 years ago

Good news, that was helpful for me to get the script to fire.... Bad news... There are errors now within your edited script. :(

animatedModal.min.js:107 Uncaught TypeError: Cannot read property 'preventDefault' of undefinedcloseModal @ animatedModal.min.js:107
(anonymous function) @ demos.html:61
m.event.dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3
adnasa commented 8 years ago

@onetrev :) my bad

as you can see, there are two event.preventDefault() called in this file on Line 107 and Line 88...

Just remove those and you should be fine

onetrev commented 8 years ago

Radical, thanks!!! I can now let you know your script works perfectly! Hopefully you get a chance to adjust it in your fork in case anyone comes along and needs it.

Sure would be nice if this could be added to the original animatedModal.js repo, but not sure if it's still active. Doesn't look like it.

VictorLezh commented 8 years ago

@adnasa thanks for api! is working ;)

adnasa commented 8 years ago

@onetrev code is updated Should work better now ;)


enjoy

onetrev commented 8 years ago

Awesome thanks @adnasa! It worked with the edits you suggested previously, but I dropped the updated version and it continues to work nicely. Thanks again!

sunilw commented 6 years ago

@adnasa: It's great having an open method. However, when I use that method, the z-index set inline on the modal div remains at -9999. So the div remains invisible.

adnasa commented 6 years ago

@sunilw okay... here is a (couple of) thoughts

  1. We are discussing issues with my fork of the animatedModal. Let's move the discussion there if this is still pressing, and that we keep the discussion relevant to a solution (which is in my repo)
  2. It's been a while since I even looked into the code. I no longer use this lib, so I wouldn't know what problem I'm really going to solve.
  3. Feel free to open a PR

I highly suggest that we open a PR in this repo to provide a complete solution to the original lib so we no longer have to jump between repos

esseti commented 6 years ago

Someone has a solution for this? if i do

var mymodal =$("#animatedModal").animatedModal();
mymodal.open();

or If i try to close it, all the time I get demos.html:55 Uncaught TypeError: Cannot read property 'open' of undefined the #animatedModal is the Id of the div that I would like to have as modal.

onetrev commented 6 years ago

If you want to be able to do this @esseti you have to use the fork that @joaopereirawd created. And there are details here for how to use it: https://github.com/joaopereirawd/animatedModal.js/issues/24