From ecbfa1de9391d51173e1901e6e2e3167a7f138f1 Mon Sep 17 00:00:00 2001 From: jlukic Date: Wed, 13 May 2015 13:01:45 -0400 Subject: [PATCH] Use slightly more performant triggerHandler for pub/sub --- src/definitions/behaviors/visibility.js | 17 ++++++++++------- src/definitions/modules/sticky.js | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/definitions/behaviors/visibility.js b/src/definitions/behaviors/visibility.js index 699c230c1..eda471c9e 100644 --- a/src/definitions/behaviors/visibility.js +++ b/src/definitions/behaviors/visibility.js @@ -103,7 +103,7 @@ $.fn.visibility = function(parameters) { observer.disconnect(); } $window - .off('load' + eventNamespace, module.event.load) + .off('load' + eventNamespace, module.event.load) .off('resize' + eventNamespace, module.event.resize) ; $context.off('scrollchange' + eventNamespace, module.event.scrollchange); @@ -137,13 +137,13 @@ $.fn.visibility = function(parameters) { events: function() { module.verbose('Binding visibility events to scroll and resize'); $window - .on('load' + eventNamespace, module.event.load) + .on('load' + eventNamespace, module.event.load) .on('resize' + eventNamespace, module.event.resize) ; // pub/sub pattern $context - .off('scroll' + eventNamespace) - .on('scroll' + eventNamespace, module.event.scroll) + .off('scroll' + eventNamespace) + .on('scroll' + eventNamespace, module.event.scroll) .on('scrollchange' + eventNamespace, module.event.scrollchange) ; }, @@ -195,12 +195,12 @@ $.fn.visibility = function(parameters) { if(settings.throttle) { clearTimeout(module.timer); module.timer = setTimeout(function() { - $context.trigger('scrollchange' + eventNamespace, [ $context.scrollTop() ]); + $context.triggerHandler('scrollchange' + eventNamespace, [ $context.scrollTop() ]); }, settings.throttle); } else { requestAnimationFrame(function() { - $context.trigger('scrollchange' + eventNamespace, [ $context.scrollTop() ]); + $context.triggerHandler('scrollchange' + eventNamespace, [ $context.scrollTop() ]); }); } }, @@ -713,7 +713,10 @@ $.fn.visibility = function(parameters) { remove: { occurred: function(callback) { if(callback) { - if(module.cache.occurred[callback] !== undefined && module.cache.occurred[callback] === true) { + var + occurred = module.cache.occurred + ; + if(occurred[callback] !== undefined && occurred[callback] === true) { module.debug('Callback can now be called again', callback); module.cache.occurred[callback] = false; } diff --git a/src/definitions/modules/sticky.js b/src/definitions/modules/sticky.js index 36fcc9aba..5c2ea1bd8 100644 --- a/src/definitions/modules/sticky.js +++ b/src/definitions/modules/sticky.js @@ -176,7 +176,7 @@ $.fn.sticky = function(parameters) { }, scroll: function() { requestAnimationFrame(function() { - $scroll.trigger('scrollchange' + eventNamespace, $scroll.scrollTop() ); + $scroll.triggerHandler('scrollchange' + eventNamespace, $scroll.scrollTop() ); }); }, scrollchange: function(event, scrollPosition) {