mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-11 08:04:59 +02:00
refactor dropdown in accordance with readme
This commit is contained in:
41
js/bootstrap-accordion.js
vendored
41
js/bootstrap-accordion.js
vendored
@@ -1,41 +0,0 @@
|
|||||||
/* =============================================================
|
|
||||||
* bootstrap-accordion.js v2.0.0
|
|
||||||
* http://twitter.github.com/bootstrap/javascript.html#accordion
|
|
||||||
* =============================================================
|
|
||||||
* Copyright 2011 Twitter, Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
* ============================================================ */
|
|
||||||
|
|
||||||
(function( $ ){
|
|
||||||
|
|
||||||
var Accordion = function ( element, options ) {}
|
|
||||||
|
|
||||||
Accordion.prototype = {}
|
|
||||||
|
|
||||||
/* ALERT PLUGIN DEFINITION
|
|
||||||
* ======================= */
|
|
||||||
|
|
||||||
$.fn.accordion = function ( options ) {
|
|
||||||
|
|
||||||
if ( options === true ) {
|
|
||||||
return this.data('accordion')
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.each(function () {
|
|
||||||
new Accordion(this, options)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
})( window.jQuery || window.ender )
|
|
7
js/bootstrap-alerts.js
vendored
7
js/bootstrap-alerts.js
vendored
@@ -26,7 +26,7 @@
|
|||||||
* ====================== */
|
* ====================== */
|
||||||
|
|
||||||
var dismiss = '[data-dismiss="alert"]'
|
var dismiss = '[data-dismiss="alert"]'
|
||||||
, Alert = function ( el, close ) {
|
, Alert = function ( el ) {
|
||||||
$(el).delegate(dismiss, 'click', this.close)
|
$(el).delegate(dismiss, 'click', this.close)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +36,6 @@
|
|||||||
var $element = $(this)
|
var $element = $(this)
|
||||||
|
|
||||||
$element = $element.hasClass('alert-message') ? $element : $element.parent()
|
$element = $element.hasClass('alert-message') ? $element : $element.parent()
|
||||||
|
|
||||||
e && e.preventDefault()
|
e && e.preventDefault()
|
||||||
$element.removeClass('in')
|
$element.removeClass('in')
|
||||||
|
|
||||||
@@ -55,12 +54,12 @@
|
|||||||
/* ALERT PLUGIN DEFINITION
|
/* ALERT PLUGIN DEFINITION
|
||||||
* ======================= */
|
* ======================= */
|
||||||
|
|
||||||
$.fn.alert = function ( options ) {
|
$.fn.alert = function ( option ) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
var $this = $(this)
|
var $this = $(this)
|
||||||
, data = $this.data('alert')
|
, data = $this.data('alert')
|
||||||
if (!data) $this.data('alert', (data = new Alert(this)))
|
if (!data) $this.data('alert', (data = new Alert(this)))
|
||||||
if (typeof options == 'string') data[options].call($this)
|
if (typeof option == 'string') data[option].call($this)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
67
js/bootstrap-buttons.js
vendored
67
js/bootstrap-buttons.js
vendored
@@ -24,45 +24,56 @@
|
|||||||
/* BUTTON PUBLIC CLASS DEFINITION
|
/* BUTTON PUBLIC CLASS DEFINITION
|
||||||
* ============================== */
|
* ============================== */
|
||||||
|
|
||||||
var Button
|
var Button = function (element, options) {
|
||||||
|
this.$element = $(element)
|
||||||
function setState(el, state) {
|
this.settings = $.extend({}, $.fn.button.defaults, options)
|
||||||
var d = 'disabled'
|
|
||||||
, $el = $(el)
|
|
||||||
, data = $el.data()
|
|
||||||
, val = $el.is('input') ? 'val' : 'html'
|
|
||||||
|
|
||||||
state = state + 'Text'
|
|
||||||
data.resetText || $el.data('resetText', $el[val]())
|
|
||||||
|
|
||||||
$el[val]( data[state] || $.fn.button.defaults[state] )
|
|
||||||
|
|
||||||
setTimeout(function () {
|
|
||||||
state == 'loadingText' ?
|
|
||||||
$el.addClass(d).attr(d, d) :
|
|
||||||
$el.removeClass(d).removeAttr(d)
|
|
||||||
}, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggle(el) {
|
Button.prototype = {
|
||||||
var $el = $(el)
|
|
||||||
, $parent = $el.parent('[data-toggle="buttons-radio"]')
|
|
||||||
|
|
||||||
$parent && $parent
|
setState: function (state) {
|
||||||
.find('.active')
|
var d = 'disabled'
|
||||||
.removeClass('active')
|
, $el = this.$element
|
||||||
|
, data = $el.data()
|
||||||
|
, val = $el.is('input') ? 'val' : 'html'
|
||||||
|
|
||||||
|
state = state + 'Text'
|
||||||
|
data.resetText || $el.data('resetText', $el[val]())
|
||||||
|
|
||||||
|
$el[val](data[state] || this.settings[state])
|
||||||
|
|
||||||
|
// push to event loop to allow forms to submit
|
||||||
|
setTimeout(function () {
|
||||||
|
state == 'loadingText' ?
|
||||||
|
$el.addClass(d).attr(d, d) :
|
||||||
|
$el.removeClass(d).removeAttr(d)
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
, toggle: function () {
|
||||||
|
var $parent = this.$element.parent('[data-toggle="buttons-radio"]')
|
||||||
|
|
||||||
|
$parent && $parent
|
||||||
|
.find('.active')
|
||||||
|
.removeClass('active')
|
||||||
|
|
||||||
|
this.$element.toggleClass('active')
|
||||||
|
}
|
||||||
|
|
||||||
$el.toggleClass('active')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* BUTTON PLUGIN DEFINITION
|
/* BUTTON PLUGIN DEFINITION
|
||||||
* ======================== */
|
* ======================== */
|
||||||
|
|
||||||
$.fn.button = function(options) {
|
$.fn.button = function ( option ) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
if (options == 'toggle') return toggle(this)
|
var $this = $(this)
|
||||||
options && setState(this, options)
|
, data = $this.data('button')
|
||||||
|
, options = typeof option == 'object' && option
|
||||||
|
if (!data) $this.data('button', (data = new Button(this, options)))
|
||||||
|
if (option == 'toggle') data.toggle()
|
||||||
|
else if (option) data.setState(option)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
47
js/bootstrap-dropdown.js
vendored
47
js/bootstrap-dropdown.js
vendored
@@ -22,35 +22,42 @@
|
|||||||
|
|
||||||
"use strict"
|
"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) {
|
function clearMenus() {
|
||||||
var li = $(this).parent('li')
|
$(toggle).parent('li').removeClass('open')
|
||||||
, isActive = li.hasClass('open')
|
|
||||||
|
|
||||||
clearMenus()
|
|
||||||
!isActive && li.toggleClass('open')
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* DROPDOWN PLUGIN DEFINITION
|
/* DROPDOWN PLUGIN DEFINITION
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
$.fn.dropdown = function ( selector ) {
|
$.fn.dropdown = function ( option ) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
var args = ['click', toggle]
|
var $this = $(this)
|
||||||
, $this = $(this)
|
, data = $this.data('dropdown')
|
||||||
selector && args.unshift(selector)
|
if (!data) $this.data('dropdown', (data = new Dropdown(this)))
|
||||||
$this[selector ? 'delegate' : 'bind'].apply($this, args)
|
if (typeof option == 'string') data[option].call($this)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,8 +66,8 @@
|
|||||||
* =================================== */
|
* =================================== */
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
$('html').bind("click.dropdown.data-api", clearMenus)
|
$('html').bind('click.dropdown.data-api', clearMenus)
|
||||||
$('body').dropdown(s)
|
$('body').delegate(toggle, 'click.dropdown.data-api', Dropdown.prototype.toggle)
|
||||||
})
|
})
|
||||||
|
|
||||||
}( window.jQuery || window.ender );
|
}( window.jQuery || window.ender );
|
Reference in New Issue
Block a user