Skip to content

Instantly share code, notes, and snippets.

@rogeruiz
Last active October 10, 2015 19:27
Show Gist options
  • Select an option

  • Save rogeruiz/3738936 to your computer and use it in GitHub Desktop.

Select an option

Save rogeruiz/3738936 to your computer and use it in GitHub Desktop.
Resize delay and window / document dimensions getter.
window.dimensions = {}
window.getDimensions = ->
window.dimensions.winX = $(window).width()
window.dimensions.winY = $(window).height()
window.dimensions.docX = $(document).width()
window.dimensions.docY = $(document).height()
return
window.resizeDelay = do ->
timers = {}
(callback, ms, uniqueId) ->
uniqueId = "Don't call this twice without a uniqueId" if !uniqueId
clearTimeout (timers[uniqueId]) if timers[uniqueId]
timers[uniqueId] = setTimeout(callback, ms)
return
# Window Event Listener
$(window).on 'resize.dimensions', (e) ->
window.resizeDelay ->
do window.getDimensions
console.log 'Dimensions', JSON.stringify(window.dimensions) if console.log
return
, 500, 'dimensions getter'
return
// Generated by CoffeeScript 1.6.1
(function() {
window.dimensions = {};
window.getDimensions = function() {
window.dimensions.winX = $(window).width();
window.dimensions.winY = $(window).height();
window.dimensions.docX = $(document).width();
window.dimensions.docY = $(document).height();
};
window.resizeDelay = (function() {
var timers;
timers = {};
return function(callback, ms, uniqueId) {
if (!uniqueId) {
uniqueId = "Don't call this twice without a uniqueId";
}
if (timers[uniqueId]) {
clearTimeout(timers[uniqueId]);
}
timers[uniqueId] = setTimeout(callback, ms);
};
})();
$(window).on('resize.dimensions', function(e) {
window.resizeDelay(function() {
window.getDimensions();
if (console.log) {
console.log('Dimensions', JSON.stringify(window.dimensions));
}
}, 500, 'dimensions getter');
});
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment