From: Daniel Ruf Date: Sat, 16 Jun 2018 07:26:06 +0000 (+0200) Subject: Use pull request #10988 from DanielRuf/fix/magellan-update-active for v6.5.0 X-Git-Tag: v6.5.0-rc.1^2~109 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad1b5e4793d1d561e278b1c5f4fb4e6ae606da8c;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Use pull request #10988 from DanielRuf/fix/magellan-update-active for v6.5.0 9731ba470 fire updateActive after calcPoints e50e15bc2 remove unused code 6371c6da3 do less calculations to improve the performance e89d85cbf tests: make sure that the Magellan tests are properly running b2a1f1302 tests: revert to systematic test of magellan graceful failure 738903c31 clean: remove comment about a resolved bug in Magellan tests Co-Authored-By: Nicolas Coden Signed-off-by: Nicolas Coden --- diff --git a/js/foundation.magellan.js b/js/foundation.magellan.js index 01f9785e7..93ae3306f 100644 --- a/js/foundation.magellan.js +++ b/js/foundation.magellan.js @@ -93,15 +93,28 @@ class Magellan extends Plugin { _this._updateActive(); }); - this.$element.on({ - 'resizeme.zf.trigger': this.reflow.bind(this), - 'scrollme.zf.trigger': this._updateActive.bind(this) - }).on('click.zf.magellan', 'a[href^="#"]', function(e) { + if (document.readyState === "complete") { + _this.$element.on({ + 'resizeme.zf.trigger': _this.reflow.bind(_this), + 'scrollme.zf.trigger': _this._updateActive.bind(_this) + }).on('click.zf.magellan', 'a[href^="#"]', function(e) { e.preventDefault(); - var arrival = this.getAttribute('href'); + var arrival = _this.getAttribute('href'); _this.scrollToLoc(arrival); }); - + } else { + $(window).one('load', function(){ + _this.$element.on({ + 'resizeme.zf.trigger': _this.reflow.bind(_this), + 'scrollme.zf.trigger': _this._updateActive.bind(_this) + }).on('click.zf.magellan', 'a[href^="#"]', function(e) { + e.preventDefault(); + var arrival = _this.getAttribute('href'); + _this.scrollToLoc(arrival); + }); + }); + } + this._deepLinkScroll = function(e) { if(_this.options.deepLinking) { _this.scrollToLoc(window.location.hash); @@ -129,7 +142,6 @@ class Magellan extends Plugin { SmoothScroll.scrollToLoc(loc, options, function() { _this._inTransition = false; - _this._updateActive(); }) } diff --git a/test/javascript/components/magellan.js b/test/javascript/components/magellan.js index 23e6d4f5e..243c201ff 100644 --- a/test/javascript/components/magellan.js +++ b/test/javascript/components/magellan.js @@ -1,6 +1,6 @@ describe('Magellan', function() { var plugin; - var $html, $content; + var $html, $content; var generateUl = function(count) { var html = ''; @@ -52,20 +52,17 @@ describe('Magellan', function() { animationDuration: duration }); - - // Jump to last section var target = $html.find('a').eq(-1).attr('href'); - plugin.scrollToLoc(target); + plugin.scrollToLoc(target); - // The `update` event doesn't work properly because it fires too often setTimeout(function() { - var isInViewport = false; - if ($content.find('div').eq(-1).offset().top > $('body').scrollTop() && $content.offset().top < $('body').scrollTop() + $('body').innerHeight()) { - isInViewport = true; - } - isInViewport.should.equal(true); - done(); + var isInViewport = false; + if ($content.find('div').eq(-1).offset().top > $('body').scrollTop() && $content.offset().top < $('body').scrollTop() + $('body').innerHeight()) { + isInViewport = true; + } + isInViewport.should.equal(true); + done(); }, duration); }); @@ -80,16 +77,17 @@ describe('Magellan', function() { }); var hasError = false; + var targets = $html.find('a'); try { - var target = $html.find('a').eq(-1).attr('href'); - plugin.scrollToLoc(target); - } catch (err) { - hasError = true; + var target = $(targets).eq(-1).attr('href'); + plugin.scrollToLoc(target); + } + catch (err) { + hasError = true; } hasError.should.equal(false); - }); }); -}); \ No newline at end of file +});