bootstrap-dropdown.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* ============================================================
  2. * bootstrap-dropdown.js v1.3.0
  3. * http://twitter.github.com/bootstrap/javascript.html#dropdown
  4. * ============================================================
  5. * Copyright 2011 Twitter, Inc.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * ============================================================ */
  19. !function( $ ){
  20. var d = 'a.menu, .dropdown-toggle'
  21. function clearMenus() {
  22. $(d).parent('li').removeClass('open')
  23. }
  24. $(function () {
  25. $('html').bind("click", clearMenus)
  26. $('body').dropdown( '[data-dropdown] a.menu, [data-dropdown] .dropdown-toggle' )
  27. })
  28. /* DROPDOWN PLUGIN DEFINITION
  29. * ========================== */
  30. $.fn.dropdown = function ( selector ) {
  31. return this.each(function () {
  32. $(this).delegate(selector || d, 'click', function (e) {
  33. var li = $(this).parent('li')
  34. , isActive = li.hasClass('open')
  35. clearMenus()
  36. !isActive && li.toggleClass('open')
  37. return false
  38. })
  39. })
  40. }
  41. }( window.jQuery || window.ender );