From 7eb340ec589acd56ad960a020969822636c2bc54 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 27 Nov 2011 17:31:12 -0800 Subject: add code to reset data for collapsed element so that item can be intitialized with correct options --- js/bootstrap-button.js | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 js/bootstrap-button.js (limited to 'js/bootstrap-button.js') diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js new file mode 100644 index 000000000..1cafe4d68 --- /dev/null +++ b/js/bootstrap-button.js @@ -0,0 +1,96 @@ +/* ============================================================ + * bootstrap-buttons.js v2.0.0 + * http://twitter.github.com/bootstrap/javascript.html#buttons + * ============================================================ + * Copyright 2011 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. + * ============================================================ */ + +!function( $ ){ + + "use strict" + + /* BUTTON PUBLIC CLASS DEFINITION + * ============================== */ + + var Button = function (element, options) { + this.$element = $(element) + this.settings = $.extend({}, $.fn.button.defaults, options) + } + + Button.prototype = { + + setState: function (state) { + var d = 'disabled' + , $el = this.$element + , data = $el.data() + , val = $el.is('input') ? 'val' : 'html' + + state = state + 'Text' + data.resetText || $el.data('resetText', $el[val]()) + + $el[val](data[state] || this.settings[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) + } + + , toggle: function () { + var $parent = this.$element.parent('[data-toggle="buttons-radio"]') + + $parent && $parent + .find('.active') + .removeClass('active') + + this.$element.toggleClass('active') + } + + } + + + /* BUTTON PLUGIN DEFINITION + * ======================== */ + + $.fn.button = function ( option ) { + return this.each(function () { + var $this = $(this) + , data = $this.data('button') + , options = typeof option == 'object' && option + if (!data) $this.data('button', (data = new Button(this, options))) + if (option == 'toggle') data.toggle() + else if (option) data.setState(option) + }) + } + + $.fn.button.defaults = { + loadingText: 'loading...' + } + + $.fn.button.Button = Button + + + /* BUTTON DATA-API + * =============== */ + + $(function () { + $('body').delegate('[data-toggle^=button]', 'click.button.data-api', function (e) { + $(e.srcElement).button('toggle') + }) + }) + +}( window.jQuery || window.ender ) \ No newline at end of file -- cgit v1.2.3 From cee2f61898f4807311402fed747a93ee68a31f8f Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 30 Nov 2011 22:42:22 -0800 Subject: define constructor on prototypes --- js/bootstrap-button.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js/bootstrap-button.js') diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js index 1cafe4d68..4ed24d98b 100644 --- a/js/bootstrap-button.js +++ b/js/bootstrap-button.js @@ -31,7 +31,9 @@ Button.prototype = { - setState: function (state) { + constructor: Button + + , setState: function (state) { var d = 'disabled' , $el = this.$element , data = $el.data() -- cgit v1.2.3 From 1ef5fa7d6b4e50230c0c12919b0a06a9a2ac07f1 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 20 Dec 2011 18:02:47 -0800 Subject: giant refactor - all spec passing again... --- js/bootstrap-button.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'js/bootstrap-button.js') diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js index 4ed24d98b..508835a38 100644 --- a/js/bootstrap-button.js +++ b/js/bootstrap-button.js @@ -24,16 +24,16 @@ /* BUTTON PUBLIC CLASS DEFINITION * ============================== */ - var Button = function (element, options) { + var Button = function ( element, options ) { this.$element = $(element) - this.settings = $.extend({}, $.fn.button.defaults, options) + this.options = $.extend({}, $.fn.button.defaults, options) } Button.prototype = { constructor: Button - , setState: function (state) { + , setState: function ( state ) { var d = 'disabled' , $el = this.$element , data = $el.data() @@ -42,7 +42,7 @@ state = state + 'Text' data.resetText || $el.data('resetText', $el[val]()) - $el[val](data[state] || this.settings[state]) + $el[val](data[state] || this.options[state]) // push to event loop to allow forms to submit setTimeout(function () { @@ -90,9 +90,9 @@ * =============== */ $(function () { - $('body').delegate('[data-toggle^=button]', 'click.button.data-api', function (e) { + $('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) { $(e.srcElement).button('toggle') }) }) -}( window.jQuery || window.ender ) \ No newline at end of file +}( window.jQuery ) \ No newline at end of file -- cgit v1.2.3 From f72a94ae2879ebfc5206dd40d5db175e13113850 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 20 Dec 2011 23:28:48 -0800 Subject: update more readme changes - introduce target specificty convention to more plugins --- js/bootstrap-button.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-button.js') diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js index 508835a38..10a85835e 100644 --- a/js/bootstrap-button.js +++ b/js/bootstrap-button.js @@ -83,7 +83,7 @@ loadingText: 'loading...' } - $.fn.button.Button = Button + $.fn.button.Constructor = Button /* BUTTON DATA-API -- cgit v1.2.3 From f1cbd22b99c3fec54d18341c31cfb1c237db44f2 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 8 Jan 2012 11:23:51 -0800 Subject: fix buttons for firefox --- js/bootstrap-button.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-button.js') diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js index 10a85835e..cb0c45cdf 100644 --- a/js/bootstrap-button.js +++ b/js/bootstrap-button.js @@ -91,7 +91,7 @@ $(function () { $('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) { - $(e.srcElement).button('toggle') + $(e.target).button('toggle') }) }) -- cgit v1.2.3 From 16eccc43d9fa6317818b5d1621d0477150214488 Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Sat, 14 Jan 2012 23:28:48 -0800 Subject: dates updated to 2012 --- js/bootstrap-button.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-button.js') diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js index cb0c45cdf..046d25614 100644 --- a/js/bootstrap-button.js +++ b/js/bootstrap-button.js @@ -2,7 +2,7 @@ * bootstrap-buttons.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#buttons * ============================================================ - * Copyright 2011 Twitter, Inc. + * Copyright 2012 Twitter, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. -- cgit v1.2.3 From 84a8aa1beac447cbbe77983730f7590fc955b312 Mon Sep 17 00:00:00 2001 From: Jon Stevens Date: Tue, 24 Jan 2012 11:08:03 -0800 Subject: 2.0-wip: fix js heads --- js/bootstrap-button.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-button.js') diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js index 046d25614..2461ffec6 100644 --- a/js/bootstrap-button.js +++ b/js/bootstrap-button.js @@ -1,5 +1,5 @@ /* ============================================================ - * bootstrap-buttons.js v2.0.0 + * bootstrap-button.js v2.0.0 * http://twitter.github.com/bootstrap/javascript.html#buttons * ============================================================ * Copyright 2012 Twitter, Inc. -- cgit v1.2.3 From 5844aa550d5a2d22d527d80cfa42443914d28c1f Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Thu, 26 Jan 2012 15:00:59 -0800 Subject: consistent new lines at ends of files --- js/bootstrap-button.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/bootstrap-button.js') diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js index 2461ffec6..d85c82947 100644 --- a/js/bootstrap-button.js +++ b/js/bootstrap-button.js @@ -95,4 +95,4 @@ }) }) -}( window.jQuery ) \ No newline at end of file +}( window.jQuery ) -- cgit v1.2.3