From 14651035deda4d02a1ca02c6088c34f770f897f6 Mon Sep 17 00:00:00 2001 From: fat Date: Thu, 16 May 2013 11:06:30 -0700 Subject: a bunch javascript junk --- js/button.js | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 js/button.js (limited to 'js/button.js') diff --git a/js/button.js b/js/button.js new file mode 100644 index 000000000..f43bba18f --- /dev/null +++ b/js/button.js @@ -0,0 +1,105 @@ +/* ============================================================ + * Bootstrap: button.js v3.0.0 + * http://twitter.github.com/bootstrap/javascript.html#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. + * ============================================================ */ + + +!function ($) { "use strict"; + + // BUTTON PUBLIC CLASS DEFINITION + // ============================== + + var Button = function (element, options) { + this.$element = $(element) + this.options = $.extend({}, Button.DEFAULTS, options) + } + + Button.DEFAULTS = { + loadingText: 'loading...' + } + + Button.prototype.setState = function (state) { + var d = 'disabled' + var $el = this.$element + var val = $el.is('input') ? 'val' : 'html' + var data = $el.data() + + state = state + 'Text' + + if (!data.resetText) $el.data('resetText', $el[val]()) + + $el[val](data[state] || this.options[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) + } + + Button.prototype.toggle = function () { + var $parent = this.$element.closest('[data-toggle="buttons-radio"]') + + if ($parent) { + $parent.find('.active').removeClass('active') + } + + this.$element.toggleClass('active') + } + + + // BUTTON PLUGIN DEFINITION + // ======================== + + var old = $.fn.button + + $.fn.button = function (option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('button') + var options = typeof option == 'object' && option + + if (!data) $this.data('bs-button', (data = new Button(this, options))) + + if (option == 'toggle') data.toggle() + else if (option) data.setState(option) + }) + } + + $.fn.button.Constructor = Button + + + // BUTTON NO CONFLICT + // ================== + + $.fn.button.noConflict = function () { + $.fn.button = old + return this + } + + + // BUTTON DATA-API + // =============== + + $(document).on('click.bs-button.bs-data-api', '[data-toggle^=button]', function (e) { + var $btn = $(e.target) + if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') + $btn.button('toggle') + }) + +}(window.jQuery); -- cgit v1.2.3 From 140ef2320bbb96ad90b73a884d83198706affaf9 Mon Sep 17 00:00:00 2001 From: fat Date: Thu, 16 May 2013 20:19:51 -0700 Subject: change namespace back to dot notation and someother js shizzle --- js/button.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/button.js') diff --git a/js/button.js b/js/button.js index f43bba18f..1dbef5ccd 100644 --- a/js/button.js +++ b/js/button.js @@ -74,7 +74,7 @@ var data = $this.data('button') var options = typeof option == 'object' && option - if (!data) $this.data('bs-button', (data = new Button(this, options))) + if (!data) $this.data('bs.button', (data = new Button(this, options))) if (option == 'toggle') data.toggle() else if (option) data.setState(option) @@ -96,7 +96,7 @@ // BUTTON DATA-API // =============== - $(document).on('click.bs-button.bs-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') -- cgit v1.2.3 From ccfa989898bdfcd91aa8dd5ad1e2de2832bfda71 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 21 May 2013 19:30:33 -0700 Subject: upgrade jshint to 2.1.2 for anton <3 --- js/button.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/button.js') diff --git a/js/button.js b/js/button.js index 1dbef5ccd..c29647840 100644 --- a/js/button.js +++ b/js/button.js @@ -1,7 +1,7 @@ -/* ============================================================ +/* ======================================================================== * Bootstrap: button.js v3.0.0 * http://twitter.github.com/bootstrap/javascript.html#buttons - * ============================================================ + * ======================================================================== * Copyright 2013 Twitter, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,10 +15,10 @@ * 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"; ++function ($) { "use strict"; // BUTTON PUBLIC CLASS DEFINITION // ============================== -- cgit v1.2.3