From d7e3bf722d784b167b665e8bacb749f18ae0d0f4 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 4 Oct 2011 21:24:59 -0700 Subject: add selector option to alerts, update modal settings strategy --- js/bootstrap-alerts.js | 15 +++++++++++---- js/bootstrap-modal.js | 4 +--- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'js') diff --git a/js/bootstrap-alerts.js b/js/bootstrap-alerts.js index 266029cc4..a8d15e24e 100644 --- a/js/bootstrap-alerts.js +++ b/js/bootstrap-alerts.js @@ -51,9 +51,10 @@ /* ALERT CLASS DEFINITION * ====================== */ - var Alert = function ( content, selector ) { + var Alert = function ( content, options ) { + this.settings = $.extend({}, $.fn.alert.defaults, options) this.$element = $(content) - .delegate(selector || '.close', 'click', this.close) + .delegate(this.settings.selector, 'click', this.close) } Alert.prototype = { @@ -92,13 +93,19 @@ return $this.data('alert')[options]() } - $(this).data('alert', new Alert( this )) + $(this).data('alert', new Alert( this, options )) }) } + $.fn.alert.defaults = { + selector: '.close' + } + $(document).ready(function () { - new Alert($('body'), '.alert-message[data-alert] .close') + new Alert($('body'), { + selector: '.alert-message[data-alert] .close' + }) }) }( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index 76c495259..2cc910989 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -53,12 +53,10 @@ * ============================= */ var Modal = function ( content, options ) { - this.settings = $.extend({}, $.fn.modal.defaults) + this.settings = $.extend({}, $.fn.modal.defaults, options) this.$element = $(content) .delegate('.close', 'click.modal', $.proxy(this.hide, this)) - $.extend( this.settings, options ) - if ( this.settings.show ) { this.show() } -- cgit v1.2.3 From a2c263493a7b6ca1933778feada80bab38c78581 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 4 Oct 2011 22:11:44 -0700 Subject: add dropdown tab selection support --- js/bootstrap-tabs.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'js') diff --git a/js/bootstrap-tabs.js b/js/bootstrap-tabs.js index e8e2dc622..9ccf85436 100644 --- a/js/bootstrap-tabs.js +++ b/js/bootstrap-tabs.js @@ -21,24 +21,33 @@ !function( $ ){ function activate ( element, container ) { - container.find('> .active').removeClass('active') + container + .find('> .active') + .removeClass('active') + .find('> .dropdown-menu > .active') + .removeClass('active') + element.addClass('active') + + if ( element.parent('.dropdown-menu') ) { + element.closest('li.dropdown').addClass('active') + } } function tab( e ) { var $this = $(this) - , $ul = $this.closest('ul') + , $ul = $this.closest('ul:not(.dropdown-menu)') , href = $this.attr('href') , previous - if (/^#\w+/.test(href)) { + if ( /^#\w+/.test(href) ) { e.preventDefault() - if ($this.parent('li').hasClass('active')) { + if ( $this.parent('li').hasClass('active') ) { return } - previous = $ul.find('.active a')[0] + previous = $ul.find('.active a').last()[0] $href = $(href) activate($this.parent('li'), $ul) -- cgit v1.2.3 From 356227ef506a34f0f5b42076bd776474b3830e9c Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 4 Oct 2011 22:56:23 -0700 Subject: pass more args to placement function --- js/bootstrap-twipsy.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'js') diff --git a/js/bootstrap-twipsy.js b/js/bootstrap-twipsy.js index 0144c4815..97cf47f46 100644 --- a/js/bootstrap-twipsy.js +++ b/js/bootstrap-twipsy.js @@ -90,7 +90,8 @@ actualWidth = $tip[0].offsetWidth actualHeight = $tip[0].offsetHeight - placement = _.maybeCall(this.options.placement, this.$element[0]) + + placement = maybeCall(this.options.placement, this, [ $tip[0], this.$element[0] ]) switch (placement) { case 'below': @@ -193,15 +194,10 @@ /* TWIPSY PRIVATE METHODS * ====================== */ - var _ = { - - maybeCall: function ( thing, ctx ) { - return (typeof thing == 'function') ? (thing.call(ctx)) : thing - } - + function maybeCall ( thing, ctx, args ) { + return typeof thing == 'function' ? thing.apply(ctx, args) : thing } - /* TWIPSY PLUGIN DEFINITION * ======================== */ -- cgit v1.2.3 From e8b66a9626055957a378464e2b9204f156b34c17 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 29 Oct 2011 17:58:58 -0700 Subject: star work on bootstrap-buttons.js --- js/bootstrap-buttons.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 js/bootstrap-buttons.js (limited to 'js') diff --git a/js/bootstrap-buttons.js b/js/bootstrap-buttons.js new file mode 100644 index 000000000..fe6c9c599 --- /dev/null +++ b/js/bootstrap-buttons.js @@ -0,0 +1,50 @@ +/* ============================================================ + * bootstrap-dropdown.js v1.3.0 + * http://twitter.github.com/bootstrap/javascript.html#dropdown + * ============================================================ + * 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" + + function setState(el, state) { + var d = 'disabled' + , $el = $(el) + , data = $el.data() + + state = state + 'Text' + data.resetText || $el.data('resetText', $el.html()) + + $el.html( data[state] || $.fn.button.defaults[state] ) + + state == 'loadingText' ? + $el.addClass(d).attr(d, d) : + $el.removeClass(d).removeAttr(d) + } + + $.fn.button = function(state) { + var d = 'disabled' + return this.each(function () { + state && setState(this, state) + }) + } + + $.fn.button.defaults = { + loadingText: 'loading...' + } + +}( window.jQuery || window.ender ); \ No newline at end of file -- cgit v1.2.3 From ea50e8aeeed6616a61a7e44d28fe60ced327be0c Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 29 Oct 2011 18:49:35 -0700 Subject: add active class to css for buttons, write new spec for button, "use strict" --- js/bootstrap-alerts.js | 2 ++ js/bootstrap-buttons.js | 18 +++++++++++++--- js/bootstrap-dropdown.js | 2 ++ js/bootstrap-modal.js | 37 ++++++++++++++++++--------------- js/bootstrap-popover.js | 2 ++ js/bootstrap-scrollspy.js | 2 ++ js/bootstrap-tabs.js | 3 +++ js/bootstrap-twipsy.js | 2 ++ js/tests/index.html | 4 +++- js/tests/unit/bootstrap-buttons.js | 42 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 93 insertions(+), 21 deletions(-) create mode 100644 js/tests/unit/bootstrap-buttons.js (limited to 'js') diff --git a/js/bootstrap-alerts.js b/js/bootstrap-alerts.js index a8d15e24e..1c6f7f346 100644 --- a/js/bootstrap-alerts.js +++ b/js/bootstrap-alerts.js @@ -20,6 +20,8 @@ !function( $ ){ + "use strict" + /* CSS TRANSITION SUPPORT (https://gist.github.com/373874) * ======================================================= */ diff --git a/js/bootstrap-buttons.js b/js/bootstrap-buttons.js index fe6c9c599..1fcc5e505 100644 --- a/js/bootstrap-buttons.js +++ b/js/bootstrap-buttons.js @@ -36,10 +36,16 @@ $el.removeClass(d).removeAttr(d) } - $.fn.button = function(state) { - var d = 'disabled' + function toggle(el) { + $(el).toggleClass('active') + } + + $.fn.button = function(options) { return this.each(function () { - state && setState(this, state) + if (options == 'toggle') { + return toggle(this) + } + options && setState(this, options) }) } @@ -47,4 +53,10 @@ loadingText: 'loading...' } + $(function () { + $('body').delegate('.btn[data-toggle]', 'click', function () { + $(this).button('toggle') + }) + }) + }( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js index 68a3db5f2..789d4a207 100644 --- a/js/bootstrap-dropdown.js +++ b/js/bootstrap-dropdown.js @@ -20,6 +20,8 @@ !function( $ ){ + "use strict" + /* DROPDOWN PLUGIN DEFINITION * ========================== */ diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index 2cc910989..9c57f6ddf 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -20,6 +20,8 @@ !function( $ ){ + "use strict" + /* CSS TRANSITION SUPPORT (https://gist.github.com/373874) * ======================================================= */ @@ -115,17 +117,9 @@ .trigger('hide') .removeClass('in') - function removeElement () { - that.$element - .hide() - .trigger('hidden') - - backdrop.call(that) - } - $.support.transition && this.$element.hasClass('fade') ? - this.$element.one(transitionEnd, removeElement) : - removeElement() + this.$element.one(transitionEnd, $.proxy(hideModal, this)) : + hideModal.call(this) return this } @@ -136,6 +130,14 @@ /* MODAL PRIVATE METHODS * ===================== */ + function hideModal (that) { + this.$element + .hide() + .trigger('hidden') + + backdrop.call(this) + } + function backdrop ( callback ) { var that = this , animate = this.$element.hasClass('fade') ? 'fade' : '' @@ -162,19 +164,20 @@ } else if ( !this.isShown && this.$backdrop ) { this.$backdrop.removeClass('in') - function removeElement() { - that.$backdrop.remove() - that.$backdrop = null - } - $.support.transition && this.$element.hasClass('fade')? - this.$backdrop.one(transitionEnd, removeElement) : - removeElement() + this.$backdrop.one(transitionEnd, $.proxy(removeBackdrop, this)) : + removeBackdrop.call(this) + } else if ( callback ) { callback() } } + function removeBackdrop() { + this.$backdrop.remove() + this.$backdrop = null + } + function escape() { var that = this if ( this.isShown && this.settings.keyboard ) { diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index 1cf4b8917..a8a1d8e7b 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -20,6 +20,8 @@ !function( $ ) { + "use strict" + var Popover = function ( element, options ) { this.$element = $(element) this.options = options diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index 5226d9dfe..213de20d1 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -20,6 +20,8 @@ !function ( $ ) { + "use strict" + var $window = $(window) function ScrollSpy( topbar, selector ) { diff --git a/js/bootstrap-tabs.js b/js/bootstrap-tabs.js index 9ccf85436..ef7d4af15 100644 --- a/js/bootstrap-tabs.js +++ b/js/bootstrap-tabs.js @@ -20,6 +20,8 @@ !function( $ ){ + "use strict" + function activate ( element, container ) { container .find('> .active') @@ -39,6 +41,7 @@ , $ul = $this.closest('ul:not(.dropdown-menu)') , href = $this.attr('href') , previous + , $href if ( /^#\w+/.test(href) ) { e.preventDefault() diff --git a/js/bootstrap-twipsy.js b/js/bootstrap-twipsy.js index 97cf47f46..ad2938a1a 100644 --- a/js/bootstrap-twipsy.js +++ b/js/bootstrap-twipsy.js @@ -21,6 +21,8 @@ !function( $ ) { + "use strict" + /* CSS TRANSITION SUPPORT (https://gist.github.com/373874) * ======================================================= */ diff --git a/js/tests/index.html b/js/tests/index.html index 2ca94102a..355c3f0af 100644 --- a/js/tests/index.html +++ b/js/tests/index.html @@ -4,7 +4,7 @@ Bootstrap Plugin Test Suite - + @@ -17,6 +17,7 @@ + @@ -25,6 +26,7 @@ +
diff --git a/js/tests/unit/bootstrap-buttons.js b/js/tests/unit/bootstrap-buttons.js new file mode 100644 index 000000000..9784f5222 --- /dev/null +++ b/js/tests/unit/bootstrap-buttons.js @@ -0,0 +1,42 @@ +$(function () { + + module("bootstrap-buttons") + + test("should be defined on jquery object", function () { + ok($(document.body).button, 'tabs method is defined') + }) + + test("should return element", function () { + ok($(document.body).button()[0] == document.body, 'document.body returned') + }) + + test("should return set state to loading", function () { + var btn = $('') + equals(btn.html(), 'mdo', 'btn text equals mdo') + btn.button('loading') + equals(btn.html(), 'fat', 'btn text equals fat') + ok(btn.attr('disabled'), 'btn is disabled') + ok(btn.hasClass('disabled'), 'btn has disabled class') + }) + + test("should return reset state", function () { + var btn = $('') + equals(btn.html(), 'mdo', 'btn text equals mdo') + btn.button('loading') + equals(btn.html(), 'fat', 'btn text equals fat') + ok(btn.attr('disabled'), 'btn is disabled') + ok(btn.hasClass('disabled'), 'btn is disabled') + btn.button('reset') + equals(btn.html(), 'mdo', 'btn text equals mdo') + ok(!btn.attr('disabled'), 'btn is not disabled') + ok(!btn.hasClass('disabled'), 'btn does not have disabled class') + }) + + test("should toggle active", function () { + var btn = $('') + ok(!btn.hasClass('active'), 'btn does not have active class') + btn.button('toggle') + ok(btn.hasClass('active'), 'btn has class active') + }) + +}) \ No newline at end of file -- cgit v1.2.3 From 640fd15464306238de99a3391888a95156e27995 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 29 Oct 2011 19:27:02 -0700 Subject: allow the use of data attributes to define popover options --- js/bootstrap-popover.js | 4 ++-- js/bootstrap-twipsy.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'js') diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index a8a1d8e7b..e8f4ce096 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -47,7 +47,7 @@ , o = this.options if (typeof this.options.content == 'string') { - content = $e.attr(o.content) + content = this.options.content } else if (typeof this.options.content == 'function') { content = this.options.content.call(this.$element[0]) } @@ -74,6 +74,6 @@ return this } - $.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, { content: 'data-content', placement: 'right'}) + $.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, { placement: 'right'}) }( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/bootstrap-twipsy.js b/js/bootstrap-twipsy.js index ad2938a1a..f0e5b1b90 100644 --- a/js/bootstrap-twipsy.js +++ b/js/bootstrap-twipsy.js @@ -299,7 +299,7 @@ } $.fn.twipsy.elementOptions = function(ele, options) { - return $.metadata ? $.extend({}, options, $(ele).metadata()) : options + return $.extend({}, options, $(ele).data()) } }( window.jQuery || window.ender ); \ No newline at end of file -- cgit v1.2.3 From 169b4b5dcbca740951735a60cc5c46a1366c2652 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 29 Oct 2011 19:59:51 -0700 Subject: add template option and make title an optional attribute for popover --- js/bootstrap-popover.js | 11 +++++++++-- js/bootstrap-twipsy.js | 9 +++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index e8f4ce096..95ca39ab7 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -41,6 +41,10 @@ $tip[0].className = 'popover' } + , hasContent: function () { + return this.getTitle() || this.getContent() + } + , getContent: function () { var content , $e = this.$element @@ -57,7 +61,7 @@ , tip: function() { if (!this.$tip) { this.$tip = $('
') - .html('

') + .html(this.options.template) } return this.$tip } @@ -74,6 +78,9 @@ return this } - $.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, { placement: 'right'}) + $.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, { + placement: 'right' + , template: '

' + }) }( window.jQuery || window.ender ); \ No newline at end of file diff --git a/js/bootstrap-twipsy.js b/js/bootstrap-twipsy.js index f0e5b1b90..6066ab06a 100644 --- a/js/bootstrap-twipsy.js +++ b/js/bootstrap-twipsy.js @@ -72,7 +72,7 @@ , $tip , tp - if (this.getTitle() && this.enabled) { + if (this.hasContent() && this.enabled) { $tip = this.tip() this.setContent() @@ -145,6 +145,10 @@ } } + , hasContent: function () { + return this.getTitle() + } + , getTitle: function() { var title , $e = this.$element @@ -165,7 +169,7 @@ , tip: function() { if (!this.$tip) { - this.$tip = $('
').html('
') + this.$tip = $('
').html(this.options.template) } return this.$tip } @@ -296,6 +300,7 @@ , offset: 0 , title: 'title' , trigger: 'hover' + , template: '
' } $.fn.twipsy.elementOptions = function(ele, options) { -- cgit v1.2.3 From 8f726dc6ef3ee725ef032ef4a11dbce26982ae24 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Mon, 31 Oct 2011 22:44:42 -0700 Subject: issue #240 - firefox drop css transition events :{o --- js/bootstrap-modal.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'js') diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index 9c57f6ddf..72b78d632 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -89,8 +89,7 @@ that.$element[0].offsetWidth // force reflow } - that.$element - .addClass('in') + that.$element.addClass('in') transition ? that.$element.one(transitionEnd, function () { that.$element.trigger('shown') }) : @@ -118,7 +117,7 @@ .removeClass('in') $.support.transition && this.$element.hasClass('fade') ? - this.$element.one(transitionEnd, $.proxy(hideModal, this)) : + hideWithTransition.call(this) : hideModal.call(this) return this @@ -130,6 +129,20 @@ /* MODAL PRIVATE METHODS * ===================== */ + function hideWithTransition() { + // firefox drops transitionEnd events :{o + var that = this + , timeout = setTimeout(function () { + that.$element.unbind(transitionEnd) + hideModal.call(that) + }, 500) + + this.$element.one(transitionEnd, function () { + clearTimeout(timeout) + hideModal.call(that) + }) + } + function hideModal (that) { this.$element .hide() -- cgit v1.2.3