diff options
| author | Chris Rebert <[email protected]> | 2014-06-23 11:07:18 -0700 |
|---|---|---|
| committer | Chris Rebert <[email protected]> | 2014-06-23 11:11:59 -0700 |
| commit | c2c19a4d2d45d8ccb5c84d293dea35a94148c9a4 (patch) | |
| tree | f12ed485a1a3f84ce60c6a195e8efca27f418042 /js/collapse.js | |
| parent | bc895a4b43ecfd2ad8c3793fdd6d8bada9d93186 (diff) | |
| download | bootstrap-c2c19a4d2d45d8ccb5c84d293dea35a94148c9a4.tar.xz bootstrap-c2c19a4d2d45d8ccb5c84d293dea35a94148c9a4.zip | |
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
Diffstat (limited to 'js/collapse.js')
| -rw-r--r-- | js/collapse.js | 240 |
1 files changed, 117 insertions, 123 deletions
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); |
