Skip to content
This repository has been archived by the owner on Oct 30, 2022. It is now read-only.

request: close modal programmatically #24

Open
sunilw opened this issue Jan 20, 2016 · 14 comments
Open

request: close modal programmatically #24

sunilw opened this issue Jan 20, 2016 · 14 comments

Comments

@sunilw
Copy link

sunilw commented Jan 20, 2016

@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
Copy link

+1

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

Please.

@adnasa
Copy link

adnasa commented Mar 5, 2016

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 😂

Have fun

@onetrev
Copy link

onetrev commented Apr 19, 2016

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
Copy link

adnasa commented Apr 19, 2016

@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
Copy link

onetrev commented Apr 19, 2016

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
Copy link

adnasa commented Apr 19, 2016

@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
Copy link

onetrev commented Apr 20, 2016

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
Copy link

@adnasa
thanks for api! is working ;)

@adnasa
Copy link

adnasa commented Apr 20, 2016

@onetrev code is updated
Should work better now ;)


enjoy

@onetrev
Copy link

onetrev commented Apr 20, 2016

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
Copy link
Author

sunilw commented Nov 6, 2017

@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
Copy link

adnasa commented Nov 6, 2017

@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
Copy link

esseti commented Feb 7, 2018

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
Copy link

onetrev commented Feb 7, 2018

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: #24

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants