Browse Source

Iterations on visibility, getting ready for docs

pull/1875/head
jlukic 9 years ago
parent
commit
dec01c0ada
3 changed files with 71 additions and 36 deletions
  1. 65
      src/definitions/behaviors/visibility.js
  2. 41
      src/definitions/modules/sticky.js
  3. 1
      src/definitions/modules/transition.js

65
src/definitions/behaviors/visibility.js

@ -52,6 +52,7 @@ $.fn.visibility = function(parameters) {
|| function(callback) { setTimeout(callback, 0); }, || function(callback) { setTimeout(callback, 0); },
element = this, element = this,
observer,
module module
; ;
@ -73,6 +74,9 @@ $.fn.visibility = function(parameters) {
} }
} }
module.checkVisibility(); module.checkVisibility();
if(settings.observeChanges) {
module.observeChanges();
}
module.instantiate(); module.instantiate();
}, },
@ -92,6 +96,26 @@ $.fn.visibility = function(parameters) {
; ;
}, },
observeChanges: function() {
var
context = $context[0]
;
if('MutationObserver' in window) {
observer = new MutationObserver(function(mutations) {
clearTimeout(module.timer);
module.timer = setTimeout(function() {
module.verbose('DOM tree modified, updating visibility calculations');
module.refresh();
}, 20);
});
observer.observe(element, {
childList : true,
subtree : true
});
module.debug('Setting up mutation observer', observer);
}
},
bindEvents: function() { bindEvents: function() {
module.verbose('Binding visibility events to scroll and resize'); module.verbose('Binding visibility events to scroll and resize');
$window $window
@ -236,6 +260,15 @@ $.fn.visibility = function(parameters) {
} }
}, },
is: {
visible: function() {
if(module.cache && module.cache.element) {
return (module.cache.element.height > 0 && module.cache.element.width > 0);
}
return false;
}
},
refresh: function() { refresh: function() {
module.debug('Refreshing constants (element width/height)'); module.debug('Refreshing constants (element width/height)');
module.reset(); module.reset();
@ -256,22 +289,24 @@ $.fn.visibility = function(parameters) {
module.verbose('Checking visibility of element', module.cache.element); module.verbose('Checking visibility of element', module.cache.element);
module.save.calculations(); module.save.calculations();
// percentage
module.passed();
if( module.is.visible() ) {
// percentage
module.passed();
// reverse (must be first)
module.passingReverse();
module.topVisibleReverse();
module.bottomVisibleReverse();
module.topPassedReverse();
module.bottomPassedReverse();
// reverse (must be first)
module.passingReverse();
module.topVisibleReverse();
module.bottomVisibleReverse();
module.topPassedReverse();
module.bottomPassedReverse();
// one time
module.passing();
module.topVisible();
module.bottomVisible();
module.topPassed();
module.bottomPassed();
// one time
module.passing();
module.topVisible();
module.bottomVisible();
module.topPassed();
module.bottomPassed();
}
}, },
passed: function(amount, newCallback) { passed: function(amount, newCallback) {
@ -918,6 +953,8 @@ $.fn.visibility.settings = {
fixed: 'fixed' fixed: 'fixed'
}, },
observeChanges : true,
debug : false, debug : false,
verbose : false, verbose : false,
performance : true, performance : true,

41
src/definitions/modules/sticky.js

@ -91,8 +91,9 @@ $.fn.sticky = function(parameters) {
$scroll $scroll
.on('scroll' + eventNamespace, module.event.scroll) .on('scroll' + eventNamespace, module.event.scroll)
; ;
module.observeChanges();
if(settings.observeChanges) {
module.observeChanges();
}
module.instantiate(); module.instantiate();
}, },
@ -125,25 +126,23 @@ $.fn.sticky = function(parameters) {
var var
context = $context[0] context = $context[0]
; ;
if(settings.observeChanges) {
if('MutationObserver' in window) {
observer = new MutationObserver(function(mutations) {
clearTimeout(module.timer);
module.timer = setTimeout(function() {
module.verbose('DOM tree modified, updating sticky menu');
module.refresh();
}, 200);
});
observer.observe(element, {
childList : true,
subtree : true
});
observer.observe(context, {
childList : true,
subtree : true
});
module.debug('Setting up mutation observer', observer);
}
if('MutationObserver' in window) {
observer = new MutationObserver(function(mutations) {
clearTimeout(module.timer);
module.timer = setTimeout(function() {
module.verbose('DOM tree modified, updating sticky menu');
module.refresh();
}, 20);
});
observer.observe(element, {
childList : true,
subtree : true
});
observer.observe(context, {
childList : true,
subtree : true
});
module.debug('Setting up mutation observer', observer);
} }
}, },

1
src/definitions/modules/transition.js

@ -394,7 +394,6 @@ $.fn.transition = function() {
} }
if(module.cache.style) { if(module.cache.style) {
module.verbose('Restoring original style attribute', module.cache.style); module.verbose('Restoring original style attribute', module.cache.style);
console.log('restoring cache', module.cache.style);
$module.attr('style', module.cache.style); $module.attr('style', module.cache.style);
} }
if(module.is.looping()) { if(module.is.looping()) {

Loading…
Cancel
Save