1 /* ============================================================
2 * bootstrap-button.js v2.3.2
3 * http://getbootstrap.com/2.3.2/javascript.html#buttons
4 * ============================================================
5 * Copyright 2013 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.closest('[data-toggle="buttons-radio"]')
58 .removeClass('active')
60 this.$element.toggleClass('active')
64 /* BUTTON PLUGIN DEFINITION
65 * ======================== */
69 $.fn.button = function (option) {
70 return this.each(function () {
72 , data = $this.data('button')
73 , options = typeof option == 'object' && option
74 if (!data) $this.data('button', (data = new Button(this, options)))
75 if (option == 'toggle') data.toggle()
76 else if (option) data.setState(option)
80 $.fn.button.defaults = {
81 loadingText: 'loading...'
84 $.fn.button.Constructor = Button
88 * ================== */
90 $.fn.button.noConflict = function () {
99 $(document).on('click.button.data-api', '[data-toggle^=button]', function (e) {
100 var $btn = $(e.target)
101 if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
102 $btn.button('toggle')