Last active
August 29, 2015 14:01
-
-
Save erikakers/60d083a130ce145a9954 to your computer and use it in GitHub Desktop.
Javascript: Throttle Resize Handler with PubSub event broadcast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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