Post resize event function

Only fire an event once after a screen resize.

by Carosn Shold

JavaScript

var waitForFinalEvent = (function () {
  var 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);
  };
})();


// Usage
$(window).resize(function () {
    waitForFinalEvent(function(){
        console.log('resized');
    }, 250, "some unique string");
});