diff options
| author | Sean Fridman <fridman@mail.sfsu.edu> | 2015-05-12 16:32:43 -0400 |
|---|---|---|
| committer | Sean Fridman <fridman@mail.sfsu.edu> | 2015-05-12 16:33:34 -0400 |
| commit | 21256f1fc48ee448626a32d6c41c077dfbaf0e02 (patch) | |
| tree | 9f2c371c95a1ed2abc401955aa976720cb19a6f2 /site/public/assets/javascripts/vendor/util.js | |
| parent | 6355b85fc5cb6ad2bac4e3d40e1b550875adb22e (diff) | |
Add some polyfills + utils
Diffstat (limited to 'site/public/assets/javascripts/vendor/util.js')
| -rw-r--r-- | site/public/assets/javascripts/vendor/util.js | 21 |
1 files changed, 21 insertions, 0 deletions
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) { |
