can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[livejournal] r21114: LJSUP-11003: Change date format at S1

Committer: dpetrov
LJSUP-11003: Change date format at S1
U   trunk/htdocs/js/basic.js
Modified: trunk/htdocs/js/basic.js
===================================================================
--- trunk/htdocs/js/basic.js	2012-02-07 11:41:32 UTC (rev 21113)
+++ trunk/htdocs/js/basic.js	2012-02-07 12:10:45 UTC (rev 21114)
@@ -108,8 +108,52 @@
 	return e;
 };
 
+/**
+ * @namespace LiveJournal utility objects
+ */
+LJ = window.LJ || {};
 
+/**
+ * @class Class allows to call a function with  some delay and also prevent
+ *     its execution if needed.
+ * @constructor
+ *
+ * @param {Function} func Function to call.
+ * @param {number} wait Time in ms to wait before function will be called.
+ */
+LJ.DelayedCall = function(func, wait) {
+	this._func = func;
+	this._wait = wait;
+	this._timer = null;
+	this._args = null;
+};
 
+LJ.DelayedCall.prototype._timerCallback = function() {
+	this._timer = null;
+	this._func.apply(null, this._args);
+};
+
+/**
+ * Run function. All arguments that will be passed to this function will be
+ *    passed to the function called.
+ */
+LJ.DelayedCall.prototype.run = function(/* arguments */) {
+	this._args = [].slice.call(arguments, 0);
+	if (this._timer) { return; }
+
+	this._timer = setTimeout(this._timerCallback.bind(this), this._wait);
+};
+
+/**
+ * Prevent function execution.
+ */
+LJ.DelayedCall.prototype.stop = function() {
+	clearTimeout(this._timer);
+	this._timer = null;
+}
+
+
+
 /* object extensions */
 if (!Object.extend)
 	Object.extend = function (d, s){

Tags: can3p, dpetrov, js, livejournal
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments