1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-26 21:39:08 +02:00

refactor dropdown in accordance with readme

This commit is contained in:
Jacob Thornton
2011-11-24 19:40:25 -08:00
parent 71654cbf69
commit 69372701cf
4 changed files with 69 additions and 93 deletions

View File

@@ -22,35 +22,42 @@
"use strict"
/* SIMPLE DROPDOWN LOGIC
* ===================== */
/* DROPDOWN CLASS DEFINITION
* ========================= */
var s = '[data-toggle="dropdown"]'
var toggle = '[data-toggle="dropdown"]'
, Dropdown = function ( element ) {
$(element).bind('click', this.toggle)
}
Dropdown.prototype = {
toggle: function ( e ) {
var li = $(this).parent('li')
, isActive = li.hasClass('open')
clearMenus()
!isActive && li.toggleClass('open')
return false
}
function clearMenus() {
$(s).parent('li').removeClass('open')
}
function toggle(e) {
var li = $(this).parent('li')
, isActive = li.hasClass('open')
clearMenus()
!isActive && li.toggleClass('open')
return false
function clearMenus() {
$(toggle).parent('li').removeClass('open')
}
/* DROPDOWN PLUGIN DEFINITION
* ========================== */
$.fn.dropdown = function ( selector ) {
$.fn.dropdown = function ( option ) {
return this.each(function () {
var args = ['click', toggle]
, $this = $(this)
selector && args.unshift(selector)
$this[selector ? 'delegate' : 'bind'].apply($this, args)
var $this = $(this)
, data = $this.data('dropdown')
if (!data) $this.data('dropdown', (data = new Dropdown(this)))
if (typeof option == 'string') data[option].call($this)
})
}
@@ -59,8 +66,8 @@
* =================================== */
$(function () {
$('html').bind("click.dropdown.data-api", clearMenus)
$('body').dropdown(s)
$('html').bind('click.dropdown.data-api', clearMenus)
$('body').delegate(toggle, 'click.dropdown.data-api', Dropdown.prototype.toggle)
})
}( window.jQuery || window.ender );