]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Use pull request #10988 from DanielRuf/fix/magellan-update-active for v6.5.0
authorDaniel Ruf <daniel@daniel-ruf.de>
Sat, 16 Jun 2018 07:26:06 +0000 (09:26 +0200)
committerNicolas Coden <nicolas@ncoden.fr>
Sat, 16 Jun 2018 07:26:06 +0000 (09:26 +0200)
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 <nicolas@ncoden.fr>
Signed-off-by: Nicolas Coden <nicolas@ncoden.fr>
js/foundation.magellan.js
test/javascript/components/magellan.js

index 01f9785e7764d5da4834192988a522facac1d377..93ae3306fe14c8c78de95efdf2c87f1f383da30f 100644 (file)
@@ -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();
     })
   }
 
index 23e6d4f5edffc25a70651046bfdea5ac5bea4017..243c201ffc6f4b32b9487b51fa1ee8a777970b6b 100644 (file)
@@ -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
+});