Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

In large screens we may hit the bottom of the page and dont reach the…

… top of the last magellan-destination, so lets force it

also did some more var caching
  • Loading branch information...
commit 7ce593eaaed3d7b41ca2b4b4d485d177eec2f5fa 1 parent a922040
@BMCouto authored
Showing with 29 additions and 22 deletions.
  1. +29 −22 vendor/assets/javascripts/foundation/jquery.foundation.magellan.js
View
51 vendor/assets/javascripts/foundation/jquery.foundation.magellan.js
@@ -12,24 +12,26 @@
'use strict';
$.fn.foundationMagellan = function(options) {
- var $fixedMagellan = $('[data-magellan-expedition=fixed]'),
+ var $window = $(window),
+ $document = $(document),
+ $fixedMagellan = $('[data-magellan-expedition=fixed]'),
defaults = {
- threshold: ($fixedMagellan.length) ? $fixedMagellan.outerHeight(true) : 25,
- activeClass: 'active'
- },
-
- options = $.extend({}, defaults, options);
-
+ threshold: ($fixedMagellan.length) ? $fixedMagellan.outerHeight(true) : 0,
+ activeClass: 'active'
+ },
+ options = $.extend({}, defaults, options);
+
// Indicate we have arrived at a destination
- $(document).on('magellan.arrival', '[data-magellan-arrival]', function(e) {
- var $expedition = $(this).closest('[data-magellan-expedition]'),
- activeClass = $expedition.attr('data-magellan-active-class') || options.activeClass;
- $(this)
+ $document.on('magellan.arrival', '[data-magellan-arrival]', function(e) {
+ var $destination = $(this),
+ $expedition = $destination.closest('[data-magellan-expedition]'),
+ activeClass = $expedition.attr('data-magellan-active-class') || options.activeClass;
+ $destination
.closest('[data-magellan-expedition]')
.find('[data-magellan-arrival]')
.not(this)
.removeClass(activeClass);
- $(this).addClass(activeClass);
+ $destination.addClass(activeClass);
});
// Set starting point as the current destination
@@ -42,16 +44,15 @@
var $el = $(this);
$el.data("magellan-fixed-position","");
$el.data("magellan-top-offset", "");
- });
+ })
+ .trigger('magellan.update-position');
- $fixedMagellan.trigger('magellan.update-position');
-
- $(window).on('resize.magellan', function() {
+ $window.on('resize.magellan', function() {
$fixedMagellan.trigger('magellan.update-position');
});
- $(window).on('scroll.magellan', function() {
- var windowScrollTop = $(window).scrollTop();
+ $window.on('scroll.magellan', function() {
+ var windowScrollTop = $window.scrollTop();
$fixedMagellan.each(function() {
var $expedition = $(this);
if ($expedition.data("magellan-top-offset") === "") {
@@ -70,15 +71,21 @@
});
// Determine when a destination has been reached, ah0y!
- $(window).on('scroll.magellan', function(e){
- var windowScrollTop = $(window).scrollTop();
+ var $lastDestination = $('[data-magellan-destination]:last');
+ $window.on('scroll.magellan', function(e){
+ var windowScrollTop = $window.scrollTop(),
+ scrolltopPlusHeight = windowScrollTop+$window.outerHeight(true),
+ lastDestinationTop = Math.ceil($lastDestination.offset().top);
$('[data-magellan-destination]').each(function(){
var $destination = $(this),
destination_name = $destination.attr('data-magellan-destination'),
topOffset = $destination.offset().top - windowScrollTop;
if (topOffset <= options.threshold) {
- $('[data-magellan-arrival=' + destination_name + ']')
- .trigger('magellan.arrival');
+ $('[data-magellan-arrival=' + destination_name + ']').trigger('magellan.arrival');
+ }
+ // In large screens we may hit the bottom of the page and dont reach the top of the last magellan-destination, so lets force it
+ if (scrolltopPlusHeight >= $document.outerHeight(true) && lastDestinationTop > windowScrollTop && lastDestinationTop < scrolltopPlusHeight) {
+ $('[data-magellan-arrival]:last').trigger('magellan.arrival');
}
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.