2013-05-21 22:30:33 -04:00
|
|
|
/* ========================================================================
|
2015-01-19 11:32:13 -05:00
|
|
|
* Bootstrap: button.js v3.3.2
|
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)
|
2013-05-21 22:30:33 -04:00
|
|
|
* ======================================================================== */
|
2011-11-20 21:19:50 -05:00
|
|
|
|
2012-03-24 21:59:04 -04:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
+function ($) {
|
|
|
|
'use strict';
|
2014-06-10 01:18:05 -04:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
// BUTTON PUBLIC CLASS DEFINITION
|
|
|
|
// ==============================
|
2012-04-14 19:29:53 -04:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
var Button = function (element, options) {
|
|
|
|
this.$element = $(element)
|
|
|
|
this.options = $.extend({}, Button.DEFAULTS, options)
|
|
|
|
this.isLoading = false
|
|
|
|
}
|
2011-11-24 21:55:44 -05:00
|
|
|
|
2015-01-19 11:32:13 -05:00
|
|
|
Button.VERSION = '3.3.2'
|
2011-11-24 21:55:44 -05:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
Button.DEFAULTS = {
|
|
|
|
loadingText: 'loading...'
|
|
|
|
}
|
2011-11-20 21:19:50 -05:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
Button.prototype.setState = function (state) {
|
|
|
|
var d = 'disabled'
|
|
|
|
var $el = this.$element
|
|
|
|
var val = $el.is('input') ? 'val' : 'html'
|
|
|
|
var data = $el.data()
|
2013-05-16 14:06:30 -04:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
state = state + 'Text'
|
2011-11-20 21:19:50 -05:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
if (data.resetText == null) $el.data('resetText', $el[val]())
|
2011-11-24 22:40:25 -05:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
// push to event loop to allow forms to submit
|
|
|
|
setTimeout($.proxy(function () {
|
2014-08-25 21:02:29 -04:00
|
|
|
$el[val](data[state] == null ? this.options[state] : data[state])
|
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
if (state == 'loadingText') {
|
|
|
|
this.isLoading = true
|
|
|
|
$el.addClass(d).attr(d, d)
|
|
|
|
} else if (this.isLoading) {
|
|
|
|
this.isLoading = false
|
|
|
|
$el.removeClass(d).removeAttr(d)
|
2013-09-02 01:23:31 -04:00
|
|
|
}
|
2014-06-23 14:07:18 -04:00
|
|
|
}, this), 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
Button.prototype.toggle = function () {
|
|
|
|
var changed = true
|
|
|
|
var $parent = this.$element.closest('[data-toggle="buttons"]')
|
|
|
|
|
|
|
|
if ($parent.length) {
|
|
|
|
var $input = this.$element.find('input')
|
|
|
|
if ($input.prop('type') == 'radio') {
|
|
|
|
if ($input.prop('checked') && this.$element.hasClass('active')) changed = false
|
|
|
|
else $parent.find('.active').removeClass('active')
|
|
|
|
}
|
|
|
|
if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change')
|
2014-10-17 10:17:57 -04:00
|
|
|
} else {
|
|
|
|
this.$element.attr('aria-pressed', !this.$element.hasClass('active'))
|
2013-05-16 14:06:30 -04:00
|
|
|
}
|
2011-11-24 17:43:26 -05:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
if (changed) this.$element.toggleClass('active')
|
|
|
|
}
|
2011-11-20 21:19:50 -05:00
|
|
|
|
2011-11-24 21:55:44 -05:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
// BUTTON PLUGIN DEFINITION
|
|
|
|
// ========================
|
2011-11-24 21:55:44 -05:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
function Plugin(option) {
|
|
|
|
return this.each(function () {
|
|
|
|
var $this = $(this)
|
|
|
|
var data = $this.data('bs.button')
|
|
|
|
var options = typeof option == 'object' && option
|
2013-05-16 14:06:30 -04:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
if (!data) $this.data('bs.button', (data = new Button(this, options)))
|
2013-05-16 14:06:30 -04:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
if (option == 'toggle') data.toggle()
|
|
|
|
else if (option) data.setState(option)
|
|
|
|
})
|
|
|
|
}
|
2011-11-20 21:19:50 -05:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
var old = $.fn.button
|
2014-04-22 01:03:33 -04:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
$.fn.button = Plugin
|
|
|
|
$.fn.button.Constructor = Button
|
2011-11-24 21:55:44 -05:00
|
|
|
|
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
// BUTTON NO CONFLICT
|
|
|
|
// ==================
|
2012-12-07 17:06:01 -05:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
$.fn.button.noConflict = function () {
|
|
|
|
$.fn.button = old
|
|
|
|
return this
|
|
|
|
}
|
2012-12-07 17:06:01 -05:00
|
|
|
|
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
// BUTTON DATA-API
|
|
|
|
// ===============
|
2011-11-24 21:55:44 -05:00
|
|
|
|
2014-06-24 02:32:52 -04:00
|
|
|
$(document)
|
|
|
|
.on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
|
|
|
|
var $btn = $(e.target)
|
|
|
|
if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
|
|
|
|
Plugin.call($btn, 'toggle')
|
|
|
|
e.preventDefault()
|
|
|
|
})
|
2014-07-16 02:44:56 -04:00
|
|
|
.on('focus.bs.button.data-api blur.bs.button.data-api', '[data-toggle^="button"]', function (e) {
|
2014-10-29 22:46:49 -04:00
|
|
|
$(e.target).closest('.btn').toggleClass('focus', /^focus(in)?$/.test(e.type))
|
2014-06-24 02:32:52 -04:00
|
|
|
})
|
2011-11-20 21:19:50 -05:00
|
|
|
|
2014-06-23 14:07:18 -04:00
|
|
|
}(jQuery);
|