From f071549c8408241b88a95192e477816d2402eb6e Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Thu, 22 May 2014 09:00:19 -0700 Subject: [PATCH 01/19] fix #13386 --- js/carousel.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/carousel.js b/js/carousel.js index 05631f7a33..d3e7e52b4e 100644 --- a/js/carousel.js +++ b/js/carousel.js @@ -203,6 +203,7 @@ var href var $this = $(this) var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 + if (!$target.hasClass('carousel')) return var options = $.extend({}, $target.data(), $this.data()) var slideIndex = $this.attr('data-slide-to') if (slideIndex) options.interval = false From 7339759fd6e11473a633f55f53a0b4ced6a7fa7d Mon Sep 17 00:00:00 2001 From: Julian Thilo Date: Mon, 23 Jun 2014 17:51:02 +0200 Subject: [PATCH 02/19] Remove broken link to Customizing Bootstrap --- docs/_includes/getting-started/examples.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_includes/getting-started/examples.html b/docs/_includes/getting-started/examples.html index 849d044c05..b1739f1d7f 100644 --- a/docs/_includes/getting-started/examples.html +++ b/docs/_includes/getting-started/examples.html @@ -1,7 +1,7 @@

Examples

-

Build on the basic template above with Bootstrap's many components. See also Customizing Bootstrap for tips on maintaining your own Bootstrap variants.

+

Build on the basic template above with Bootstrap's many components. We encourage you to customize and adapt Bootstrap to suit your individual project's needs.

Using the framework

