app/assets/javascripts/bootstrap/button.js in bootstrap-on-rails-0.0.2 vs app/assets/javascripts/bootstrap/button.js in bootstrap-on-rails-3.2.0
- old
+ new
@@ -1,35 +1,28 @@
/* ========================================================================
- * Bootstrap: button.js v3.0.2
+ * Bootstrap: button.js v3.2.0
* http://getbootstrap.com/javascript/#buttons
* ========================================================================
- * Copyright 2013 Twitter, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Copyright 2011-2014 Twitter, Inc.
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* ======================================================================== */
-+function ($) { "use strict";
++function ($) {
+ 'use strict';
// BUTTON PUBLIC CLASS DEFINITION
// ==============================
var Button = function (element, options) {
- this.$element = $(element)
- this.options = $.extend({}, Button.DEFAULTS, options)
+ this.$element = $(element)
+ this.options = $.extend({}, Button.DEFAULTS, options)
+ this.isLoading = false
}
+ Button.VERSION = '3.2.0'
+
Button.DEFAULTS = {
loadingText: 'loading...'
}
Button.prototype.setState = function (state) {
@@ -38,42 +31,47 @@
var val = $el.is('input') ? 'val' : 'html'
var data = $el.data()
state = state + 'Text'
- if (!data.resetText) $el.data('resetText', $el[val]())
+ if (data.resetText == null) $el.data('resetText', $el[val]())
- $el[val](data[state] || this.options[state])
+ $el[val](data[state] == null ? this.options[state] : data[state])
// push to event loop to allow forms to submit
- setTimeout(function () {
- state == 'loadingText' ?
- $el.addClass(d).attr(d, d) :
- $el.removeClass(d).removeAttr(d);
- }, 0)
+ setTimeout($.proxy(function () {
+ if (state == 'loadingText') {
+ this.isLoading = true
+ $el.addClass(d).attr(d, d)
+ } else if (this.isLoading) {
+ this.isLoading = false
+ $el.removeClass(d).removeAttr(d)
+ }
+ }, 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')
- .prop('checked', !this.$element.hasClass('active'))
- .trigger('change')
- if ($input.prop('type') === 'radio') $parent.find('.active').removeClass('active')
+ 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')
}
- this.$element.toggleClass('active')
+ if (changed) this.$element.toggleClass('active')
}
// BUTTON PLUGIN DEFINITION
// ========================
- var old = $.fn.button
-
- $.fn.button = function (option) {
+ function Plugin(option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.button')
var options = typeof option == 'object' && option
@@ -82,10 +80,13 @@
if (option == 'toggle') data.toggle()
else if (option) data.setState(option)
})
}
+ var old = $.fn.button
+
+ $.fn.button = Plugin
$.fn.button.Constructor = Button
// BUTTON NO CONFLICT
// ==================
@@ -97,13 +98,13 @@
// BUTTON DATA-API
// ===============
- $(document).on('click.bs.button.data-api', '[data-toggle^=button]', function (e) {
+ $(document).on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
var $btn = $(e.target)
if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
- $btn.button('toggle')
+ Plugin.call($btn, 'toggle')
e.preventDefault()
})
}(jQuery);