vkiryukhin/Smartupdater — Issue #7: Patch for selfStartImmediate option
Author: maltem-za
Created: 2012-02-03 10:18:46+00:00
State: open

I've added an option which makes it possible to toggle the selfStart behaviour between immediately polling on init and observing the timeout (default). This prevents immediate polling after page load. Hopefully it's useful to others.

```javascript
diff -r 995b6dcc6843 mm-gae/web/rich/scripts/smartupdater/smartupdater.4.0.js
--- a/mm-gae/web/rich/scripts/smartupdater/smartupdater.4.0.js	Thu Feb 02 11:48:45 2012 +0200
+++ b/mm-gae/web/rich/scripts/smartupdater/smartupdater.4.0.js	Fri Feb 03 11:21:11 2012 +0200
@@ -55,11 +55,13 @@
httpCache	: false,	// http cache
rCallback	: false,	// remote callback functions
selfStart	: true,	// start automatically after initializing
+ selfStartImmediate : false, // whether selfStart causes polling to start immediately
+ // default: false - polling will start after minTimeout has elapsed
smartStop	: { active:	false,	//disabled by default
monitorTimeout:	2500,	// 2.5 seconds
minHeight:	1,	// 1px
minWidth:	1	// 1px
-	}
+	}

}, options);

@@ -74,11 +76,17 @@
es.callback	= callback;
es.origReq = {url:es.url,data:es.data,callback:callback};
es.stopFlag = false;
+ es.timesRun = 0;

function start() {
-
-	/* check if element has been deleted and clean it up */
+ if (es.timesRun == 0 && !es.selfStartImmediate) {
+ es.timesRun = 1;
+ es.h = setTimeout(start, es.minTimeout);
+ return;
+ }
+
+	/* check if element has been deleted and clean it up */
if(!$(elem).parents('body').length) {
clearInterval(elem.smartupdaterStatus.smartStop);
clearTimeout(elem.settings.h);
@@ -149,7 +157,7 @@

elem.smartupdaterStatus.timeout = es.minTimeout;
es.failedRequests = 0;
-	},
+	},

error: function(xhr, textStatus, errorThrown) {
if ( ++es.failedRequests < es.maxFailedRequests ) {
@@ -187,6 +195,7 @@
});

elem.smartupdaterStatus.state = 'ON';
+ es.timesRun++;
}

es.fnStart = start;
```