From a736c69683e2bfc7abdc28501b5b5bed2ff85a97 Mon Sep 17 00:00:00 2001 From: Salvatore Iovene Date: Mon, 14 Jan 2013 11:35:01 +0200 Subject: [PATCH] Upgrades Bootstrap widgets to 2.2.2. --- src/bootstrap/js/bootstrap-affix.js | 17 +++++++-- src/bootstrap/js/bootstrap-alert.js | 17 ++++++--- src/bootstrap/js/bootstrap-button.js | 23 +++++++++---- src/bootstrap/js/bootstrap-carousel.js | 35 ++++++++++++------- src/bootstrap/js/bootstrap-collapse.js | 37 ++++++++++++-------- src/bootstrap/js/bootstrap-dropdown.js | 37 +++++++++++++------- src/bootstrap/js/bootstrap-modal.js | 56 ++++++++++++++++-------------- src/bootstrap/js/bootstrap-popover.js | 17 +++++++-- src/bootstrap/js/bootstrap-scrollspy.js | 15 ++++++-- src/bootstrap/js/bootstrap-tab.js | 25 +++++++++----- src/bootstrap/js/bootstrap-tooltip.js | 34 ++++++++++++------ src/bootstrap/js/bootstrap-transition.js | 10 +++--- src/bootstrap/js/bootstrap-typeahead.js | 59 ++++++++++++++++++++++---------- 13 files changed, 257 insertions(+), 125 deletions(-) diff --git a/src/bootstrap/js/bootstrap-affix.js b/src/bootstrap/js/bootstrap-affix.js index c49d6e9..6020a19 100644 --- a/src/bootstrap/js/bootstrap-affix.js +++ b/src/bootstrap/js/bootstrap-affix.js @@ -1,5 +1,5 @@ /* ========================================================== - * bootstrap-affix.js v2.1.1 + * bootstrap-affix.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#affix * ========================================================== * Copyright 2012 Twitter, Inc. @@ -28,7 +28,9 @@ var Affix = function (element, options) { this.options = $.extend({}, $.fn.affix.defaults, options) - this.$window = $(window).on('scroll.affix.data-api', $.proxy(this.checkPosition, this)) + this.$window = $(window) + .on('scroll.affix.data-api', $.proxy(this.checkPosition, this)) + .on('click.affix.data-api', $.proxy(function () { setTimeout($.proxy(this.checkPosition, this), 1) }, this)) this.$element = $(element) this.checkPosition() } @@ -66,6 +68,8 @@ /* AFFIX PLUGIN DEFINITION * ======================= */ + var old = $.fn.affix + $.fn.affix = function (option) { return this.each(function () { var $this = $(this) @@ -83,6 +87,15 @@ } + /* AFFIX NO CONFLICT + * ================= */ + + $.fn.affix.noConflict = function () { + $.fn.affix = old + return this + } + + /* AFFIX DATA-API * ============== */ diff --git a/src/bootstrap/js/bootstrap-alert.js b/src/bootstrap/js/bootstrap-alert.js index 51273ab..5bc0264 100644 --- a/src/bootstrap/js/bootstrap-alert.js +++ b/src/bootstrap/js/bootstrap-alert.js @@ -1,5 +1,5 @@ /* ========================================================== - * bootstrap-alert.js v2.1.1 + * bootstrap-alert.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#alerts * ========================================================== * Copyright 2012 Twitter, Inc. @@ -68,6 +68,8 @@ /* ALERT PLUGIN DEFINITION * ======================= */ + var old = $.fn.alert + $.fn.alert = function (option) { return this.each(function () { var $this = $(this) @@ -80,11 +82,18 @@ $.fn.alert.Constructor = Alert + /* ALERT NO CONFLICT + * ================= */ + + $.fn.alert.noConflict = function () { + $.fn.alert = old + return this + } + + /* ALERT DATA-API * ============== */ - $(function () { - $('body').on('click.alert.data-api', dismiss, Alert.prototype.close) - }) + $(document).on('click.alert.data-api', dismiss, Alert.prototype.close) }(window.jQuery); \ No newline at end of file diff --git a/src/bootstrap/js/bootstrap-button.js b/src/bootstrap/js/bootstrap-button.js index a0ab0bf..39b8339 100644 --- a/src/bootstrap/js/bootstrap-button.js +++ b/src/bootstrap/js/bootstrap-button.js @@ -1,5 +1,5 @@ /* ============================================================ - * bootstrap-button.js v2.1.1 + * bootstrap-button.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#buttons * ============================================================ * Copyright 2012 Twitter, Inc. @@ -64,6 +64,8 @@ /* BUTTON PLUGIN DEFINITION * ======================== */ + var old = $.fn.button + $.fn.button = function (option) { return this.each(function () { var $this = $(this) @@ -82,15 +84,22 @@ $.fn.button.Constructor = Button + /* BUTTON NO CONFLICT + * ================== */ + + $.fn.button.noConflict = function () { + $.fn.button = old + return this + } + + /* BUTTON DATA-API * =============== */ - $(function () { - $('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) { - var $btn = $(e.target) - if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') - $btn.button('toggle') - }) + $(document).on('click.button.data-api', '[data-toggle^=button]', function (e) { + var $btn = $(e.target) + if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') + $btn.button('toggle') }) }(window.jQuery); \ No newline at end of file diff --git a/src/bootstrap/js/bootstrap-carousel.js b/src/bootstrap/js/bootstrap-carousel.js index 5c194b4..238ff42 100644 --- a/src/bootstrap/js/bootstrap-carousel.js +++ b/src/bootstrap/js/bootstrap-carousel.js @@ -1,5 +1,5 @@ /* ========================================================== - * bootstrap-carousel.js v2.1.1 + * bootstrap-carousel.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#carousel * ========================================================== * Copyright 2012 Twitter, Inc. @@ -29,7 +29,6 @@ var Carousel = function (element, options) { this.$element = $(element) this.options = options - this.options.slide && this.slide(this.options.slide) this.options.pause == 'hover' && this.$element .on('mouseenter', $.proxy(this.pause, this)) .on('mouseleave', $.proxy(this.cycle, this)) @@ -94,9 +93,7 @@ , direction = type == 'next' ? 'left' : 'right' , fallback = type == 'next' ? 'first' : 'last' , that = this - , e = $.Event('slide', { - relatedTarget: $next[0] - }) + , e this.sliding = true @@ -104,6 +101,10 @@ $next = $next.length ? $next : this.$element.find('.item')[fallback]() + e = $.Event('slide', { + relatedTarget: $next[0] + }) + if ($next.hasClass('active')) return if ($.support.transition && this.$element.hasClass('slide')) { @@ -139,6 +140,8 @@ /* CAROUSEL PLUGIN DEFINITION * ========================== */ + var old = $.fn.carousel + $.fn.carousel = function (option) { return this.each(function () { var $this = $(this) @@ -160,17 +163,23 @@ $.fn.carousel.Constructor = Carousel + /* CAROUSEL NO CONFLICT + * ==================== */ + + $.fn.carousel.noConflict = function () { + $.fn.carousel = old + return this + } + /* CAROUSEL DATA-API * ================= */ - $(function () { - $('body').on('click.carousel.data-api', '[data-slide]', function ( e ) { - var $this = $(this), href - , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 - , options = !$target.data('modal') && $.extend({}, $target.data(), $this.data()) - $target.carousel(options) - e.preventDefault() - }) + $(document).on('click.carousel.data-api', '[data-slide]', function (e) { + var $this = $(this), href + , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 + , options = $.extend({}, $target.data(), $this.data()) + $target.carousel(options) + e.preventDefault() }) }(window.jQuery); \ No newline at end of file diff --git a/src/bootstrap/js/bootstrap-collapse.js b/src/bootstrap/js/bootstrap-collapse.js index 8116f22..6ac0191 100644 --- a/src/bootstrap/js/bootstrap-collapse.js +++ b/src/bootstrap/js/bootstrap-collapse.js @@ -1,5 +1,5 @@ /* ============================================================= - * bootstrap-collapse.js v2.1.1 + * bootstrap-collapse.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#collapse * ============================================================= * Copyright 2012 Twitter, Inc. @@ -120,8 +120,10 @@ } - /* COLLAPSIBLE PLUGIN DEFINITION - * ============================== */ + /* COLLAPSE PLUGIN DEFINITION + * ========================== */ + + var old = $.fn.collapse $.fn.collapse = function (option) { return this.each(function () { @@ -140,19 +142,26 @@ $.fn.collapse.Constructor = Collapse - /* COLLAPSIBLE DATA-API + /* COLLAPSE NO CONFLICT * ==================== */ - $(function () { - $('body').on('click.collapse.data-api', '[data-toggle=collapse]', function (e) { - var $this = $(this), href - , target = $this.attr('data-target') - || e.preventDefault() - || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7 - , option = $(target).data('collapse') ? 'toggle' : $this.data() - $this[$(target).hasClass('in') ? 'addClass' : 'removeClass']('collapsed') - $(target).collapse(option) - }) + $.fn.collapse.noConflict = function () { + $.fn.collapse = old + return this + } + + + /* COLLAPSE DATA-API + * ================= */ + + $(document).on('click.collapse.data-api', '[data-toggle=collapse]', function (e) { + var $this = $(this), href + , target = $this.attr('data-target') + || e.preventDefault() + || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7 + , option = $(target).data('collapse') ? 'toggle' : $this.data() + $this[$(target).hasClass('in') ? 'addClass' : 'removeClass']('collapsed') + $(target).collapse(option) }) }(window.jQuery); \ No newline at end of file diff --git a/src/bootstrap/js/bootstrap-dropdown.js b/src/bootstrap/js/bootstrap-dropdown.js index 42370df..900355d 100644 --- a/src/bootstrap/js/bootstrap-dropdown.js +++ b/src/bootstrap/js/bootstrap-dropdown.js @@ -1,5 +1,5 @@ /* ============================================================ - * bootstrap-dropdown.js v2.1.1 + * bootstrap-dropdown.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#dropdowns * ============================================================ * Copyright 2012 Twitter, Inc. @@ -53,9 +53,10 @@ if (!isActive) { $parent.toggleClass('open') - $this.focus() } + $this.focus() + return false } @@ -82,7 +83,7 @@ if (!isActive || (isActive && e.keyCode == 27)) return $this.click() - $items = $('[role=menu] li:not(.divider) a', $parent) + $items = $('[role=menu] li:not(.divider):visible a', $parent) if (!$items.length) return @@ -100,8 +101,9 @@ } function clearMenus() { - getParent($(toggle)) - .removeClass('open') + $(toggle).each(function () { + getParent($(this)).removeClass('open') + }) } function getParent($this) { @@ -123,6 +125,8 @@ /* DROPDOWN PLUGIN DEFINITION * ========================== */ + var old = $.fn.dropdown + $.fn.dropdown = function (option) { return this.each(function () { var $this = $(this) @@ -135,16 +139,23 @@ $.fn.dropdown.Constructor = Dropdown + /* DROPDOWN NO CONFLICT + * ==================== */ + + $.fn.dropdown.noConflict = function () { + $.fn.dropdown = old + return this + } + + /* APPLY TO STANDARD DROPDOWN ELEMENTS * =================================== */ - $(function () { - $('html') - .on('click.dropdown.data-api touchstart.dropdown.data-api', clearMenus) - $('body') - .on('click.dropdown touchstart.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) - .on('click.dropdown.data-api touchstart.dropdown.data-api' , toggle, Dropdown.prototype.toggle) - .on('keydown.dropdown.data-api touchstart.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown) - }) + $(document) + .on('click.dropdown.data-api touchstart.dropdown.data-api', clearMenus) + .on('click.dropdown touchstart.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) + .on('touchstart.dropdown.data-api', '.dropdown-menu', function (e) { e.stopPropagation() }) + .on('click.dropdown.data-api touchstart.dropdown.data-api' , toggle, Dropdown.prototype.toggle) + .on('keydown.dropdown.data-api touchstart.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown) }(window.jQuery); \ No newline at end of file diff --git a/src/bootstrap/js/bootstrap-modal.js b/src/bootstrap/js/bootstrap-modal.js index f1622b1..689a414 100644 --- a/src/bootstrap/js/bootstrap-modal.js +++ b/src/bootstrap/js/bootstrap-modal.js @@ -1,5 +1,5 @@ /* ========================================================= - * bootstrap-modal.js v2.1.1 + * bootstrap-modal.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#modals * ========================================================= * Copyright 2012 Twitter, Inc. @@ -49,8 +49,6 @@ if (this.isShown || e.isDefaultPrevented()) return - $('body').addClass('modal-open') - this.isShown = true this.escape() @@ -72,13 +70,12 @@ that.$element .addClass('in') .attr('aria-hidden', false) - .focus() that.enforceFocus() transition ? - that.$element.one($.support.transition.end, function () { that.$element.trigger('shown') }) : - that.$element.trigger('shown') + that.$element.one($.support.transition.end, function () { that.$element.focus().trigger('shown') }) : + that.$element.focus().trigger('shown') }) } @@ -96,8 +93,6 @@ this.isShown = false - $('body').removeClass('modal-open') - this.escape() $(document).off('focusin.modal') @@ -167,9 +162,11 @@ this.$backdrop = $('