Skip to content

Instantly share code, notes, and snippets.

@erikakers
Last active August 29, 2015 14:01
Show Gist options
  • Save erikakers/60d083a130ce145a9954 to your computer and use it in GitHub Desktop.
Save erikakers/60d083a130ce145a9954 to your computer and use it in GitHub Desktop.
Javascript: Throttle Resize Handler with PubSub event broadcast
App.Helpers.resizeThrottle = (function(throttle) {
throttle.init = function() {
var updateLayout = _.debounce(function(e) {
console.log('Throttled resize event. Broadcasting...');
$.publish('resize');
}, 500);
if (window.addEventListener) {
window.addEventListener("resize", updateLayout, false);
}
};
return throttle;
}(App.Helpers.resizeThrottle || {}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment