]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Pass $element to offset top/bottom calc funcs 10359/head
authorAleksey V. Zapparov <ixti@member.fsf.org>
Mon, 2 Sep 2013 01:24:27 +0000 (03:24 +0200)
committerAleksey V. Zapparov <ixti@member.fsf.org>
Mon, 2 Sep 2013 01:24:27 +0000 (03:24 +0200)
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; }
  }
});
```

js/affix.js

index c7be96e1dd842f4506cd358853c37c186d88eb3e..84760779d5433a334d2279a8df3e07e6c9d726bc 100644 (file)
@@ -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' :