[livejournal] r20569: LJSUP-10421: S1 Comments ?\226?\128?\148...
Committer: dpetrov
LJSUP-10421: S1 Comments ?\226?\128?\148 v.2: New ThreadsU branches/commenting-form/htdocs/js/jquery_fn.js
Modified: branches/commenting-form/htdocs/js/jquery_fn.js
===================================================================
--- branches/commenting-form/htdocs/js/jquery_fn.js 2011-11-17 14:24:57 UTC (rev 20568)
+++ branches/commenting-form/htdocs/js/jquery_fn.js 2011-11-17 14:39:19 UTC (rev 20569)
@@ -279,3 +279,28 @@
}
});
};
+
+/**
+ * Function assures that callback will run not faster then minDelay.
+ *
+ * @param {Function} callback A callback to run.
+ * @param {Number} minDelay Minimum delay in ms.
+ *
+ * @return {Function} Callback wrapper to use as a collback in your code.
+ */
+jQuery.delayedCallback = function(callback, minDelay) {
+ var callCount = 2,
+ results,
+ checkFinish = function() {
+ callCount--;
+ if (callCount === 0) {
+ callback.apply(null, results);
+ }
+ }
+
+ setTimeout(checkFinish, minDelay);
+ return function() {
+ results = [].slice.apply(arguments);
+ checkFinish();
+ };
+};
