From 21256f1fc48ee448626a32d6c41c077dfbaf0e02 Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Tue, 12 May 2015 16:32:43 -0400 Subject: Add some polyfills + utils --- site/public/assets/javascripts/vendor/util.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'site/public/assets/javascripts/vendor/util.js') diff --git a/site/public/assets/javascripts/vendor/util.js b/site/public/assets/javascripts/vendor/util.js index 0f5c6ed..487fe56 100644 --- a/site/public/assets/javascripts/vendor/util.js +++ b/site/public/assets/javascripts/vendor/util.js @@ -240,6 +240,27 @@ if (!Function.prototype.bind) { }; }()); +/* + * Throttle a function to be called no more often + * than ms milliseconds + */ +function throttle(fn, ms) { + ms = ms || 100 + var ready = true + var last + return function() { + var now = Date.now() + if (ready) { + last = now + return fn.apply(this, arguments) + ready = false + } else { + if (now - last > ms) { + ready = true + } + } + } +} function selectElementContents(el) { if (window.getSelection && document.createRange) { -- cgit v1.2.3-70-g09d2