indvd00m@0: /* ============================================================ indvd00m@0: * bootstrap-button.js v2.3.1 indvd00m@0: * http://twitter.github.com/bootstrap/javascript.html#buttons indvd00m@0: * ============================================================ indvd00m@0: * Copyright 2012 Twitter, Inc. indvd00m@0: * indvd00m@0: * Licensed under the Apache License, Version 2.0 (the "License"); indvd00m@0: * you may not use this file except in compliance with the License. indvd00m@0: * You may obtain a copy of the License at indvd00m@0: * indvd00m@0: * http://www.apache.org/licenses/LICENSE-2.0 indvd00m@0: * indvd00m@0: * Unless required by applicable law or agreed to in writing, software indvd00m@0: * distributed under the License is distributed on an "AS IS" BASIS, indvd00m@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. indvd00m@0: * See the License for the specific language governing permissions and indvd00m@0: * limitations under the License. indvd00m@0: * ============================================================ */ indvd00m@0: indvd00m@0: indvd00m@0: !function ($) { indvd00m@0: indvd00m@0: "use strict"; // jshint ;_; indvd00m@0: indvd00m@0: indvd00m@0: /* BUTTON PUBLIC CLASS DEFINITION indvd00m@0: * ============================== */ indvd00m@0: indvd00m@0: var Button = function (element, options) { indvd00m@0: this.$element = $(element) indvd00m@0: this.options = $.extend({}, $.fn.button.defaults, options) indvd00m@0: } indvd00m@0: indvd00m@0: Button.prototype.setState = function (state) { indvd00m@0: var d = 'disabled' indvd00m@0: , $el = this.$element indvd00m@0: , data = $el.data() indvd00m@0: , val = $el.is('input') ? 'val' : 'html' indvd00m@0: indvd00m@0: state = state + 'Text' indvd00m@0: data.resetText || $el.data('resetText', $el[val]()) indvd00m@0: indvd00m@0: $el[val](data[state] || this.options[state]) indvd00m@0: indvd00m@0: // push to event loop to allow forms to submit indvd00m@0: setTimeout(function () { indvd00m@0: state == 'loadingText' ? indvd00m@0: $el.addClass(d).attr(d, d) : indvd00m@0: $el.removeClass(d).removeAttr(d) indvd00m@0: }, 0) indvd00m@0: } indvd00m@0: indvd00m@0: Button.prototype.toggle = function () { indvd00m@0: var $parent = this.$element.closest('[data-toggle="buttons-radio"]') indvd00m@0: indvd00m@0: $parent && $parent indvd00m@0: .find('.active') indvd00m@0: .removeClass('active') indvd00m@0: indvd00m@0: this.$element.toggleClass('active') indvd00m@0: } indvd00m@0: indvd00m@0: indvd00m@0: /* BUTTON PLUGIN DEFINITION indvd00m@0: * ======================== */ indvd00m@0: indvd00m@0: var old = $.fn.button indvd00m@0: indvd00m@0: $.fn.button = function (option) { indvd00m@0: return this.each(function () { indvd00m@0: var $this = $(this) indvd00m@0: , data = $this.data('button') indvd00m@0: , options = typeof option == 'object' && option indvd00m@0: if (!data) $this.data('button', (data = new Button(this, options))) indvd00m@0: if (option == 'toggle') data.toggle() indvd00m@0: else if (option) data.setState(option) indvd00m@0: }) indvd00m@0: } indvd00m@0: indvd00m@0: $.fn.button.defaults = { indvd00m@0: loadingText: 'loading...' indvd00m@0: } indvd00m@0: indvd00m@0: $.fn.button.Constructor = Button indvd00m@0: indvd00m@0: indvd00m@0: /* BUTTON NO CONFLICT indvd00m@0: * ================== */ indvd00m@0: indvd00m@0: $.fn.button.noConflict = function () { indvd00m@0: $.fn.button = old indvd00m@0: return this indvd00m@0: } indvd00m@0: indvd00m@0: indvd00m@0: /* BUTTON DATA-API indvd00m@0: * =============== */ indvd00m@0: indvd00m@0: $(document).on('click.button.data-api', '[data-toggle^=button]', function (e) { indvd00m@0: var $btn = $(e.target) indvd00m@0: if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') indvd00m@0: $btn.button('toggle') indvd00m@0: }) indvd00m@0: indvd00m@0: }(window.jQuery);