dinbror / bpopup

bPopup is a lightweight jQuery modal popup plugin (only 1.34KB gzipped). It doesn't create or style your popup but provides you with all the logic like centering, modal overlay, events and more. It gives you a lot of opportunities to customize so it will fit your needs.
http://dinbror.dk/bPopup
427 stars 260 forks source link

Edited to clone()/remove() modal instead of append()/hide() #29

Open ghost opened 10 years ago

ghost commented 10 years ago

This can be an option, but I don't have time for that, sorry. Emacs trimmed whitespace so diff seems messy.

nickpiesco commented 10 years ago

@k1-hedayati Just wanted to thank you for this.... I was running into the same issue you probably did, and your modified version works a treat!

ghost commented 10 years ago

Your welcome, but consider this that I'm not a JS programmer so my changes may be dirty or hacky and they need to be written with correct way :)

dinbror commented 10 years ago

Hey there.

I just need to understand the use case. When and why do you prefer to clone/remove instead of append/hide?

Thanks Bjørn

nickpiesco commented 10 years ago

Ninja edit: I have a table of errors thrown by an application, and the last cell has my trigger link and a hidden div with the stack trace. I call the popup on the hidden div like this:

$('.open-popup').click(function() {
    $(this).siblings('.error-popup').bPopup();
});

.append() moves that content into the popup, breaking that sibling relationship – once I open and close the popup, I can't use the same trigger to open it again. Cloning the content into the popup div preserves that relationship, so I can open and close at will. It's kind of an edgy case, but that's what worked for me.

This is the only quibble I've had with what has been a very helpful plugin, though – I appreciate all your hard work!

dinbror commented 10 years ago

Have you tried setting the appending attribute to false?

nickpiesco commented 10 years ago

No, but the problem was solved and I've since moved on. :) I'm pretty sure I read through the API docs before realising what the exact issue was, so I probably didn't even think to re-check. Thanks for calling it out here, though, so anybody coming here from Google like I did can try that first without having to resort to hackery.