2

I want to skin my own confirmation dialog using bootstrap modal without having to hook up events and without resorting to any library, except angular or jquery.

Basically, I want to be able to call something like:

if (myConfirm("text")) {
    // handle yes
} else {
    // handle no
};

myConfirm is supposed to show the modal, wait until either yes or no button was pressed and then return true or false.

What's the best way to do this? I am not concerned at all about any IE issues.

Mike Causer
  • 8,196
  • 2
  • 43
  • 63
Harald
  • 1,007
  • 1
  • 14
  • 27
  • 2
    There is no good way to do that. Make it event-based. – Ry- Feb 13 '14 at 01:04
  • And why no libraries? You can make a very nice modal dialog/confirm box using [colorbox](http://www.jacklmoore.com/colorbox/). – aroth Feb 13 '14 at 01:06
  • This question has a practical purpose but it is actually mostly about wanting to understand js better. I want to understand if there is a way to safely circumvent the event base approach of js. BTW: colorbox is event based. – Harald Feb 13 '14 at 01:17
  • use showModalDialog to make a modal html dialog instead of confirm() that still gives you the simple non-event sync interface you crave. It's not perfect from a developer standpoint, but it's a lot better from a user standpoint than confirm. – dandavis Feb 13 '14 at 01:22

1 Answers1

3

Your best bet for a blocking function is the old window.showModalDialog method (which has excellent IE support, btw). But you should not use it.

Make it event-based. Especially when for learning purposes. You won't get the bootstrap modal without events. If you want a nicer abstraction, return a Promise from your function.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375