Life @ NCP

not everyone needs to go outside to have fun

Closing popovers in Ratchet

Ratchet is a css/js library for prototyping iOS apps. Maintained by Twitter, it looks similar to its more established older brother Bootstrap but is much less mature and has an anemic API.

Simple things like closing its popovers don’t seem to exist. If you need to do this, digging into the source reveals

    element.addEventListener('touchend', function () {  
          popover.addEventListener('webkitTransitionEnd', onPopoverHidden);

for the popover backdrop, so doing something like

    var backdrop = document.querySelector('div.backdrop');  
    if (backdrop) {  
      // sad there's not real way to close this
      var evt = document.createEvent('TouchEvent');
      evt.initUIEvent('touchend', true, true); = backdrop;

to dispatch the touch event was sufficient for my purposes.

See for a short discussion on this.