2

How do you destroy a Bootstrap popover created with a selector option? e.g.

$e.popover({
  selector: 'mark',
  trigger: 'hover',
  container: "body",
});

If you then call $e.popover('destroy') you get an error.

I note that the Plugin function called by popover('destroy') is as follows:

 function Plugin(option) {
    return this.each(function () {
      var $this    = $(this)
      var data     = $this.data('bs.popover')
      var options  = typeof option == 'object' && option
      var selector = options && options.selector

      if (!data && option == 'destroy') return
      if (selector) {
        if (!data) $this.data('bs.popover', (data = {}))
        if (!data[selector]) data[selector] = new Popover(this, options)
      } else {
        if (!data) $this.data('bs.popover',(data = new Popover(this, options)))
      }
      if (typeof option == 'string') data[option]() /// <<-- THIS ALWAYS FAILS
    })
  }

If you call $e.popover('destroy') the above line (clearly marked) always fails because it is calling data['destroy'], however the data will be an object like {mark: Popover}.

It should clearly be calling data['mark']['destroy'] but it is not immediately clear to me how this is supposed to happen.

One option is to create a string s = 'destroy' then add the selector property to the string, but it should be apparent that that is not the intended design.

Alternatively, one could call $e.data('bs.popover').mark.destroy(), but again I am not sure that's the intended design, and it's not documented anywhere I could find.

Here's a sample jsFiddle

Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
  • What version of Bootstrap are you using? Even when using your code, I still get `data` being what it should be (what is `data.mark` in your examples). – Matt Nov 24 '14 at 16:32
  • @Matt It's Bootstrap 3.3.1 – Brian M. Hunt Nov 24 '14 at 16:38
  • Ah, I was working on a older version. Seems like a blatant bug in Bootstrap (introduced in this commit; https://github.com/twbs/bootstrap/commit/1b3237629a316af41945e20837cf3a332798b264) – Matt Nov 24 '14 at 16:42
  • Thanks @Matt - good find. :) Feel free to submit a bug report to twbs and reference this (or let me know and I can submit one). Cheers – Brian M. Hunt Nov 24 '14 at 16:50
  • 1
    Brian: I've commented on https://github.com/twbs/bootstrap/issues/15168... seems it wasn't a very well thought through change, and breaks a lot of things! – Matt Nov 24 '14 at 16:54
  • Very good, thanks @Matt. – Brian M. Hunt Nov 24 '14 at 18:00

1 Answers1

2

As Matt commented, this is a Bootstrap bug in 3.3.1.

Community
  • 1
  • 1
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343