diff options
| author | Mark Otto <[email protected]> | 2011-10-31 23:22:13 -0700 |
|---|---|---|
| committer | Mark Otto <[email protected]> | 2011-10-31 23:22:13 -0700 |
| commit | a21363a749f7d30a282e24cefd83840a5a3fca7c (patch) | |
| tree | c3dc61772359fdcbb75418bd105a61e3e5579f70 /js | |
| parent | 98007b8394a5cf892694000d066a07a32f8c517f (diff) | |
| parent | 8f726dc6ef3ee725ef032ef4a11dbce26982ae24 (diff) | |
| download | bootstrap-a21363a749f7d30a282e24cefd83840a5a3fca7c.tar.xz bootstrap-a21363a749f7d30a282e24cefd83840a5a3fca7c.zip | |
Merge branch 'dev' of github.com:twitter/bootstrap into dev
Conflicts:
bootstrap.css
Diffstat (limited to 'js')
| -rw-r--r-- | js/bootstrap-alerts.js | 17 | ||||
| -rw-r--r-- | js/bootstrap-buttons.js | 62 | ||||
| -rw-r--r-- | js/bootstrap-dropdown.js | 2 | ||||
| -rw-r--r-- | js/bootstrap-modal.js | 58 | ||||
| -rw-r--r-- | js/bootstrap-popover.js | 15 | ||||
| -rw-r--r-- | js/bootstrap-scrollspy.js | 2 | ||||
| -rw-r--r-- | js/bootstrap-tabs.js | 22 | ||||
| -rw-r--r-- | js/bootstrap-twipsy.js | 25 | ||||
| -rw-r--r-- | js/tests/index.html | 4 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-buttons.js | 42 |
10 files changed, 203 insertions, 46 deletions
diff --git a/js/bootstrap-alerts.js b/js/bootstrap-alerts.js index 266029cc4..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) * ======================================================= */ @@ -51,9 +53,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 +95,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-buttons.js b/js/bootstrap-buttons.js new file mode 100644 index 000000000..1fcc5e505 --- /dev/null +++ b/js/bootstrap-buttons.js @@ -0,0 +1,62 @@ +/* ============================================================ + * 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) + } + + function toggle(el) { + $(el).toggleClass('active') + } + + $.fn.button = function(options) { + return this.each(function () { + if (options == 'toggle') { + return toggle(this) + } + options && setState(this, options) + }) + } + + $.fn.button.defaults = { + 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 76c495259..72b78d632 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) * ======================================================= */ @@ -53,12 +55,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() } @@ -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') }) : @@ -117,17 +116,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() + hideWithTransition.call(this) : + hideModal.call(this) return this } @@ -138,6 +129,28 @@ /* 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() + .trigger('hidden') + + backdrop.call(this) + } + function backdrop ( callback ) { var that = this , animate = this.$element.hasClass('fade') ? 'fade' : '' @@ -164,19 +177,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..95ca39ab7 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 @@ -39,13 +41,17 @@ $tip[0].className = 'popover' } + , hasContent: function () { + return this.getTitle() || this.getContent() + } + , getContent: function () { var content , $e = this.$element , 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]) } @@ -55,7 +61,7 @@ , tip: function() { if (!this.$tip) { this.$tip = $('<div class="popover" />') - .html('<div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div>') + .html(this.options.template) } return this.$tip } @@ -72,6 +78,9 @@ return this } - $.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, { content: 'data-content', placement: 'right'}) + $.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, { + placement: 'right' + , template: '<div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div>' + }) }( window.jQuery || window.ender );
\ No newline at end of file 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 e8e2dc622..ef7d4af15 100644 --- a/js/bootstrap-tabs.js +++ b/js/bootstrap-tabs.js @@ -20,25 +20,37 @@ !function( $ ){ + "use strict" + 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 + , $href - 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) diff --git a/js/bootstrap-twipsy.js b/js/bootstrap-twipsy.js index 0144c4815..6066ab06a 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) * ======================================================= */ @@ -70,7 +72,7 @@ , $tip , tp - if (this.getTitle() && this.enabled) { + if (this.hasContent() && this.enabled) { $tip = this.tip() this.setContent() @@ -90,7 +92,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': @@ -142,6 +145,10 @@ } } + , hasContent: function () { + return this.getTitle() + } + , getTitle: function() { var title , $e = this.$element @@ -162,7 +169,7 @@ , tip: function() { if (!this.$tip) { - this.$tip = $('<div class="twipsy" />').html('<div class="twipsy-arrow"></div><div class="twipsy-inner"></div>') + this.$tip = $('<div class="twipsy" />').html(this.options.template) } return this.$tip } @@ -193,15 +200,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 * ======================== */ @@ -298,10 +300,11 @@ , offset: 0 , title: 'title' , trigger: 'hover' + , template: '<div class="twipsy-arrow"></div><div class="twipsy-inner"></div>' } $.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 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 @@ <title>Bootstrap Plugin Test Suite</title> <!-- jquery --> - <script src="http://code.jquery.com/jquery-1.5.2.min.js"></script> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <!-- qunit --> <link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen" /> @@ -17,6 +17,7 @@ <script src="../../js/bootstrap-tabs.js"></script> <script src="../../js/bootstrap-twipsy.js"></script> <script src="../../js/bootstrap-popover.js"></script> + <script src="../../js/bootstrap-buttons.js"></script> <!-- unit tests --> <script src="unit/bootstrap-alerts.js"></script> @@ -25,6 +26,7 @@ <script src="unit/bootstrap-popover.js"></script> <script src="unit/bootstrap-tabs.js"></script> <script src="unit/bootstrap-twipsy.js"></script> + <script src="unit/bootstrap-buttons.js"></script> <body> <div> 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 = $('<button class="btn" data-loading-text="fat">mdo</button>') + 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 = $('<button class="btn" data-loading-text="fat">mdo</button>') + 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 = $('<button class="btn" data-loading-text="fat">mdo</button>') + 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 |