From 09cf618acff6e6992aa14bc11c89206f104c6748 Mon Sep 17 00:00:00 2001 From: Thomas Welton Date: Fri, 20 Jun 2014 10:31:49 +0100 Subject: [PATCH 03/19] Use @font-size-small variable to calculate font-size fixes #13713 #13809 --- less/type.less | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/less/type.less b/less/type.less index 5eb69f3c21..9b1e48bae0 100644 --- a/less/type.less +++ b/less/type.less @@ -74,10 +74,10 @@ p { // Emphasis & misc // ------------------------- -// Ex: 14px base font * 85% = about 12px +// Ex: (12px small font / 14px base font) * 100% = about 85% small, .small { - font-size: 85%; + font-size: floor((100% * @font-size-small / @font-size-base)); } // Undo browser default styling From c2c19a4d2d45d8ccb5c84d293dea35a94148c9a4 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 23 Jun 2014 11:07:18 -0700 Subject: [PATCH 04/19] Revert UMD (#13772 & friends) for now, due to #13812. Will hopefully revert this reversion and land a fully-working version of UMD in v3.3.0. Revert "some changes from #13801 - add strict mode back and ==" This reverts commit 2b302f69eea416bc85e7827b7d7a74d49f879662. Revert "Fix regression of #10038 introduced by #13772" This reverts commit e9d6756a1ac76a9db31a41e8e03f663bedc41b70. Revert "MD/CommonJS/Globals #12909" This reverts commit 1c6fa9010daf0d0c21de9e20fe6ac4dba1788d90. Revert "address #13811" This reverts commit f347d7d955bbb17234b8e12c68efae7d516ce62c. Conflicts: js/carousel.js js/collapse.js js/dropdown.js js/modal.js js/tab.js js/tooltip.js --- Gruntfile.js | 2 +- dist/js/bootstrap.js | 2 +- docs/assets/js/_src/customizer.js | 2 +- js/.jscsrc | 3 +- js/.jshintrc | 3 +- js/affix.js | 210 ++++---- js/alert.js | 128 +++-- js/button.js | 164 +++---- js/carousel.js | 372 +++++++------- js/collapse.js | 270 +++++------ js/dropdown.js | 256 +++++----- js/modal.js | 528 ++++++++++---------- js/popover.js | 200 ++++---- js/scrollspy.js | 270 +++++------ js/tab.js | 224 +++++---- js/tooltip.js | 776 +++++++++++++++--------------- js/transition.js | 82 ++-- 17 files changed, 1710 insertions(+), 1782 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 31f287960f..66ee6975c0 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -33,7 +33,7 @@ module.exports = function (grunt) { ' * Licensed under <%= pkg.license.type %> (<%= pkg.license.url %>)\n' + ' */\n', // NOTE: This jqueryCheck code is duplicated in customizer.js; if making changes here, be sure to update the other copy too. - jqueryCheck: 'if (typeof define == \'undefined\' && typeof exports == \'undefined\' && typeof jQuery == \'undefined\') { throw new Error(\'Bootstrap\\\'s JavaScript requires jQuery\') }\n\n', + jqueryCheck: 'if (typeof jQuery === \'undefined\') { throw new Error(\'Bootstrap\\\'s JavaScript requires jQuery\') }\n\n', // Task configuration. clean: { diff --git a/dist/js/bootstrap.js b/dist/js/bootstrap.js index 74e45e49d0..aa9bbb1753 100644 --- a/dist/js/bootstrap.js +++ b/dist/js/bootstrap.js @@ -4,7 +4,7 @@ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) */ -if (typeof define == 'undefined' && typeof exports == 'undefined' && typeof jQuery == 'undefined') { throw new Error('Bootstrap\'s JavaScript requires jQuery') } +if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript requires jQuery') } /* ======================================================================== * Bootstrap: transition.js v3.1.1 diff --git a/docs/assets/js/_src/customizer.js b/docs/assets/js/_src/customizer.js index 5bbb0b64bb..f04908e31f 100644 --- a/docs/assets/js/_src/customizer.js +++ b/docs/assets/js/_src/customizer.js @@ -306,7 +306,7 @@ window.onload = function () { // wait for load in a dumb way because B-0 function generateJS(preamble) { var $checked = $('#plugin-section input:checked') - var jqueryCheck = 'if (typeof define == \'undefined\' && typeof exports == \'undefined\' && typeof jQuery == \'undefined\') { throw new Error(\'Bootstrap\\\'s JavaScript requires jQuery\') }\n\n' + var jqueryCheck = 'if (typeof jQuery === "undefined") { throw new Error("Bootstrap\'s JavaScript requires jQuery") }\n\n' if (!$checked.length) return false diff --git a/js/.jscsrc b/js/.jscsrc index 5b481cfb22..619690a686 100644 --- a/js/.jscsrc +++ b/js/.jscsrc @@ -11,9 +11,10 @@ "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], "disallowSpacesInNamedFunctionExpression": { "beforeOpeningRoundBrace": true }, "disallowSpacesInsideArrayBrackets": true, - "disallowTrailingComma": true, "disallowSpacesInsideParentheses": true, + "disallowTrailingComma": true, "disallowTrailingWhitespace": true, + "requireCamelCaseOrUpperCaseIdentifiers": true, "requireCapitalizedConstructors": true, "requireCommaBeforeLineBreak": true, "requireDotNotation": true, diff --git a/js/.jshintrc b/js/.jshintrc index 8a9391fdd0..a59e1d00a1 100644 --- a/js/.jshintrc +++ b/js/.jshintrc @@ -11,6 +11,5 @@ "nonbsp" : true, "strict" : true, "undef" : true, - "unused" : true, - "predef" : [ "define", "require" ] + "unused" : true } diff --git a/js/affix.js b/js/affix.js index ab215bb818..5af32fee64 100644 --- a/js/affix.js +++ b/js/affix.js @@ -7,142 +7,136 @@ * ======================================================================== */ -+function () { 'use strict'; ++function ($) { + 'use strict'; - (function (o_o) { - typeof define == 'function' && define.amd ? define(['jquery'], o_o) : - typeof exports == 'object' ? o_o(require('jquery')) : o_o(jQuery) - })(function ($) { + // AFFIX CLASS DEFINITION + // ====================== - // AFFIX CLASS DEFINITION - // ====================== + var Affix = function (element, options) { + this.options = $.extend({}, Affix.DEFAULTS, options) - var Affix = function (element, options) { - this.options = $.extend({}, Affix.DEFAULTS, options) + this.$target = $(this.options.target) + .on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this)) + .on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this)) - this.$target = $(this.options.target) - .on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this)) - .on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this)) + this.$element = $(element) + this.affixed = + this.unpin = + this.pinnedOffset = null - this.$element = $(element) - this.affixed = - this.unpin = - this.pinnedOffset = null + this.checkPosition() + } - this.checkPosition() - } + Affix.VERSION = '3.1.1' - Affix.VERSION = '3.1.1' + Affix.RESET = 'affix affix-top affix-bottom' - Affix.RESET = 'affix affix-top affix-bottom' + Affix.DEFAULTS = { + offset: 0, + target: window + } - Affix.DEFAULTS = { - offset: 0, - target: window - } + Affix.prototype.getPinnedOffset = function () { + if (this.pinnedOffset) return this.pinnedOffset + this.$element.removeClass(Affix.RESET).addClass('affix') + var scrollTop = this.$target.scrollTop() + var position = this.$element.offset() + return (this.pinnedOffset = position.top - scrollTop) + } - Affix.prototype.getPinnedOffset = function () { - if (this.pinnedOffset) return this.pinnedOffset - this.$element.removeClass(Affix.RESET).addClass('affix') - var scrollTop = this.$target.scrollTop() - var position = this.$element.offset() - return (this.pinnedOffset = position.top - scrollTop) - } + Affix.prototype.checkPositionWithEventLoop = function () { + setTimeout($.proxy(this.checkPosition, this), 1) + } - Affix.prototype.checkPositionWithEventLoop = function () { - setTimeout($.proxy(this.checkPosition, this), 1) - } + Affix.prototype.checkPosition = function () { + if (!this.$element.is(':visible')) return - Affix.prototype.checkPosition = function () { - if (!this.$element.is(':visible')) return + var scrollHeight = $(document).height() + var scrollTop = this.$target.scrollTop() + var position = this.$element.offset() + var offset = this.options.offset + var offsetTop = offset.top + var offsetBottom = offset.bottom - var scrollHeight = $(document).height() - var scrollTop = this.$target.scrollTop() - var position = this.$element.offset() - var offset = this.options.offset - var offsetTop = offset.top - var offsetBottom = offset.bottom + if (typeof offset != 'object') offsetBottom = offsetTop = offset + if (typeof offsetTop == 'function') offsetTop = offset.top(this.$element) + if (typeof offsetBottom == 'function') offsetBottom = offset.bottom(this.$element) - if (typeof offset != 'object') offsetBottom = offsetTop = offset - if (typeof offsetTop == 'function') offsetTop = offset.top(this.$element) - if (typeof offsetBottom == 'function') offsetBottom = offset.bottom(this.$element) + var affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ? false : + offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ? 'bottom' : + offsetTop != null && (scrollTop <= offsetTop) ? 'top' : false - var affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ? false : - offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ? 'bottom' : - offsetTop != null && (scrollTop <= offsetTop) ? 'top' : false + if (this.affixed === affix) return + if (this.unpin != null) this.$element.css('top', '') - if (this.affixed === affix) return - if (this.unpin != null) this.$element.css('top', '') + var affixType = 'affix' + (affix ? '-' + affix : '') + var e = $.Event(affixType + '.bs.affix') - var affixType = 'affix' + (affix ? '-' + affix : '') - var e = $.Event(affixType + '.bs.affix') + this.$element.trigger(e) - this.$element.trigger(e) + if (e.isDefaultPrevented()) return - if (e.isDefaultPrevented()) return + this.affixed = affix + this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null - this.affixed = affix - this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null + this.$element + .removeClass(Affix.RESET) + .addClass(affixType) + .trigger($.Event(affixType.replace('affix', 'affixed'))) - this.$element - .removeClass(Affix.RESET) - .addClass(affixType) - .trigger($.Event(affixType.replace('affix', 'affixed'))) - - if (affix == 'bottom') { - this.$element.offset({ - top: scrollHeight - this.$element.height() - offsetBottom - }) - } - } - - - // AFFIX PLUGIN DEFINITION - // ======================= - - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.affix') - var options = typeof option == 'object' && option - - if (!data) $this.data('bs.affix', (data = new Affix(this, options))) - if (typeof option == 'string') data[option]() + if (affix == 'bottom') { + this.$element.offset({ + top: scrollHeight - this.$element.height() - offsetBottom }) } - - var old = $.fn.affix - - $.fn.affix = Plugin - $.fn.affix.Constructor = Affix + } - // AFFIX NO CONFLICT - // ================= + // AFFIX PLUGIN DEFINITION + // ======================= - $.fn.affix.noConflict = function () { - $.fn.affix = old - return this - } + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.affix') + var options = typeof option == 'object' && option - - // AFFIX DATA-API - // ============== - - $(window).on('load', function () { - $('[data-spy="affix"]').each(function () { - var $spy = $(this) - var data = $spy.data() - - data.offset = data.offset || {} - - if (data.offsetBottom) data.offset.bottom = data.offsetBottom - if (data.offsetTop) data.offset.top = data.offsetTop - - Plugin.call($spy, data) - }) + if (!data) $this.data('bs.affix', (data = new Affix(this, options))) + if (typeof option == 'string') data[option]() }) + } + var old = $.fn.affix + + $.fn.affix = Plugin + $.fn.affix.Constructor = Affix + + + // AFFIX NO CONFLICT + // ================= + + $.fn.affix.noConflict = function () { + $.fn.affix = old + return this + } + + + // AFFIX DATA-API + // ============== + + $(window).on('load', function () { + $('[data-spy="affix"]').each(function () { + var $spy = $(this) + var data = $spy.data() + + data.offset = data.offset || {} + + if (data.offsetBottom) data.offset.bottom = data.offsetBottom + if (data.offsetTop) data.offset.top = data.offsetTop + + Plugin.call($spy, data) + }) }) -}(); +}(jQuery); diff --git a/js/alert.js b/js/alert.js index f34f84a289..721e9aa477 100644 --- a/js/alert.js +++ b/js/alert.js @@ -7,92 +7,86 @@ * ======================================================================== */ -+function () { 'use strict'; ++function ($) { + 'use strict'; - (function (o_o) { - typeof define == 'function' && define.amd ? define(['jquery'], o_o) : - typeof exports == 'object' ? o_o(require('jquery')) : o_o(jQuery) - })(function ($) { + // ALERT CLASS DEFINITION + // ====================== - // ALERT CLASS DEFINITION - // ====================== + var dismiss = '[data-dismiss="alert"]' + var Alert = function (el) { + $(el).on('click', dismiss, this.close) + } - var dismiss = '[data-dismiss="alert"]' - var Alert = function (el) { - $(el).on('click', dismiss, this.close) + Alert.VERSION = '3.1.1' + + Alert.prototype.close = function (e) { + var $this = $(this) + var selector = $this.attr('data-target') + + if (!selector) { + selector = $this.attr('href') + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 } - Alert.VERSION = '3.1.1' + var $parent = $(selector) - Alert.prototype.close = function (e) { - var $this = $(this) - var selector = $this.attr('data-target') + if (e) e.preventDefault() - if (!selector) { - selector = $this.attr('href') - selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 - } - - var $parent = $(selector) - - if (e) e.preventDefault() - - if (!$parent.length) { - $parent = $this.hasClass('alert') ? $this : $this.parent() - } - - $parent.trigger(e = $.Event('close.bs.alert')) - - if (e.isDefaultPrevented()) return - - $parent.removeClass('in') - - function removeElement() { - // detach from parent, fire event then clean up data - $parent.detach().trigger('closed.bs.alert').remove() - } - - $.support.transition && $parent.hasClass('fade') ? - $parent - .one('bsTransitionEnd', removeElement) - .emulateTransitionEnd(150) : - removeElement() + if (!$parent.length) { + $parent = $this.hasClass('alert') ? $this : $this.parent() } + $parent.trigger(e = $.Event('close.bs.alert')) - // ALERT PLUGIN DEFINITION - // ======================= + if (e.isDefaultPrevented()) return - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.alert') + $parent.removeClass('in') - if (!data) $this.data('bs.alert', (data = new Alert(this))) - if (typeof option == 'string') data[option].call($this) - }) + function removeElement() { + // detach from parent, fire event then clean up data + $parent.detach().trigger('closed.bs.alert').remove() } - var old = $.fn.alert - - $.fn.alert = Plugin - $.fn.alert.Constructor = Alert + $.support.transition && $parent.hasClass('fade') ? + $parent + .one('bsTransitionEnd', removeElement) + .emulateTransitionEnd(150) : + removeElement() + } - // ALERT NO CONFLICT - // ================= + // ALERT PLUGIN DEFINITION + // ======================= - $.fn.alert.noConflict = function () { - $.fn.alert = old - return this - } + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.alert') + + if (!data) $this.data('bs.alert', (data = new Alert(this))) + if (typeof option == 'string') data[option].call($this) + }) + } + + var old = $.fn.alert + + $.fn.alert = Plugin + $.fn.alert.Constructor = Alert - // ALERT DATA-API - // ============== + // ALERT NO CONFLICT + // ================= - $(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close) + $.fn.alert.noConflict = function () { + $.fn.alert = old + return this + } - }) -}(); + // ALERT DATA-API + // ============== + + $(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close) + +}(jQuery); diff --git a/js/button.js b/js/button.js index e96788c05e..aa71450722 100644 --- a/js/button.js +++ b/js/button.js @@ -7,110 +7,104 @@ * ======================================================================== */ -+function () { 'use strict'; ++function ($) { + 'use strict'; - (function (o_o) { - typeof define == 'function' && define.amd ? define(['jquery'], o_o) : - typeof exports == 'object' ? o_o(require('jquery')) : o_o(jQuery) - })(function ($) { + // BUTTON PUBLIC CLASS DEFINITION + // ============================== - // BUTTON PUBLIC CLASS DEFINITION - // ============================== + var Button = function (element, options) { + this.$element = $(element) + this.options = $.extend({}, Button.DEFAULTS, options) + this.isLoading = false + } - var Button = function (element, options) { - this.$element = $(element) - this.options = $.extend({}, Button.DEFAULTS, options) - this.isLoading = false - } + Button.VERSION = '3.1.1' - Button.VERSION = '3.1.1' + Button.DEFAULTS = { + loadingText: 'loading...' + } - 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() - 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' - state = state + 'Text' + if (data.resetText == null) $el.data('resetText', $el[val]()) - if (data.resetText == null) $el.data('resetText', $el[val]()) + $el[val](data[state] == null ? this.options[state] : data[state]) - $el[val](data[state] == null ? this.options[state] : data[state]) - - // push to event loop to allow forms to submit - setTimeout($.proxy(function () { - if (state == 'loadingText') { - this.isLoading = true - $el.addClass(d).attr(d, d) - } else if (this.isLoading) { - this.isLoading = false - $el.removeClass(d).removeAttr(d) - } - }, this), 0) - } - - Button.prototype.toggle = function () { - var changed = true - var $parent = this.$element.closest('[data-toggle="buttons"]') - - if ($parent.length) { - var $input = this.$element.find('input') - if ($input.prop('type') == 'radio') { - if ($input.prop('checked') && this.$element.hasClass('active')) changed = false - else $parent.find('.active').removeClass('active') - } - if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change') + // push to event loop to allow forms to submit + setTimeout($.proxy(function () { + if (state == 'loadingText') { + this.isLoading = true + $el.addClass(d).attr(d, d) + } else if (this.isLoading) { + this.isLoading = false + $el.removeClass(d).removeAttr(d) } + }, this), 0) + } - if (changed) this.$element.toggleClass('active') + Button.prototype.toggle = function () { + var changed = true + var $parent = this.$element.closest('[data-toggle="buttons"]') + + if ($parent.length) { + var $input = this.$element.find('input') + if ($input.prop('type') == 'radio') { + if ($input.prop('checked') && this.$element.hasClass('active')) changed = false + else $parent.find('.active').removeClass('active') + } + if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change') } - - // BUTTON PLUGIN DEFINITION - // ======================== - - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.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) - }) - } - - var old = $.fn.button - - $.fn.button = Plugin - $.fn.button.Constructor = Button + if (changed) this.$element.toggleClass('active') + } - // BUTTON NO CONFLICT - // ================== + // BUTTON PLUGIN DEFINITION + // ======================== - $.fn.button.noConflict = function () { - $.fn.button = old - return this - } + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.button') + var options = typeof option == 'object' && option + if (!data) $this.data('bs.button', (data = new Button(this, options))) - // BUTTON DATA-API - // =============== - - $(document).on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) { - var $btn = $(e.target) - if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') - Plugin.call($btn, 'toggle') - e.preventDefault() + if (option == 'toggle') data.toggle() + else if (option) data.setState(option) }) + } + var old = $.fn.button + + $.fn.button = Plugin + $.fn.button.Constructor = Button + + + // BUTTON NO CONFLICT + // ================== + + $.fn.button.noConflict = function () { + $.fn.button = old + return this + } + + + // BUTTON DATA-API + // =============== + + $(document).on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) { + var $btn = $(e.target) + if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') + Plugin.call($btn, 'toggle') + e.preventDefault() }) -}(); +}(jQuery); diff --git a/js/carousel.js b/js/carousel.js index 7418ec5f51..d7727bcce6 100644 --- a/js/carousel.js +++ b/js/carousel.js @@ -7,222 +7,216 @@ * ======================================================================== */ -+function () { 'use strict'; ++function ($) { + 'use strict'; - (function (o_o) { - typeof define == 'function' && define.amd ? define(['jquery'], o_o) : - typeof exports == 'object' ? o_o(require('jquery')) : o_o(jQuery) - })(function ($) { + // CAROUSEL CLASS DEFINITION + // ========================= - // CAROUSEL CLASS DEFINITION - // ========================= + var Carousel = function (element, options) { + this.$element = $(element).on('keydown.bs.carousel', $.proxy(this.keydown, this)) + this.$indicators = this.$element.find('.carousel-indicators') + this.options = options + this.paused = + this.sliding = + this.interval = + this.$active = + this.$items = null - var Carousel = function (element, options) { - this.$element = $(element).on('keydown.bs.carousel', $.proxy(this.keydown, this)) - this.$indicators = this.$element.find('.carousel-indicators') - this.options = options - this.paused = - this.sliding = - this.interval = - this.$active = - this.$items = null + this.options.pause == 'hover' && this.$element + .on('mouseenter.bs.carousel', $.proxy(this.pause, this)) + .on('mouseleave.bs.carousel', $.proxy(this.cycle, this)) + } - this.options.pause == 'hover' && this.$element - .on('mouseenter.bs.carousel', $.proxy(this.pause, this)) - .on('mouseleave.bs.carousel', $.proxy(this.cycle, this)) + Carousel.VERSION = '3.1.1' + + Carousel.DEFAULTS = { + interval: 5000, + pause: 'hover', + wrap: true + } + + Carousel.prototype.keydown = function (e) { + switch (e.which) { + case 37: this.prev(); break + case 39: this.next(); break + default: return } - Carousel.VERSION = '3.1.1' + e.preventDefault() + } - Carousel.DEFAULTS = { - interval: 5000, - pause: 'hover', - wrap: true + Carousel.prototype.cycle = function (e) { + e || (this.paused = false) + + this.interval && clearInterval(this.interval) + + this.options.interval + && !this.paused + && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) + + return this + } + + Carousel.prototype.getItemIndex = function (item) { + this.$items = item.parent().children('.item') + return this.$items.index(item || this.$active) + } + + Carousel.prototype.to = function (pos) { + var that = this + var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active')) + + if (pos > (this.$items.length - 1) || pos < 0) return + + if (this.sliding) return this.$element.one('slid.bs.carousel', function () { that.to(pos) }) // yes, "slid" + if (activeIndex == pos) return this.pause().cycle() + + return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos])) + } + + Carousel.prototype.pause = function (e) { + e || (this.paused = true) + + if (this.$element.find('.next, .prev').length && $.support.transition) { + this.$element.trigger($.support.transition.end) + this.cycle(true) } - Carousel.prototype.keydown = function (e) { - switch (e.which) { - case 37: this.prev(); break - case 39: this.next(); break - default: return - } + this.interval = clearInterval(this.interval) - e.preventDefault() + return this + } + + Carousel.prototype.next = function () { + if (this.sliding) return + return this.slide('next') + } + + Carousel.prototype.prev = function () { + if (this.sliding) return + return this.slide('prev') + } + + Carousel.prototype.slide = function (type, next) { + var $active = this.$element.find('.item.active') + var $next = next || $active[type]() + var isCycling = this.interval + var direction = type == 'next' ? 'left' : 'right' + var fallback = type == 'next' ? 'first' : 'last' + var that = this + + if (!$next.length) { + if (!this.options.wrap) return + $next = this.$element.find('.item')[fallback]() } - Carousel.prototype.cycle = function (e) { - e || (this.paused = false) + if ($next.hasClass('active')) return (this.sliding = false) - this.interval && clearInterval(this.interval) + var relatedTarget = $next[0] + var slideEvent = $.Event('slide.bs.carousel', { + relatedTarget: relatedTarget, + direction: direction + }) + this.$element.trigger(slideEvent) + if (slideEvent.isDefaultPrevented()) return - this.options.interval - && !this.paused - && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) + this.sliding = true - return this + isCycling && this.pause() + + if (this.$indicators.length) { + this.$indicators.find('.active').removeClass('active') + var $nextIndicator = $(this.$indicators.children()[this.getItemIndex($next)]) + $nextIndicator && $nextIndicator.addClass('active') } - Carousel.prototype.getItemIndex = function (item) { - this.$items = item.parent().children('.item') - return this.$items.index(item || this.$active) + var slidEvent = $.Event('slid.bs.carousel', { relatedTarget: relatedTarget, direction: direction }) // yes, "slid" + if ($.support.transition && this.$element.hasClass('slide')) { + $next.addClass(type) + $next[0].offsetWidth // force reflow + $active.addClass(direction) + $next.addClass(direction) + $active + .one('bsTransitionEnd', function () { + $next.removeClass([type, direction].join(' ')).addClass('active') + $active.removeClass(['active', direction].join(' ')) + that.sliding = false + setTimeout(function () { + that.$element.trigger(slidEvent) + }, 0) + }) + .emulateTransitionEnd($active.css('transition-duration').slice(0, -1) * 1000) + } else { + $active.removeClass('active') + $next.addClass('active') + this.sliding = false + this.$element.trigger(slidEvent) } - Carousel.prototype.to = function (pos) { - var that = this - var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active')) + isCycling && this.cycle() - if (pos > (this.$items.length - 1) || pos < 0) return - - if (this.sliding) return this.$element.one('slid.bs.carousel', function () { that.to(pos) }) // yes, "slid" - if (activeIndex == pos) return this.pause().cycle() - - return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos])) - } - - Carousel.prototype.pause = function (e) { - e || (this.paused = true) - - if (this.$element.find('.next, .prev').length && $.support.transition) { - this.$element.trigger($.support.transition.end) - this.cycle(true) - } - - this.interval = clearInterval(this.interval) - - return this - } - - Carousel.prototype.next = function () { - if (this.sliding) return - return this.slide('next') - } - - Carousel.prototype.prev = function () { - if (this.sliding) return - return this.slide('prev') - } - - Carousel.prototype.slide = function (type, next) { - var $active = this.$element.find('.item.active') - var $next = next || $active[type]() - var isCycling = this.interval - var direction = type == 'next' ? 'left' : 'right' - var fallback = type == 'next' ? 'first' : 'last' - var that = this - - if (!$next.length) { - if (!this.options.wrap) return - $next = this.$element.find('.item')[fallback]() - } - - if ($next.hasClass('active')) return (this.sliding = false) - - var relatedTarget = $next[0] - var slideEvent = $.Event('slide.bs.carousel', { - relatedTarget: relatedTarget, - direction: direction - }) - this.$element.trigger(slideEvent) - if (slideEvent.isDefaultPrevented()) return - - this.sliding = true - - isCycling && this.pause() - - if (this.$indicators.length) { - this.$indicators.find('.active').removeClass('active') - var $nextIndicator = $(this.$indicators.children()[this.getItemIndex($next)]) - $nextIndicator && $nextIndicator.addClass('active') - } - - var slidEvent = $.Event('slid.bs.carousel', { relatedTarget: relatedTarget, direction: direction }) // yes, "slid" - if ($.support.transition && this.$element.hasClass('slide')) { - $next.addClass(type) - $next[0].offsetWidth // force reflow - $active.addClass(direction) - $next.addClass(direction) - $active - .one('bsTransitionEnd', function () { - $next.removeClass([type, direction].join(' ')).addClass('active') - $active.removeClass(['active', direction].join(' ')) - that.sliding = false - setTimeout(function () { - that.$element.trigger(slidEvent) - }, 0) - }) - .emulateTransitionEnd($active.css('transition-duration').slice(0, -1) * 1000) - } else { - $active.removeClass('active') - $next.addClass('active') - this.sliding = false - this.$element.trigger(slidEvent) - } - - isCycling && this.cycle() - - return this - } + return this + } - // CAROUSEL PLUGIN DEFINITION - // ========================== + // CAROUSEL PLUGIN DEFINITION + // ========================== - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.carousel') - var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option) - var action = typeof option == 'string' ? option : options.slide - - if (!data) $this.data('bs.carousel', (data = new Carousel(this, options))) - if (typeof option == 'number') data.to(option) - else if (action) data[action]() - else if (options.interval) data.pause().cycle() - }) - } - - var old = $.fn.carousel - - $.fn.carousel = Plugin - $.fn.carousel.Constructor = Carousel - - - // CAROUSEL NO CONFLICT - // ==================== - - $.fn.carousel.noConflict = function () { - $.fn.carousel = old - return this - } - - - // CAROUSEL DATA-API - // ================= - - $(document).on('click.bs.carousel.data-api', '[data-slide], [data-slide-to]', function (e) { - var href + function Plugin(option) { + return this.each(function () { var $this = $(this) - var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7 - var options = $.extend({}, $target.data(), $this.data()) - var slideIndex = $this.attr('data-slide-to') - if (slideIndex) options.interval = false + var data = $this.data('bs.carousel') + var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option) + var action = typeof option == 'string' ? option : options.slide - Plugin.call($target, options) - - if (slideIndex) { - $target.data('bs.carousel').to(slideIndex) - } - - e.preventDefault() + if (!data) $this.data('bs.carousel', (data = new Carousel(this, options))) + if (typeof option == 'number') data.to(option) + else if (action) data[action]() + else if (options.interval) data.pause().cycle() }) + } - $(window).on('load', function () { - $('[data-ride="carousel"]').each(function () { - var $carousel = $(this) - Plugin.call($carousel, $carousel.data()) - }) - }) + var old = $.fn.carousel + $.fn.carousel = Plugin + $.fn.carousel.Constructor = Carousel + + + // CAROUSEL NO CONFLICT + // ==================== + + $.fn.carousel.noConflict = function () { + $.fn.carousel = old + return this + } + + + // CAROUSEL DATA-API + // ================= + + $(document).on('click.bs.carousel.data-api', '[data-slide], [data-slide-to]', function (e) { + var href + var $this = $(this) + var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7 + var options = $.extend({}, $target.data(), $this.data()) + var slideIndex = $this.attr('data-slide-to') + if (slideIndex) options.interval = false + + Plugin.call($target, options) + + if (slideIndex) { + $target.data('bs.carousel').to(slideIndex) + } + + e.preventDefault() }) -}(); + $(window).on('load', function () { + $('[data-ride="carousel"]').each(function () { + var $carousel = $(this) + Plugin.call($carousel, $carousel.data()) + }) + }) + +}(jQuery); diff --git a/js/collapse.js b/js/collapse.js index c67939a7de..eb688f4806 100644 --- a/js/collapse.js +++ b/js/collapse.js @@ -7,170 +7,164 @@ * ======================================================================== */ -+function () { 'use strict'; ++function ($) { + 'use strict'; - (function (o_o) { - typeof define == 'function' && define.amd ? define(['jquery'], o_o) : - typeof exports == 'object' ? o_o(require('jquery')) : o_o(jQuery) - })(function ($) { + // COLLAPSE PUBLIC CLASS DEFINITION + // ================================ - // COLLAPSE PUBLIC CLASS DEFINITION - // ================================ + var Collapse = function (element, options) { + this.$element = $(element) + this.options = $.extend({}, Collapse.DEFAULTS, options) + this.transitioning = null - var Collapse = function (element, options) { - this.$element = $(element) - this.options = $.extend({}, Collapse.DEFAULTS, options) - this.transitioning = null + if (this.options.parent) this.$parent = $(this.options.parent) + if (this.options.toggle) this.toggle() + } - if (this.options.parent) this.$parent = $(this.options.parent) - if (this.options.toggle) this.toggle() + Collapse.VERSION = '3.1.1' + + Collapse.DEFAULTS = { + toggle: true + } + + Collapse.prototype.dimension = function () { + var hasWidth = this.$element.hasClass('width') + return hasWidth ? 'width' : 'height' + } + + Collapse.prototype.show = function () { + if (this.transitioning || this.$element.hasClass('in')) return + + var startEvent = $.Event('show.bs.collapse') + this.$element.trigger(startEvent) + if (startEvent.isDefaultPrevented()) return + + var actives = this.$parent && this.$parent.find('> .panel > .in') + + if (actives && actives.length) { + var hasData = actives.data('bs.collapse') + if (hasData && hasData.transitioning) return + Plugin.call(actives, 'hide') + hasData || actives.data('bs.collapse', null) } - Collapse.VERSION = '3.1.1' + var dimension = this.dimension() - Collapse.DEFAULTS = { - toggle: true - } + this.$element + .removeClass('collapse') + .addClass('collapsing')[dimension](0) - Collapse.prototype.dimension = function () { - var hasWidth = this.$element.hasClass('width') - return hasWidth ? 'width' : 'height' - } - - Collapse.prototype.show = function () { - if (this.transitioning || this.$element.hasClass('in')) return - - var startEvent = $.Event('show.bs.collapse') - this.$element.trigger(startEvent) - if (startEvent.isDefaultPrevented()) return - - var actives = this.$parent && this.$parent.find('> .panel > .in') - - if (actives && actives.length) { - var hasData = actives.data('bs.collapse') - if (hasData && hasData.transitioning) return - Plugin.call(actives, 'hide') - hasData || actives.data('bs.collapse', null) - } - - var dimension = this.dimension() + this.transitioning = 1 + var complete = function () { this.$element - .removeClass('collapse') - .addClass('collapsing')[dimension](0) - - this.transitioning = 1 - - var complete = function () { - this.$element - .removeClass('collapsing') - .addClass('collapse in')[dimension]('') - this.transitioning = 0 - this.$element - .trigger('shown.bs.collapse') - } - - if (!$.support.transition) return complete.call(this) - - var scrollSize = $.camelCase(['scroll', dimension].join('-')) - + .removeClass('collapsing') + .addClass('collapse in')[dimension]('') + this.transitioning = 0 this.$element - .one('bsTransitionEnd', $.proxy(complete, this)) - .emulateTransitionEnd(350)[dimension](this.$element[0][scrollSize]) + .trigger('shown.bs.collapse') } - Collapse.prototype.hide = function () { - if (this.transitioning || !this.$element.hasClass('in')) return + if (!$.support.transition) return complete.call(this) - var startEvent = $.Event('hide.bs.collapse') - this.$element.trigger(startEvent) - if (startEvent.isDefaultPrevented()) return + var scrollSize = $.camelCase(['scroll', dimension].join('-')) - var dimension = this.dimension() + this.$element + .one('bsTransitionEnd', $.proxy(complete, this)) + .emulateTransitionEnd(350)[dimension](this.$element[0][scrollSize]) + } - this.$element[dimension](this.$element[dimension]())[0].offsetHeight + Collapse.prototype.hide = function () { + if (this.transitioning || !this.$element.hasClass('in')) return + var startEvent = $.Event('hide.bs.collapse') + this.$element.trigger(startEvent) + if (startEvent.isDefaultPrevented()) return + + var dimension = this.dimension() + + this.$element[dimension](this.$element[dimension]())[0].offsetHeight + + this.$element + .addClass('collapsing') + .removeClass('collapse') + .removeClass('in') + + this.transitioning = 1 + + var complete = function () { + this.transitioning = 0 this.$element - .addClass('collapsing') - .removeClass('collapse') - .removeClass('in') - - this.transitioning = 1 - - var complete = function () { - this.transitioning = 0 - this.$element - .trigger('hidden.bs.collapse') - .removeClass('collapsing') - .addClass('collapse') - } - - if (!$.support.transition) return complete.call(this) - - this.$element - [dimension](0) - .one('bsTransitionEnd', $.proxy(complete, this)) - .emulateTransitionEnd(350) + .trigger('hidden.bs.collapse') + .removeClass('collapsing') + .addClass('collapse') } - Collapse.prototype.toggle = function () { - this[this.$element.hasClass('in') ? 'hide' : 'show']() - } + if (!$.support.transition) return complete.call(this) + + this.$element + [dimension](0) + .one('bsTransitionEnd', $.proxy(complete, this)) + .emulateTransitionEnd(350) + } + + Collapse.prototype.toggle = function () { + this[this.$element.hasClass('in') ? 'hide' : 'show']() + } - // COLLAPSE PLUGIN DEFINITION - // ========================== + // COLLAPSE PLUGIN DEFINITION + // ========================== - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.collapse') - var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option) - - if (!data && options.toggle && option == 'show') option = !option - if (!data) $this.data('bs.collapse', (data = new Collapse(this, options))) - if (typeof option == 'string') data[option]() - }) - } - - var old = $.fn.collapse - - $.fn.collapse = Plugin - $.fn.collapse.Constructor = Collapse - - - // COLLAPSE NO CONFLICT - // ==================== - - $.fn.collapse.noConflict = function () { - $.fn.collapse = old - return this - } - - - // COLLAPSE DATA-API - // ================= - - $(document).on('click.bs.collapse.data-api', '[data-toggle="collapse"]', function (e) { - var href + function Plugin(option) { + return this.each(function () { var $this = $(this) - var target = $this.attr('data-target') - || e.preventDefault() - || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7 - var $target = $(target) - var data = $target.data('bs.collapse') - var option = data ? 'toggle' : $this.data() - var parent = $this.attr('data-parent') - var $parent = parent && $(parent) + var data = $this.data('bs.collapse') + var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option) - if (!data || !data.transitioning) { - if ($parent) $parent.find('[data-toggle="collapse"][data-parent="' + parent + '"]').not($this).addClass('collapsed') - $this[$target.hasClass('in') ? 'addClass' : 'removeClass']('collapsed') - } - - Plugin.call($target, option) + if (!data && options.toggle && option == 'show') option = !option + if (!data) $this.data('bs.collapse', (data = new Collapse(this, options))) + if (typeof option == 'string') data[option]() }) + } + var old = $.fn.collapse + + $.fn.collapse = Plugin + $.fn.collapse.Constructor = Collapse + + + // COLLAPSE NO CONFLICT + // ==================== + + $.fn.collapse.noConflict = function () { + $.fn.collapse = old + return this + } + + + // COLLAPSE DATA-API + // ================= + + $(document).on('click.bs.collapse.data-api', '[data-toggle="collapse"]', function (e) { + var href + var $this = $(this) + var target = $this.attr('data-target') + || e.preventDefault() + || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7 + var $target = $(target) + var data = $target.data('bs.collapse') + var option = data ? 'toggle' : $this.data() + var parent = $this.attr('data-parent') + var $parent = parent && $(parent) + + if (!data || !data.transitioning) { + if ($parent) $parent.find('[data-toggle="collapse"][data-parent="' + parent + '"]').not($this).addClass('collapsed') + $this[$target.hasClass('in') ? 'addClass' : 'removeClass']('collapsed') + } + + Plugin.call($target, option) }) -}(); +}(jQuery); diff --git a/js/dropdown.js b/js/dropdown.js index 704eda96c0..fe769db912 100644 --- a/js/dropdown.js +++ b/js/dropdown.js @@ -7,151 +7,145 @@ * ======================================================================== */ -+function () { 'use strict'; ++function ($) { + 'use strict'; - (function (o_o) { - typeof define == 'function' && define.amd ? define(['jquery'], o_o) : - typeof exports == 'object' ? o_o(require('jquery')) : o_o(jQuery) - })(function ($) { + // DROPDOWN CLASS DEFINITION + // ========================= - // DROPDOWN CLASS DEFINITION - // ========================= + var backdrop = '.dropdown-backdrop' + var toggle = '[data-toggle="dropdown"]' + var Dropdown = function (element) { + $(element).on('click.bs.dropdown', this.toggle) + } - var backdrop = '.dropdown-backdrop' - var toggle = '[data-toggle="dropdown"]' - var Dropdown = function (element) { - $(element).on('click.bs.dropdown', this.toggle) + Dropdown.VERSION = '3.1.1' + + Dropdown.prototype.toggle = function (e) { + var $this = $(this) + + if ($this.is('.disabled, :disabled')) return + + var $parent = getParent($this) + var isActive = $parent.hasClass('open') + + clearMenus() + + if (!isActive) { + if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) { + // if mobile we use a backdrop because click events don't delegate + $('