From bdbb1c92aab9e9379341c80b8d1c53cc14ac7198 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Mon, 3 Oct 2011 10:05:43 +0100 Subject: [PATCH] Add jquery.ready hook after defining plugin, to avoid breakage when used 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. --- js/bootstrap-dropdown.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js index a3b0b0dfa4..68a3db5f20 100644 --- a/js/bootstrap-dropdown.js +++ b/js/bootstrap-dropdown.js @@ -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 * ========================== */ @@ -47,4 +36,18 @@ }) } -}( window.jQuery || window.ender ); \ No newline at end of file + /* 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 );