From: g.chanaud Date: Sat, 30 Apr 2016 16:59:32 +0000 (+0200) Subject: [Bugfix] Correct anchor offset when using only one of data-top-anchor data-btm-anchor X-Git-Tag: v6.2.2-rc1~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F8716%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git [Bugfix] Correct anchor offset when using only one of data-top-anchor data-btm-anchor --- diff --git a/js/foundation.sticky.js b/js/foundation.sticky.js index cfe356ffc..134253c05 100644 --- a/js/foundation.sticky.js +++ b/js/foundation.sticky.js @@ -66,31 +66,27 @@ class Sticky { * @private */ _parsePoints() { - var top = this.options.topAnchor, - btm = this.options.btmAnchor, + var top = this.options.topAnchor == "" ? 1 : this.options.topAnchor, + btm = this.options.btmAnchor== "" ? document.documentElement.scrollHeight : this.options.btmAnchor, pts = [top, btm], breaks = {}; - if (top && btm) { - - for (var i = 0, len = pts.length; i < len && pts[i]; i++) { - var pt; - if (typeof pts[i] === 'number') { - pt = pts[i]; - } else { - var place = pts[i].split(':'), - anchor = $(`#${place[0]}`); - - pt = anchor.offset().top; - if (place[1] && place[1].toLowerCase() === 'bottom') { - pt += anchor[0].getBoundingClientRect().height; - } + for (var i = 0, len = pts.length; i < len && pts[i]; i++) { + var pt; + if (typeof pts[i] === 'number') { + pt = pts[i]; + } else { + var place = pts[i].split(':'), + anchor = $(`#${place[0]}`); + + pt = anchor.offset().top; + if (place[1] && place[1].toLowerCase() === 'bottom') { + pt += anchor[0].getBoundingClientRect().height; } - breaks[i] = pt; } - } else { - breaks = {0: 1, 1: document.documentElement.scrollHeight}; + breaks[i] = pt; } + this.points = breaks; return; }