2013-05-21 19:30:33 -07:00
|
|
|
/* ========================================================================
|
2014-02-13 01:12:26 -08:00
|
|
|
* Bootstrap: button.js v3.1.1
|
2013-10-29 12:10:47 -05:00
|
|
|
* http://getbootstrap.com/javascript/#buttons
|
2013-05-21 19:30:33 -07:00
|
|
|
* ========================================================================
|
2014-01-07 01:05:24 +01:00
|
|
|
* Copyright 2011-2014 Twitter, Inc.
|
2013-12-18 15:28:08 -08:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
2013-05-21 19:30:33 -07:00
|
|
|
* ======================================================================== */
|
2011-11-20 18:19:50 -08:00
|
|
|
|
2012-03-24 18:59:04 -07:00
|
|
|
|
2014-01-01 15:42:41 +01:00
|
|
|
+function ($) {
|
|
|
|
'use strict';
|
2012-04-14 16:29:53 -07:00
|
|
|
|
2013-05-16 11:06:30 -07:00
|
|
|
// BUTTON PUBLIC CLASS DEFINITION
|
|
|
|
// ==============================
|
2011-11-24 18:55:44 -08:00
|
|
|
|
2012-04-14 16:29:53 -07:00
|
|
|
var Button = function (element, options) {
|
2013-12-26 19:40:18 -08:00
|
|
|
this.$element = $(element)
|
|
|
|
this.options = $.extend({}, Button.DEFAULTS, options)
|
|
|
|
this.isLoading = false
|
2013-05-16 11:06:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Button.DEFAULTS = {
|
|
|
|
loadingText: 'loading...'
|
2011-11-24 19:40:25 -08:00
|
|
|
}
|
2011-11-24 18:55:44 -08:00
|
|
|
|
2012-04-14 16:29:53 -07:00
|
|
|
Button.prototype.setState = function (state) {
|
2013-05-16 11:06:30 -07:00
|
|
|
var d = 'disabled'
|
|
|
|
var $el = this.$element
|
|
|
|
var val = $el.is('input') ? 'val' : 'html'
|
|
|
|
var data = $el.data()
|
2011-11-20 18:19:50 -08:00
|
|
|
|
2012-04-14 16:29:53 -07:00
|
|
|
state = state + 'Text'
|
2013-05-16 11:06:30 -07:00
|
|
|
|
|
|
|
if (!data.resetText) $el.data('resetText', $el[val]())
|
2011-11-20 18:19:50 -08:00
|
|
|
|
2012-04-14 16:29:53 -07:00
|
|
|
$el[val](data[state] || this.options[state])
|
2011-11-24 19:40:25 -08:00
|
|
|
|
2012-04-14 16:29:53 -07:00
|
|
|
// push to event loop to allow forms to submit
|
2013-12-26 19:40:18 -08:00
|
|
|
setTimeout($.proxy(function () {
|
|
|
|
if (state == 'loadingText') {
|
|
|
|
this.isLoading = true
|
|
|
|
$el.addClass(d).attr(d, d)
|
|
|
|
} else if (this.isLoading) {
|
|
|
|
this.isLoading = false
|
|
|
|
$el.removeClass(d).removeAttr(d)
|
|
|
|
}
|
|
|
|
}, this), 0)
|
2012-04-14 16:29:53 -07:00
|
|
|
}
|
2011-11-20 18:19:50 -08:00
|
|
|
|
2012-04-14 16:29:53 -07:00
|
|
|
Button.prototype.toggle = function () {
|
2013-09-01 22:23:31 -07:00
|
|
|
var changed = true
|
2013-12-26 19:40:18 -08:00
|
|
|
var $parent = this.$element.closest('[data-toggle="buttons"]')
|
2011-11-24 14:43:26 -08:00
|
|
|
|
2013-07-18 00:59:31 -07:00
|
|
|
if ($parent.length) {
|
2013-08-02 15:13:12 -07:00
|
|
|
var $input = this.$element.find('input')
|
2013-12-26 19:40:18 -08:00
|
|
|
if ($input.prop('type') == 'radio') {
|
|
|
|
if ($input.prop('checked') && this.$element.hasClass('active')) changed = false
|
|
|
|
else $parent.find('.active').removeClass('active')
|
2013-09-01 22:23:31 -07:00
|
|
|
}
|
|
|
|
if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change')
|
2013-05-16 11:06:30 -07:00
|
|
|
}
|
2011-11-24 14:43:26 -08:00
|
|
|
|
2013-09-01 22:23:31 -07:00
|
|
|
if (changed) this.$element.toggleClass('active')
|
2011-11-20 18:19:50 -08:00
|
|
|
}
|
|
|
|
|
2011-11-24 18:55:44 -08:00
|
|
|
|
2013-05-16 11:06:30 -07:00
|
|
|
// BUTTON PLUGIN DEFINITION
|
|
|
|
// ========================
|
2011-11-24 18:55:44 -08:00
|
|
|
|
2012-12-07 17:06:01 -05:00
|
|
|
var old = $.fn.button
|
|
|
|
|
2012-04-14 16:29:53 -07:00
|
|
|
$.fn.button = function (option) {
|
2011-11-20 18:19:50 -08:00
|
|
|
return this.each(function () {
|
2013-05-16 11:06:30 -07:00
|
|
|
var $this = $(this)
|
2013-07-30 13:31:57 -07:00
|
|
|
var data = $this.data('bs.button')
|
2013-05-16 11:06:30 -07:00
|
|
|
var options = typeof option == 'object' && option
|
|
|
|
|
2013-05-16 20:19:51 -07:00
|
|
|
if (!data) $this.data('bs.button', (data = new Button(this, options)))
|
2013-05-16 11:06:30 -07:00
|
|
|
|
2011-11-24 19:40:25 -08:00
|
|
|
if (option == 'toggle') data.toggle()
|
|
|
|
else if (option) data.setState(option)
|
2011-11-20 18:19:50 -08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2011-12-20 23:28:48 -08:00
|
|
|
$.fn.button.Constructor = Button
|
2011-11-24 18:55:44 -08:00
|
|
|
|
|
|
|
|
2013-05-16 11:06:30 -07:00
|
|
|
// BUTTON NO CONFLICT
|
|
|
|
// ==================
|
2012-12-07 17:06:01 -05:00
|
|
|
|
|
|
|
$.fn.button.noConflict = function () {
|
|
|
|
$.fn.button = old
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-16 11:06:30 -07:00
|
|
|
// BUTTON DATA-API
|
|
|
|
// ===============
|
2011-11-24 18:55:44 -08:00
|
|
|
|
2013-05-16 20:19:51 -07:00
|
|
|
$(document).on('click.bs.button.data-api', '[data-toggle^=button]', function (e) {
|
2012-09-27 15:00:02 -07:00
|
|
|
var $btn = $(e.target)
|
|
|
|
if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
|
|
|
|
$btn.button('toggle')
|
2013-07-18 01:07:11 -07:00
|
|
|
e.preventDefault()
|
2011-11-20 18:19:50 -08:00
|
|
|
})
|
|
|
|
|
2013-08-22 14:50:15 -04:00
|
|
|
}(jQuery);
|