From 7627b24c1e6aa5301ee3f525dd931c2852e7ff0a Mon Sep 17 00:00:00 2001 From: breaddevil Date: Sun, 4 May 2014 11:24:31 +0200 Subject: replace js scrollspy test for default behavior --- js/tests/unit/scrollspy.js | 54 +++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 17 deletions(-) (limited to 'js') diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index 90c95d769..a36749f2e 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -25,23 +25,6 @@ $(function () { ok($(document.body).bootstrapScrollspy()[0] == document.body, 'document.body returned') }) - test('should switch active class on scroll', function () { - var sectionHTML = '
', - topbarHTML = '
' + - '
' + - '
' + - '

Bootstrap

' + - '
  • Overview
  • ' + - '' + - '
    ' + - '
    ' + - '
    ', - $topbar = $(topbarHTML).bootstrapScrollspy() - - $(sectionHTML).append('#qunit-fixture') - ok($topbar.find('.active', true)) - }) - test('should only switch active class on current target', function () { var sectionHTML = '
    ' + '
    ' + @@ -78,4 +61,41 @@ $(function () { $scrollSpy.scrollTop(350); ok($section.hasClass('active'), 'Active class still on root node') }) + + test('should add the active class to the correct element', function () { + var navbarHtml = + '' + var contentHtml = + '
    ' + + '
    div 1
    ' + + '
    div 2
    ' + + '
    ' + + $(navbarHtml).appendTo('#qunit-fixture') + var $content = $(contentHtml) + .appendTo('#qunit-fixture') + .bootstrapScrollspy({offset: 0, target: '.navbar'}) + + var testElementIsActiveAfterScroll = function (element, target) { + var deferred = $.Deferred() + var scrollHeight = $content.scrollTop() + $(target).position().top + stop() + $content.one('scroll', function () { + ok($(element).hasClass('active'), 'target:' + target + ', element' + element) + start() + deferred.resolve() + }) + $content.scrollTop(scrollHeight) + return deferred.promise() + } + + $.when(testElementIsActiveAfterScroll('#li-1', '#div-1')) + .then(function () { return testElementIsActiveAfterScroll('#li-2', '#div-2') }) + }) + }) -- cgit v1.2.3 From ee12ce83057233d271f42162ef3dd2d42d315176 Mon Sep 17 00:00:00 2001 From: Max Kramer Date: Thu, 22 May 2014 18:13:41 -0400 Subject: Add aria-haspopup and aria-expanded attributes to dropdown plugin 1. Add aria-haspopup="true" and aria-expanded="false" to dropdown docs 2. Toggle aria-expanded between "true" and "false" when opening and closing dropdown Satisfy item 1 from https://github.com/paypal/bootstrap-accessibility-plugin#dropdown. See #13553. --- js/dropdown.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/dropdown.js b/js/dropdown.js index bc671fef0..1924f70ae 100644 --- a/js/dropdown.js +++ b/js/dropdown.js @@ -42,7 +42,9 @@ if (e.isDefaultPrevented()) return - $this.trigger('focus') + $this + .trigger('focus') + .attr('aria-expanded', 'true') $parent .toggleClass('open') @@ -88,11 +90,13 @@ if (e && e.which === 3) return $(backdrop).remove() $(toggle).each(function () { - var $parent = getParent($(this)) + var $this = $(this) + var $parent = getParent($this) var relatedTarget = { relatedTarget: this } if (!$parent.hasClass('open')) return $parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget)) if (e.isDefaultPrevented()) return + $this.attr('aria-expanded', 'false') $parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget) }) } -- cgit v1.2.3 From f071549c8408241b88a95192e477816d2402eb6e Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Thu, 22 May 2014 09:00:19 -0700 Subject: fix #13386 --- js/carousel.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js') diff --git a/js/carousel.js b/js/carousel.js index 05631f7a3..d3e7e52b4 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 -- cgit v1.2.3 From 1b63d0b9ba0fad04a8428d27bc1d141079bdfa7b Mon Sep 17 00:00:00 2001 From: Erwan Jegouzo Date: Tue, 10 Jun 2014 17:36:03 -0400 Subject: fix for #13747 Closes #13782 by merging it. --- js/tooltip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/tooltip.js b/js/tooltip.js index 38940a384..c62a5061a 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -202,10 +202,10 @@ var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight) this.applyPlacement(calculatedOffset, placement) - this.hoverState = null var complete = function () { that.$element.trigger('shown.bs.' + that.type) + that.hoverState = null } $.support.transition && this.$tip.hasClass('fade') ? -- cgit v1.2.3 From 09c2e41ec4c7f3892ee3568f70bf5aef7245cdb2 Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Thu, 19 Jun 2014 11:40:56 +0200 Subject: Remove deprecated JSCS rules and add requireSpaceAfterLineComment --- js/.jscsrc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/.jscsrc b/js/.jscsrc index e6eb84560..5b481cfb2 100644 --- a/js/.jscsrc +++ b/js/.jscsrc @@ -1,12 +1,12 @@ { "disallowEmptyBlocks": true, "disallowKeywords": ["with"], - "disallowLeftStickedOperators": ["?", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], "disallowMixedSpacesAndTabs": true, "disallowMultipleLineStrings": true, "disallowMultipleVarDecl": true, "disallowQuotedKeysInObjects": "allButReserved", - "disallowRightStickedOperators": ["?", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], + "disallowSpaceAfterPrefixUnaryOperators": ["!"], + "disallowSpaceBeforeBinaryOperators": [","], "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], "disallowSpacesInNamedFunctionExpression": { "beforeOpeningRoundBrace": true }, @@ -17,13 +17,13 @@ "requireCapitalizedConstructors": true, "requireCommaBeforeLineBreak": true, "requireDotNotation": true, - "requireLeftStickedOperators": [","], "requireLineFeedAtFileEnd": true, - "requireRightStickedOperators": ["!"], "requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", "<", ">=", "<="], "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"], + "requireSpaceAfterLineComment": true, "requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", "<", ">=", "<="], "requireSpacesInAnonymousFunctionExpression": { "beforeOpeningCurlyBrace": true, "beforeOpeningRoundBrace": true }, + "requireSpacesInConditionalExpression": true, "requireSpacesInFunctionDeclaration": { "beforeOpeningCurlyBrace": true }, "requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true }, "requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true }, -- cgit v1.2.3 From 587451ad9a2b288ed54857c6ac291609a6394c6f Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Thu, 19 Jun 2014 11:41:23 +0200 Subject: Update a few source files to comply to new JSCS rules --- js/carousel.js | 2 +- js/collapse.js | 2 +- js/dropdown.js | 2 +- js/modal.js | 4 ++-- js/tab.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'js') diff --git a/js/carousel.js b/js/carousel.js index 05631f7a3..7418ec5f5 100644 --- a/js/carousel.js +++ b/js/carousel.js @@ -202,7 +202,7 @@ $(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 $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 diff --git a/js/collapse.js b/js/collapse.js index d37b8898c..c67939a7d 100644 --- a/js/collapse.js +++ b/js/collapse.js @@ -156,7 +156,7 @@ var $this = $(this) var target = $this.attr('data-target') || e.preventDefault() - || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7 + || (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() diff --git a/js/dropdown.js b/js/dropdown.js index f4f6358cd..704eda96c 100644 --- a/js/dropdown.js +++ b/js/dropdown.js @@ -106,7 +106,7 @@ if (!selector) { selector = $this.attr('href') - selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 + selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 } var $parent = selector && $(selector) diff --git a/js/modal.js b/js/modal.js index 2241e7b1e..359e1fc67 100644 --- a/js/modal.js +++ b/js/modal.js @@ -267,13 +267,13 @@ $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) { var $this = $(this) var href = $this.attr('href') - var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7 + var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7 var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()) if ($this.is('a')) e.preventDefault() $target.one('show.bs.modal', function (showEvent) { - if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown + if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown $target.one('hidden.bs.modal', function () { $this.is(':visible') && $this.trigger('focus') }) diff --git a/js/tab.js b/js/tab.js index c8122157f..de93ec83f 100644 --- a/js/tab.js +++ b/js/tab.js @@ -30,7 +30,7 @@ if (!selector) { selector = $this.attr('href') - selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 } if ($this.parent('li').hasClass('active')) return -- cgit v1.2.3 From c2c19a4d2d45d8ccb5c84d293dea35a94148c9a4 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 23 Jun 2014 11:07:18 -0700 Subject: 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 --- 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 ++++--- 14 files changed, 1488 insertions(+), 1560 deletions(-) (limited to 'js') diff --git a/js/.jscsrc b/js/.jscsrc index 5b481cfb2..619690a68 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 8a9391fdd..a59e1d00a 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 ab215bb81..5af32fee6 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 f34f84a28..721e9aa47 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 e96788c05..aa7145072 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 7418ec5f5..d7727bcce 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 c67939a7d..eb688f480 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 704eda96c..fe769db91 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 - $('