From 09ecab67fc2f11a452b045e6530fae6e82067cbe Mon Sep 17 00:00:00 2001 From: Jack Lukic Date: Tue, 11 Aug 2015 13:47:47 -0400 Subject: [PATCH] #2710 merge and modify this context --- src/definitions/modules/sticky.js | 63 +++++++++++++++++-------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/definitions/modules/sticky.js b/src/definitions/modules/sticky.js index 7bd12ad86..3729a8dba 100644 --- a/src/definitions/modules/sticky.js +++ b/src/definitions/modules/sticky.js @@ -129,6 +129,7 @@ $.fn.sticky = function(parameters) { determineContainer: function() { $container = $module.offsetParent(); + console.log($container); }, determineContext: function() { @@ -390,8 +391,8 @@ $.fn.sticky = function(parameters) { }, size: function() { if(module.cache.element.height !== 0 && module.cache.element.width !== 0) { - $module.get(0).style.setProperty('width', module.cache.element.width + 'px', 'important'); - $module.get(0).style.setProperty('height', module.cache.element.height + 'px', 'important'); + element.style.setProperty('width', module.cache.element.width + 'px', 'important'); + element.style.setProperty('height', module.cache.element.height + 'px', 'important'); } } }, @@ -445,16 +446,17 @@ $.fn.sticky = function(parameters) { if(elementVisible) { if( module.is.initialPosition() ) { - if(scroll.top > context.bottom) { - module.debug('Element bottom of container'); + if(scroll.top >= context.bottom) { + module.debug('Initial element position is bottom of container'); module.bindBottom(); } else if(scroll.top > element.top) { - module.debug('Element passed, fixing element to page'); - if( (element.height + scroll.top - elementScroll) > context.bottom ) { + if( (element.height + scroll.top - elementScroll) >= context.bottom ) { + module.debug('Initial element position is bottom of container'); module.bindBottom(); } else { + module.debug('Initial element position is fixed'); module.fixTop(); } } @@ -464,11 +466,11 @@ $.fn.sticky = function(parameters) { // currently fixed top if( module.is.top() ) { - if( scroll.top < element.top ) { + if( scroll.top <= element.top ) { module.debug('Fixed element reached top of container'); module.setInitialPosition(); } - else if( (element.height + scroll.top - elementScroll) > context.bottom ) { + else if( (element.height + scroll.top - elementScroll) >= context.bottom ) { module.debug('Fixed element reached bottom of container'); module.bindBottom(); } @@ -484,12 +486,12 @@ $.fn.sticky = function(parameters) { else if(module.is.bottom() ) { // top edge - if( (scroll.bottom - element.height) < element.top) { + if( (scroll.bottom - element.height) <= element.top) { module.debug('Bottom fixed rail has reached top of container'); module.setInitialPosition(); } // bottom edge - else if(scroll.bottom > context.bottom) { + else if(scroll.bottom >= context.bottom) { module.debug('Bottom fixed rail has reached bottom of container'); module.bindBottom(); } @@ -504,13 +506,13 @@ $.fn.sticky = function(parameters) { } else if( module.is.bottom() ) { if(settings.pushing) { - if(module.is.bound() && scroll.bottom < context.bottom ) { + if(module.is.bound() && scroll.bottom <= context.bottom ) { module.debug('Fixing bottom attached element to bottom of browser.'); module.fixBottom(); } } else { - if(module.is.bound() && (scroll.top < context.bottom - element.height) ) { + if(module.is.bound() && (scroll.top <= context.bottom - element.height) ) { module.debug('Fixing bottom attached element to top of browser.'); module.fixTop(); } @@ -554,6 +556,7 @@ $.fn.sticky = function(parameters) { }, setInitialPosition: function() { + module.debug('Returning to initial position'); module.unfix(); module.unbind(); }, @@ -596,24 +599,28 @@ $.fn.sticky = function(parameters) { }, unbind: function() { - module.debug('Removing absolute position on element'); - module.remove.offset(); - $module - .removeClass(className.bound) - .removeClass(className.top) - .removeClass(className.bottom) - ; + if( module.is.bound() ) { + module.debug('Removing container bound position on element'); + module.remove.offset(); + $module + .removeClass(className.bound) + .removeClass(className.top) + .removeClass(className.bottom) + ; + } }, unfix: function() { - module.debug('Removing fixed position on element'); - module.remove.offset(); - $module - .removeClass(className.fixed) - .removeClass(className.top) - .removeClass(className.bottom) - ; - settings.onUnstick.call(element); + if( module.is.fixed() ) { + module.debug('Removing fixed position on element'); + module.remove.offset(); + $module + .removeClass(className.fixed) + .removeClass(className.top) + .removeClass(className.bottom) + ; + settings.onUnstick.call(element); + } }, reset: function() { @@ -819,7 +826,7 @@ $.fn.sticky.settings = { name : 'Sticky', namespace : 'sticky', - debug : false, + debug : true, verbose : true, performance : true,