2015-01-03 16:58:44 -05:00
|
|
|
|
/** =======================================================================
|
|
|
|
|
* Bootstrap: button.js v4.0.0
|
2013-10-29 13:10:47 -04:00
|
|
|
|
* http://getbootstrap.com/javascript/#buttons
|
2013-05-21 22:30:33 -04:00
|
|
|
|
* ========================================================================
|
2014-12-31 19:23:48 -05:00
|
|
|
|
* Copyright 2011-2015 Twitter, Inc.
|
2013-12-18 18:28:08 -05:00
|
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
2015-01-03 16:58:44 -05:00
|
|
|
|
* ========================================================================
|
|
|
|
|
* @fileoverview - Bootstrap's generic button component.
|
|
|
|
|
*
|
|
|
|
|
* Note (@fat): Deprecated "setState" – imo, better solutions for managing a
|
|
|
|
|
* buttons state should exist outside this plugin.
|
|
|
|
|
*
|
|
|
|
|
* Public Methods & Properties:
|
|
|
|
|
*
|
|
|
|
|
* + $.button
|
|
|
|
|
* + $.button.noConflict
|
|
|
|
|
* + $.button.Constructor
|
|
|
|
|
* + $.button.Constructor.VERSION
|
|
|
|
|
* + $.button.Constructor.prototype.toggle
|
|
|
|
|
*
|
|
|
|
|
* ========================================================================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Our Button class.
|
|
|
|
|
* @param {Element!} element
|
|
|
|
|
* @constructor
|
|
|
|
|
*/
|
|
|
|
|
var Button = function (element) {
|
|
|
|
|
|
|
|
|
|
/** @private {Element} */
|
|
|
|
|
this._element = element
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @const
|
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
Button['VERSION'] = '4.0.0'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @const
|
|
|
|
|
* @type {string}
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
Button._NAME = 'button'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @const
|
|
|
|
|
* @type {string}
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
Button._DATA_KEY = 'bs.button'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @const
|
|
|
|
|
* @type {Function}
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
Button._JQUERY_NO_CONFLICT = $.fn[Button._NAME]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @const
|
|
|
|
|
* @enum {string}
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
Button._ClassName = {
|
|
|
|
|
ACTIVE : 'active',
|
|
|
|
|
BUTTON : 'btn',
|
|
|
|
|
FOCUS : 'focus'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @const
|
|
|
|
|
* @enum {string}
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
Button._Selector = {
|
|
|
|
|
DATA_TOGGLE_CARROT : '[data-toggle^="button"]',
|
|
|
|
|
DATA_TOGGLE : '[data-toggle="buttons"]',
|
|
|
|
|
INPUT : 'input',
|
|
|
|
|
ACTIVE : '.active',
|
|
|
|
|
BUTTON : '.btn'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provides the jQuery Interface for the Button component.
|
|
|
|
|
* @param {string=} opt_config
|
|
|
|
|
* @this {jQuery}
|
|
|
|
|
* @return {jQuery}
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
Button._jQueryInterface = function (opt_config) {
|
|
|
|
|
return this.each(function () {
|
|
|
|
|
var data = $(this).data(Button._DATA_KEY)
|
|
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
|
data = new Button(this)
|
|
|
|
|
$(this).data(Button._DATA_KEY, data)
|
|
|
|
|
}
|
2014-08-25 21:02:29 -04:00
|
|
|
|
|
2015-01-03 16:58:44 -05:00
|
|
|
|
if (opt_config === 'toggle') {
|
|
|
|
|
data[opt_config]()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Toggle's the button active state
|
|
|
|
|
*/
|
|
|
|
|
Button.prototype['toggle'] = function () {
|
|
|
|
|
var triggerChangeEvent = true
|
|
|
|
|
var rootElement = $(this._element).closest(Button._Selector.DATA_TOGGLE)[0]
|
|
|
|
|
|
|
|
|
|
if (rootElement) {
|
|
|
|
|
var input = $(this._element).find(Button._Selector.INPUT)[0]
|
|
|
|
|
if (input) {
|
|
|
|
|
if (input.type == 'radio') {
|
|
|
|
|
if (input.checked && $(this._element).hasClass(Button._ClassName.ACTIVE)) {
|
|
|
|
|
triggerChangeEvent = false
|
|
|
|
|
} else {
|
|
|
|
|
var activeElement = $(rootElement).find(Button._Selector.ACTIVE)[0]
|
|
|
|
|
if (activeElement) {
|
|
|
|
|
$(activeElement).removeClass(Button._ClassName.ACTIVE)
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-02 01:23:31 -04:00
|
|
|
|
}
|
2014-06-23 14:07:18 -04:00
|
|
|
|
|
2015-01-03 16:58:44 -05:00
|
|
|
|
if (triggerChangeEvent) {
|
|
|
|
|
input.checked = !$(this._element).hasClass(Button._ClassName.ACTIVE)
|
|
|
|
|
$(this._element).trigger('change')
|
2014-06-23 14:07:18 -04:00
|
|
|
|
}
|
2013-05-16 14:06:30 -04:00
|
|
|
|
}
|
2015-01-03 16:58:44 -05:00
|
|
|
|
} else {
|
|
|
|
|
this._element.setAttribute('aria-pressed', !$(this._element).hasClass(Button._ClassName.ACTIVE))
|
|
|
|
|
}
|
2011-11-24 17:43:26 -05:00
|
|
|
|
|
2015-01-03 16:58:44 -05:00
|
|
|
|
if (triggerChangeEvent) {
|
|
|
|
|
$(this._element).toggleClass(Button._ClassName.ACTIVE)
|
2014-06-23 14:07:18 -04:00
|
|
|
|
}
|
2015-01-03 16:58:44 -05:00
|
|
|
|
}
|
2011-11-20 21:19:50 -05:00
|
|
|
|
|
2011-11-24 21:55:44 -05:00
|
|
|
|
|
2015-01-03 16:58:44 -05:00
|
|
|
|
/**
|
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
|
* jQuery Interface + noConflict implementaiton
|
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
|
*/
|
2011-11-24 21:55:44 -05:00
|
|
|
|
|
2015-01-03 16:58:44 -05:00
|
|
|
|
/**
|
|
|
|
|
* @const
|
|
|
|
|
* @type {Function}
|
|
|
|
|
*/
|
|
|
|
|
$.fn[Button._NAME] = Button._jQueryInterface
|
2013-05-16 14:06:30 -04:00
|
|
|
|
|
|
|
|
|
|
2015-01-03 16:58:44 -05:00
|
|
|
|
/**
|
|
|
|
|
* @const
|
|
|
|
|
* @type {Function}
|
|
|
|
|
*/
|
|
|
|
|
$.fn[Button._NAME]['Constructor'] = Button
|
2011-11-20 21:19:50 -05:00
|
|
|
|
|
2014-04-22 01:03:33 -04:00
|
|
|
|
|
2015-01-03 16:58:44 -05:00
|
|
|
|
/**
|
|
|
|
|
* @const
|
|
|
|
|
* @type {Function}
|
|
|
|
|
*/
|
|
|
|
|
$.fn[Button._NAME]['noConflict'] = function () {
|
|
|
|
|
$.fn[Button._NAME] = Button._JQUERY_NO_CONFLICT
|
|
|
|
|
return this
|
|
|
|
|
}
|
2011-11-24 21:55:44 -05:00
|
|
|
|
|
|
|
|
|
|
2015-01-03 16:58:44 -05:00
|
|
|
|
/**
|
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
|
* Data Api implementation
|
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
|
*/
|
2012-12-07 17:06:01 -05:00
|
|
|
|
|
2015-01-03 16:58:44 -05:00
|
|
|
|
$(document)
|
|
|
|
|
.on('click.bs.button.data-api', Button._Selector.DATA_TOGGLE_CARROT, function (event) {
|
|
|
|
|
event.preventDefault()
|
2012-12-07 17:06:01 -05:00
|
|
|
|
|
2015-01-03 16:58:44 -05:00
|
|
|
|
var button = event.target
|
2012-12-07 17:06:01 -05:00
|
|
|
|
|
2015-01-03 16:58:44 -05:00
|
|
|
|
if (!$(button).hasClass(Button._ClassName.BUTTON)) {
|
|
|
|
|
button = $(button).closest(Button._Selector.BUTTON)
|
|
|
|
|
}
|
2011-11-20 21:19:50 -05:00
|
|
|
|
|
2015-01-03 16:58:44 -05:00
|
|
|
|
Button._jQueryInterface.call($(button), 'toggle')
|
|
|
|
|
})
|
|
|
|
|
.on('focus.bs.button.data-api blur.bs.button.data-api', Button._Selector.DATA_TOGGLE_CARROT, function (event) {
|
|
|
|
|
var button = $(event.target).closest(Button._Selector.BUTTON)[0]
|
|
|
|
|
$(button).toggleClass(Button._ClassName.FOCUS, /^focus(in)?$/.test(event.type))
|
|
|
|
|
})
|