summaryrefslogtreecommitdiff
path: root/templates/project/assets/javascripts/gridster/utils.js
diff options
context:
space:
mode:
authorDaniel Beauchamp <daniel.beauchamp@shopify.com>2012-08-13 23:36:38 -0400
committerDaniel Beauchamp <daniel.beauchamp@shopify.com>2012-08-13 23:36:38 -0400
commit16f51fd9dc454b26d9866b080caa17ffe2f8ce27 (patch)
tree2c031e8c8e629bdf096b00cc445d04e7782af2c3 /templates/project/assets/javascripts/gridster/utils.js
parent41d8c33a6b87c948a7fe4ae5e53483d42fead422 (diff)
Updated to use sprockets! Ah, much cleaner.
Diffstat (limited to 'templates/project/assets/javascripts/gridster/utils.js')
-rwxr-xr-xtemplates/project/assets/javascripts/gridster/utils.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/templates/project/assets/javascripts/gridster/utils.js b/templates/project/assets/javascripts/gridster/utils.js
new file mode 100755
index 0000000..5f340b3
--- /dev/null
+++ b/templates/project/assets/javascripts/gridster/utils.js
@@ -0,0 +1,41 @@
+;(function(window, undefined) {
+ /* Debounce and throttle functions taken from underscore.js */
+ window.debounce = function(func, wait, immediate) {
+ var timeout;
+ return function() {
+ var context = this, args = arguments;
+ var later = function() {
+ timeout = null;
+ if (!immediate) func.apply(context, args);
+ };
+ if (immediate && !timeout) func.apply(context, args);
+ clearTimeout(timeout);
+ timeout = setTimeout(later, wait);
+ };
+ };
+
+
+ window.throttle = function(func, wait) {
+ var context, args, timeout, throttling, more, result;
+ var whenDone = debounce(
+ function(){ more = throttling = false; }, wait);
+ return function() {
+ context = this; args = arguments;
+ var later = function() {
+ timeout = null;
+ if (more) func.apply(context, args);
+ whenDone();
+ };
+ if (!timeout) timeout = setTimeout(later, wait);
+ if (throttling) {
+ more = true;
+ } else {
+ result = func.apply(context, args);
+ }
+ whenDone();
+ throttling = true;
+ return result;
+ };
+ };
+
+})(window);