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/affix.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/affix.js')
| -rw-r--r-- | js/affix.js | 192 |
1 files changed, 93 insertions, 99 deletions
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); |
