1 /* ============================================================
2 * bootstrap-button.js v2.0.4
3 * http://twitter.github.com/bootstrap/javascript.html#buttons
4 * ============================================================
5 * Copyright 2012 Twitter, Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============================================================ */
23 "use strict"; // jshint ;_;
26 /* BUTTON PUBLIC CLASS DEFINITION
27 * ============================== */
29 var Button = function (element, options) {
30 this.$element = $(element)
31 this.options = $.extend({}, $.fn.button.defaults, options)
34 Button.prototype.setState = function (state) {
38 , val = $el.is('input') ? 'val' : 'html'
40 state = state + 'Text'
41 data.resetText || $el.data('resetText', $el[val]())
43 $el[val](data[state] || this.options[state])
45 // push to event loop to allow forms to submit
46 setTimeout(function () {
47 state == 'loadingText' ?
48 $el.addClass(d).attr(d, d) :
49 $el.removeClass(d).removeAttr(d)
53 Button.prototype.toggle = function () {
54 var $parent = this.$element.parent('[data-toggle="buttons-radio"]')
58 .removeClass('active')
60 this.$element.toggleClass('active')
64 /* BUTTON PLUGIN DEFINITION
65 * ======================== */
67 $.fn.button = function (option) {
68 return this.each(function () {
70 , data = $this.data('button')
71 , options = typeof option == 'object' && option
72 if (!data) $this.data('button', (data = new Button(this, options)))
73 if (option == 'toggle') data.toggle()
74 else if (option) data.setState(option)
78 $.fn.button.defaults = {
79 loadingText: 'loading...'
82 $.fn.button.Constructor = Button
89 $('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) {
90 var $btn = $(e.target)
91 if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')