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