From: Aleksey V. Zapparov Date: Mon, 2 Sep 2013 01:24:27 +0000 (+0200) Subject: Pass $element to offset top/bottom calc funcs X-Git-Tag: v3.1.0~136^2~26^2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=626cef9fa40a3759753383ff61d5ebde32bd9a18;p=thirdparty%2Fbootstrap.git Pass $element to offset top/bottom calc funcs At the moment to make dynamic top offset calculator on multiple elements, one would write: ``` javascript $('.my-affix').each(function () { var $el = $(this); $el.affix({ offset: { top: function () { return $el.offset().top; } } }); }) ``` This patch will allow to: ``` javascript $('.my-affix').affix({ offset: { top: function ($el) { return $el.offset().top; } } }); ``` --- diff --git a/js/affix.js b/js/affix.js index c7be96e1dd..84760779d5 100644 --- a/js/affix.js +++ b/js/affix.js @@ -57,8 +57,8 @@ var offsetBottom = offset.bottom if (typeof offset != 'object') offsetBottom = offsetTop = offset - if (typeof offsetTop == 'function') offsetTop = offset.top() - if (typeof offsetBottom == 'function') offsetBottom = offset.bottom() + 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' :