From 21cb56374ff92578e447e8aadafb1aba2d56e5e0 Mon Sep 17 00:00:00 2001
From: MaZderMind
Date: Sun, 9 Nov 2014 19:43:50 +0100
Subject: only run program timeline update when program timeline is visible

---
 assets/js/lustiges-script.js | 38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/assets/js/lustiges-script.js b/assets/js/lustiges-script.js
index d1608f8..6085129 100644
--- a/assets/js/lustiges-script.js
+++ b/assets/js/lustiges-script.js
@@ -46,15 +46,18 @@ $(function() {
 			$irc.addClass('active');
 		}).attr('src', $iframe.data('src'));
 	});
+});
 
+// programm-timeline
+$(function() {
 	var
 		$program = $('.program'),
 		$now = $program.find('.now'),
 		scrollLock = false,
 		rewindTimeout,
-		rewindTime = 10000 /* 10 seconds after manual navigation */,
-
-		scrollDuration = 500 /* 1/2s animation on the scolling element */;
+		rewindTime = 10000, /* 10 seconds after manual navigation */
+		scrollDuration = 500, /* 1/2s animation on the scolling element */
+		updateTimer = 500; /* update now-pointer placement every 1/2s */
 
 	$program.on('mouseenter mouseleave touchstart touchend', function(e) {
 		if(e.type == 'mouseleave' || e.type == 'touchend') {
@@ -68,7 +71,7 @@ $(function() {
 	});
 
 	// program now-marker & scrolling
-	function interval(initial) {
+	function updateProgramView(initial) {console.log('updateProgramView');
 		var
 			// offset to the browsers realtime (for simulation
 			offset = $('.program').data('offset'),
@@ -129,15 +132,30 @@ $(function() {
 		}
 	}
 
-	// initial trigger
-	interval(true);
 
-	// timed triggers
-	setInterval(interval, 500);
+	// when on programs tab
+	var updateInterval;
+	function on() {
+		// initial trigger
+		updateProgramView(true);
+
+		// timed triggers
+		updateInterval = setInterval(updateProgramView, updateTimer);
+	}
+
+	function off() {
+		clearInterval(updateInterval);
+	}
+
+	if(window.location.hash == '#program')
+		on();
 
 	// trigger when a tab was changed
-	$('.nav-tabs').on('shown.bs.tab', 'a', function (e) {
-		interval(true);
+	$('.nav-tabs').on('shown.bs.tab', 'a', function(e) {
+		if(e.target.hash == '#program')
+			on();
+		else
+			off();
 	});
 });
 
-- 
cgit v1.2.3