Skip to content

Commit

Permalink
Add jquery.ready hook after defining plugin, to avoid breakage when u…
Browse files Browse the repository at this point in the history
…sed with modernizr/yepnope

See https://gist.github.com/1258742 for an example, which results in the error

"TypeError: Object has no method 'dropdown' at bootstrap-dropdown.js line 31"

It looks like in these circumstances, the functions hooked into
jquery.ready get run immediately, and so applying the dropdown
behavior to specific elements before defining the 'dropdown' method
causes breakage.
  • Loading branch information
purcell committed Oct 3, 2011
1 parent 7e01ff8 commit bdbb1c9
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions js/bootstrap-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@

!function( $ ){

var d = 'a.menu, .dropdown-toggle'

function clearMenus() {
$(d).parent('li').removeClass('open')
}

$(function () {
$('html').bind("click", clearMenus)
$('body').dropdown( '[data-dropdown] a.menu, [data-dropdown] .dropdown-toggle' )
})

/* DROPDOWN PLUGIN DEFINITION
* ========================== */

Expand All @@ -47,4 +36,18 @@
})
}

}( window.jQuery || window.ender );
/* APPLY TO STANDARD DROPDOWN ELEMENTS
* =================================== */

var d = 'a.menu, .dropdown-toggle'

function clearMenus() {
$(d).parent('li').removeClass('open')
}

$(function () {
$('html').bind("click", clearMenus)
$('body').dropdown( '[data-dropdown] a.menu, [data-dropdown] .dropdown-toggle' )
})

}( window.jQuery || window.ender );

0 comments on commit bdbb1c9

Please sign in to comment.