aboutsummaryrefslogtreecommitdiff
path: root/mod/riverdashboard/views/default/riverdashboard/container.php
blob: 09a593622d7fa14e1c64d7d9682cb0a4738184f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php echo $vars['body']; ?>

<script type="text/javascript">
$(document).ready(function(){
	var updates = new activityUpdateChecker(10000);
	updates.start();
});

// check for updates on the wire.
function activityUpdateChecker(interval) {
	this.intervalID = null;
	this.interval = interval;
	this.url = '<?php echo elgg_get_site_url(); ?>mod/riverdashboard/endpoint/ping.php';
	this.seconds_passed = 0;

	this.start = function() {
		// needed to complete closure scope.
		var self = this;

		this.intervalID = setInterval(function() { self.checkUpdates(); }, this.interval);
	}

	this.checkUpdates = function() {
		this.seconds_passed += this.interval / 1000;
		// more closure fun
		var self = this;
		$.ajax({
			'type': 'GET',
			'url': this.url,
			'data': {'seconds_passed': this.seconds_passed},
			'success': function(data) {
				if (data) {
					$('#riverdashboard-updates').html(data).slideDown();
					// could crank down the interval here.
					// if we change the message to simply "New Posts!"
					// we could stop the polling altogether.
				}
			}
		})
	}

	this.stop = function() {
		clearInterval(this.interval);
	}

	this.changeInterval = function(interval) {
		this.stop();
		this.interval = interval;
		this.start();
	}
}
</script>