From: Daniel Ruf Date: Wed, 28 Feb 2018 22:13:50 +0000 (+0100) Subject: do less calculations to improve the performance X-Git-Tag: v6.6.0~23^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf0a80bc54cbb476d7038e9bcd81a2b8e6aa50ff;p=thirdparty%2Ffoundation%2Ffoundation-sites.git do less calculations to improve the performance --- diff --git a/js/foundation.magellan.js b/js/foundation.magellan.js index db72c4b10..3732e9967 100644 --- a/js/foundation.magellan.js +++ b/js/foundation.magellan.js @@ -93,22 +93,31 @@ 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); - _this.calcPoints(); - _this._updateActive(); }); - + } 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); - _this.calcPoints(); - _this._updateActive(); } }; diff --git a/test/javascript/components/magellan.js b/test/javascript/components/magellan.js index 23e6d4f5e..42fc3ee0d 100644 --- a/test/javascript/components/magellan.js +++ b/test/javascript/components/magellan.js @@ -56,7 +56,9 @@ describe('Magellan', function() { // Jump to last section var target = $html.find('a').eq(-1).attr('href'); - plugin.scrollToLoc(target); + $html.one('load', function(){ + plugin.scrollToLoc(target); + }); // The `update` event doesn't work properly because it fires too often setTimeout(function() { @@ -82,7 +84,9 @@ describe('Magellan', function() { var hasError = false; try { var target = $html.find('a').eq(-1).attr('href'); - plugin.scrollToLoc(target); + $html.one('load', function(){ + plugin.scrollToLoc(target); + }); } catch (err) { hasError = true; }