bind data-api events to document instead of body to allow body replacement #5308

Merged
merged 2 commits into from Oct 18, 2012

Conversation

Projects
None yet
Contributor

badcarl commented Sep 27, 2012

By binding data-api events to document, we can replace the body element without losing the bindings.

This is necessary to be compatible with https://github.com/rails/turbolinks and other javascript libraries that replace body.

badcarl referenced this pull request in turbolinks/turbolinks-classic Sep 27, 2012

Closed

Removing body also removes event listeners on body #16

josh commented Sep 27, 2012

You don't need to wait till ready anymore either.

This solved my problem and seems to work fine.

Works fine, looking forward to this making it into the next release!

badcarl referenced this pull request in turbolinks/turbolinks-classic Oct 5, 2012

Closed

Issues with bootstrap plugins #78

caarlos0 commented Oct 7, 2012

solve my problem too..

ollym commented Oct 7, 2012

+1 can you merge this please

This solved my problem when using Turbolinks too.

pusewicz commented Oct 8, 2012

👍

4ware commented Oct 8, 2012

👍

Bertg commented Oct 9, 2012

+1

jpzwarte commented Oct 9, 2012

Ran into the same problem, this solved it.

+1 We really need it!

fred commented Oct 12, 2012

👍 Please :)

@fat fat commented on the diff Oct 18, 2012

js/bootstrap-dropdown.js
@@ -138,13 +138,10 @@
/* APPLY TO STANDARD DROPDOWN ELEMENTS
* =================================== */
- $(function () {
- $('html')
- .on('click.dropdown.data-api touchstart.dropdown.data-api', clearMenus)
- $('body')
- .on('click.dropdown touchstart.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
- .on('click.dropdown.data-api touchstart.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
- .on('keydown.dropdown.data-api touchstart.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
- })
+ $(document)
@fat

fat Oct 18, 2012

Owner

this is a breaking change. you need to still bind to html i believe

@fat

fat Oct 18, 2012

Owner

hm nope, seems to work fine… though it will probably break something weird and we'll be sad in the future.

@fat

fat Oct 18, 2012

Owner

hopefully not tho

@josh

josh Oct 18, 2012

i can't imagine what you could be doing for it to make a difference.

w/ the old school $.fn.live, jquery defaulted to binding to document. still a fine delegation context.

@fat

fat Oct 18, 2012

Owner

document > body tho

@fat

fat Oct 18, 2012

Owner

im not gonna worry about it

fat merged commit e1f6458 into twbs:2.1.2-wip Oct 18, 2012

1 check passed

default The Travis build passed
Details

@jasny jasny referenced this pull request in jasny/bootstrap Jan 15, 2013

@jasny jasny Bind to document instead of 'body'
As per twitter#5308
ce0b235

@charlesbjohnson charlesbjohnson pushed a commit to charlesbjohnson/bootstrap that referenced this pull request Dec 9, 2014

@ghiculescu ghiculescu Bind to document instead of 'body'
As per twbs#5308
695b1cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment