Browse Source

Use slightly more performant triggerHandler for pub/sub

pull/2300/head
jlukic 9 years ago
parent
commit
ecbfa1de93
2 changed files with 11 additions and 8 deletions
  1. 17
      src/definitions/behaviors/visibility.js
  2. 2
      src/definitions/modules/sticky.js

17
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;
}

2
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) {

Loading…
Cancel
Save