From c2c19a4d2d45d8ccb5c84d293dea35a94148c9a4 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 23 Jun 2014 11:07:18 -0700 Subject: [PATCH] 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 | 192 ++++----- js/alert.js | 118 +++-- js/button.js | 154 ++++--- js/carousel.js | 344 ++++++++------- js/collapse.js | 240 +++++------ js/dropdown.js | 204 +++++---- js/modal.js | 410 +++++++++--------- js/popover.js | 156 ++++--- js/scrollspy.js | 260 ++++++----- js/tab.js | 182 ++++---- js/tooltip.js | 696 +++++++++++++++--------------- js/transition.js | 86 ++-- 17 files changed, 1491 insertions(+), 1563 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 31f287960f25..66ee6975c08a 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 74e45e49d0b6..aa9bbb175317 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 5bbb0b64bbda..f04908e31f6c 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 5b481cfb221f..619690a68698 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 8a9391fdd038..a59e1d00a113 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 ab215bb818b7..5af32fee640f 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 - }) - } + if (affix == 'bottom') { + this.$element.offset({ + top: scrollHeight - this.$element.height() - offsetBottom + }) } + } - // AFFIX PLUGIN DEFINITION - // ======================= + // 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 + 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 (!data) $this.data('bs.affix', (data = new Affix(this, options))) + if (typeof option == 'string') data[option]() + }) + } - var old = $.fn.affix + var old = $.fn.affix - $.fn.affix = Plugin - $.fn.affix.Constructor = Affix + $.fn.affix = Plugin + $.fn.affix.Constructor = Affix - // AFFIX NO CONFLICT - // ================= + // AFFIX NO CONFLICT + // ================= - $.fn.affix.noConflict = function () { - $.fn.affix = old - return this - } + $.fn.affix.noConflict = function () { + $.fn.affix = old + return this + } - // AFFIX DATA-API - // ============== + // AFFIX DATA-API + // ============== - $(window).on('load', function () { - $('[data-spy="affix"]').each(function () { - var $spy = $(this) - var data = $spy.data() + $(window).on('load', function () { + $('[data-spy="affix"]').each(function () { + var $spy = $(this) + var data = $spy.data() - data.offset = data.offset || {} + data.offset = data.offset || {} - if (data.offsetBottom) data.offset.bottom = data.offsetBottom - if (data.offsetTop) data.offset.top = data.offsetTop + if (data.offsetBottom) data.offset.bottom = data.offsetBottom + if (data.offsetTop) data.offset.top = data.offsetTop - Plugin.call($spy, data) - }) + Plugin.call($spy, data) }) - }) -}(); +}(jQuery); diff --git a/js/alert.js b/js/alert.js index f34f84a289cb..721e9aa4771b 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.VERSION = '3.1.1' - Alert.prototype.close = function (e) { - var $this = $(this) - var selector = $this.attr('data-target') + 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 - } - - var $parent = $(selector) + if (!selector) { + selector = $this.attr('href') + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 + } - if (e) e.preventDefault() + var $parent = $(selector) - if (!$parent.length) { - $parent = $this.hasClass('alert') ? $this : $this.parent() - } + if (e) e.preventDefault() - $parent.trigger(e = $.Event('close.bs.alert')) + if (!$parent.length) { + $parent = $this.hasClass('alert') ? $this : $this.parent() + } - if (e.isDefaultPrevented()) return + $parent.trigger(e = $.Event('close.bs.alert')) - $parent.removeClass('in') + if (e.isDefaultPrevented()) return - function removeElement() { - // detach from parent, fire event then clean up data - $parent.detach().trigger('closed.bs.alert').remove() - } + $parent.removeClass('in') - $.support.transition && $parent.hasClass('fade') ? - $parent - .one('bsTransitionEnd', removeElement) - .emulateTransitionEnd(150) : - removeElement() + 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() + } - // ALERT PLUGIN DEFINITION - // ======================= - function Plugin(option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.alert') + // ALERT PLUGIN DEFINITION + // ======================= - if (!data) $this.data('bs.alert', (data = new Alert(this))) - if (typeof option == 'string') data[option].call($this) - }) - } + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.alert') - var old = $.fn.alert + if (!data) $this.data('bs.alert', (data = new Alert(this))) + if (typeof option == 'string') data[option].call($this) + }) + } - $.fn.alert = Plugin - $.fn.alert.Constructor = Alert + var old = $.fn.alert + $.fn.alert = Plugin + $.fn.alert.Constructor = Alert - // ALERT NO CONFLICT - // ================= - $.fn.alert.noConflict = function () { - $.fn.alert = old - return this - } + // ALERT NO CONFLICT + // ================= + $.fn.alert.noConflict = function () { + $.fn.alert = old + return this + } - // ALERT DATA-API - // ============== - $(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close) + // 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 e96788c05e43..aa7145072289 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.DEFAULTS = { - loadingText: 'loading...' - } + Button.VERSION = '3.1.1' - Button.prototype.setState = function (state) { - var d = 'disabled' - var $el = this.$element - var val = $el.is('input') ? 'val' : 'html' - var data = $el.data() + Button.DEFAULTS = { + loadingText: 'loading...' + } - state = state + 'Text' + Button.prototype.setState = function (state) { + var d = 'disabled' + var $el = this.$element + var val = $el.is('input') ? 'val' : 'html' + var data = $el.data() - if (data.resetText == null) $el.data('resetText', $el[val]()) + state = state + 'Text' - $el[val](data[state] == null ? this.options[state] : data[state]) + if (data.resetText == null) $el.data('resetText', $el[val]()) - // 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) - } + $el[val](data[state] == null ? this.options[state] : data[state]) - 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) } - - if (changed) this.$element.toggleClass('active') + }, 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') } + if (changed) this.$element.toggleClass('active') + } - // 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 + // BUTTON PLUGIN DEFINITION + // ======================== - if (!data) $this.data('bs.button', (data = new Button(this, options))) + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.button') + var options = typeof option == 'object' && option - if (option == 'toggle') data.toggle() - else if (option) data.setState(option) - }) - } + if (!data) $this.data('bs.button', (data = new Button(this, options))) - var old = $.fn.button + if (option == 'toggle') data.toggle() + else if (option) data.setState(option) + }) + } - $.fn.button = Plugin - $.fn.button.Constructor = Button + var old = $.fn.button + $.fn.button = Plugin + $.fn.button.Constructor = Button - // BUTTON NO CONFLICT - // ================== - $.fn.button.noConflict = function () { - $.fn.button = old - return this - } + // 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() - }) + // 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 7418ec5f5135..d7727bcce68a 100644 --- a/js/carousel.js +++ b/js/carousel.js @@ -7,222 +7,216 @@ * ======================================================================== */ -+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 - // ========================= - - 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)) ++function ($) { + 'use strict'; + + // 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 + + 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) - 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() - } + this.options.interval + && !this.paused + && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) - Carousel.prototype.cycle = function (e) { - e || (this.paused = false) + return this + } - this.interval && clearInterval(this.interval) + Carousel.prototype.getItemIndex = function (item) { + this.$items = item.parent().children('.item') + return this.$items.index(item || this.$active) + } - this.options.interval - && !this.paused - && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) + Carousel.prototype.to = function (pos) { + var that = this + var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active')) - return this - } + 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.getItemIndex = function (item) { - this.$items = item.parent().children('.item') - return this.$items.index(item || this.$active) + 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.to = function (pos) { - var that = this - var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active')) + this.interval = clearInterval(this.interval) + + return this + } + + Carousel.prototype.next = function () { + if (this.sliding) return + return this.slide('next') + } - if (pos > (this.$items.length - 1) || pos < 0) return + Carousel.prototype.prev = function () { + if (this.sliding) return + return this.slide('prev') + } - if (this.sliding) return this.$element.one('slid.bs.carousel', function () { that.to(pos) }) // yes, "slid" - if (activeIndex == pos) return this.pause().cycle() + 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 - return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos])) + if (!$next.length) { + if (!this.options.wrap) return + $next = this.$element.find('.item')[fallback]() } - Carousel.prototype.pause = function (e) { - e || (this.paused = true) + if ($next.hasClass('active')) return (this.sliding = false) - if (this.$element.find('.next, .prev').length && $.support.transition) { - this.$element.trigger($.support.transition.end) - this.cycle(true) - } + var relatedTarget = $next[0] + var slideEvent = $.Event('slide.bs.carousel', { + relatedTarget: relatedTarget, + direction: direction + }) + this.$element.trigger(slideEvent) + if (slideEvent.isDefaultPrevented()) return - this.interval = clearInterval(this.interval) + this.sliding = true - return this - } + isCycling && this.pause() - Carousel.prototype.next = function () { - if (this.sliding) return - return this.slide('next') + if (this.$indicators.length) { + this.$indicators.find('.active').removeClass('active') + var $nextIndicator = $(this.$indicators.children()[this.getItemIndex($next)]) + $nextIndicator && $nextIndicator.addClass('active') } - Carousel.prototype.prev = function () { - if (this.sliding) return - return this.slide('prev') + 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.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 - } + isCycling && this.cycle() + return this + } - // 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 + // CAROUSEL PLUGIN DEFINITION + // ========================== - 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() - }) - } + 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 + var old = $.fn.carousel - $.fn.carousel = Plugin - $.fn.carousel.Constructor = Carousel + $.fn.carousel = Plugin + $.fn.carousel.Constructor = Carousel - // CAROUSEL NO CONFLICT - // ==================== + // CAROUSEL NO CONFLICT + // ==================== - $.fn.carousel.noConflict = function () { - $.fn.carousel = old - return this - } + $.fn.carousel.noConflict = function () { + $.fn.carousel = old + return this + } - // CAROUSEL DATA-API - // ================= + // 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 + $(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) + Plugin.call($target, options) - if (slideIndex) { - $target.data('bs.carousel').to(slideIndex) - } + if (slideIndex) { + $target.data('bs.carousel').to(slideIndex) + } - e.preventDefault() - }) + e.preventDefault() + }) - $(window).on('load', function () { - $('[data-ride="carousel"]').each(function () { - var $carousel = $(this) - Plugin.call($carousel, $carousel.data()) - }) + $(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 c67939a7debd..eb688f480669 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.VERSION = '3.1.1' + Collapse.DEFAULTS = { + toggle: true + } - Collapse.DEFAULTS = { - toggle: true - } + Collapse.prototype.dimension = function () { + var hasWidth = this.$element.hasClass('width') + return hasWidth ? 'width' : 'height' + } - 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 - 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 startEvent = $.Event('show.bs.collapse') - this.$element.trigger(startEvent) - if (startEvent.isDefaultPrevented()) return + var actives = this.$parent && this.$parent.find('> .panel > .in') - 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() - 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) - } + this.$element + .removeClass('collapse') + .addClass('collapsing')[dimension](0) - var dimension = this.dimension() + this.transitioning = 1 + var complete = function () { + this.$element + .removeClass('collapsing') + .addClass('collapse in')[dimension]('') + this.transitioning = 0 this.$element - .removeClass('collapse') - .addClass('collapsing')[dimension](0) + .trigger('shown.bs.collapse') + } - this.transitioning = 1 + if (!$.support.transition) return complete.call(this) - var complete = function () { - this.$element - .removeClass('collapsing') - .addClass('collapse in')[dimension]('') - this.transitioning = 0 - this.$element - .trigger('shown.bs.collapse') - } + var scrollSize = $.camelCase(['scroll', dimension].join('-')) - if (!$.support.transition) return complete.call(this) + this.$element + .one('bsTransitionEnd', $.proxy(complete, this)) + .emulateTransitionEnd(350)[dimension](this.$element[0][scrollSize]) + } - var scrollSize = $.camelCase(['scroll', dimension].join('-')) + Collapse.prototype.hide = function () { + if (this.transitioning || !this.$element.hasClass('in')) return - this.$element - .one('bsTransitionEnd', $.proxy(complete, this)) - .emulateTransitionEnd(350)[dimension](this.$element[0][scrollSize]) - } + var startEvent = $.Event('hide.bs.collapse') + this.$element.trigger(startEvent) + if (startEvent.isDefaultPrevented()) return - Collapse.prototype.hide = function () { - if (this.transitioning || !this.$element.hasClass('in')) return + var dimension = this.dimension() - var startEvent = $.Event('hide.bs.collapse') - this.$element.trigger(startEvent) - if (startEvent.isDefaultPrevented()) return + this.$element[dimension](this.$element[dimension]())[0].offsetHeight - var dimension = this.dimension() + this.$element + .addClass('collapsing') + .removeClass('collapse') + .removeClass('in') - this.$element[dimension](this.$element[dimension]())[0].offsetHeight + this.transitioning = 1 + var complete = function () { + this.transitioning = 0 this.$element - .addClass('collapsing') - .removeClass('collapse') - .removeClass('in') + .trigger('hidden.bs.collapse') + .removeClass('collapsing') + .addClass('collapse') + } - this.transitioning = 1 + if (!$.support.transition) return complete.call(this) - var complete = function () { - this.transitioning = 0 - this.$element - .trigger('hidden.bs.collapse') - .removeClass('collapsing') - .addClass('collapse') - } + this.$element + [dimension](0) + .one('bsTransitionEnd', $.proxy(complete, this)) + .emulateTransitionEnd(350) + } - if (!$.support.transition) return complete.call(this) + Collapse.prototype.toggle = function () { + this[this.$element.hasClass('in') ? 'hide' : 'show']() + } - 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) - 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]() + }) + } - 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 - var old = $.fn.collapse + $.fn.collapse = Plugin + $.fn.collapse.Constructor = Collapse - $.fn.collapse = Plugin - $.fn.collapse.Constructor = Collapse + // COLLAPSE NO CONFLICT + // ==================== - // COLLAPSE NO CONFLICT - // ==================== + $.fn.collapse.noConflict = function () { + $.fn.collapse = old + return this + } - $.fn.collapse.noConflict = function () { - $.fn.collapse = old - return this - } + // COLLAPSE DATA-API + // ================= - // 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) - $(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) - }) + 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 704eda96c0aa..fe769db9120e 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.VERSION = '3.1.1' - Dropdown.prototype.toggle = function (e) { - var $this = $(this) + Dropdown.prototype.toggle = function (e) { + var $this = $(this) - if ($this.is('.disabled, :disabled')) return + if ($this.is('.disabled, :disabled')) return - var $parent = getParent($this) - var isActive = $parent.hasClass('open') + var $parent = getParent($this) + var isActive = $parent.hasClass('open') - clearMenus() + 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 - $('