Changeset - 1a2fc3a93b3e
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 14 years ago 2011-06-15 05:46:36
drewp@bigasterisk.com
don't poll on the ascoltami page if it's not the visible tab
Ignore-this: 4c9cbccacecc6bd198fe38aa1abef7e6
1 file changed with 13 insertions and 3 deletions:
0 comments (0 inline, 0 general)
light9/ascoltami/index.html
Show inline comments
 
@@ -24,66 +24,67 @@
 

	
 
    <div class="commands">
 
      <button id="cmd-stop" class="playMode">Stop<div class="key">C-s</div></button>
 
      <button id="cmd-play" class="playMode">Play <div class="key">C-p</div></button>
 
      <button id="cmd-intro">Skip intro <div class="key">C-i</div></button>
 
      <button id="cmd-post">Skip to Post <div class="key">C-t</div></button>
 
      <button id="cmd-go">Go  <div class="key">space</div></button>
 
    </div>
 

	
 
    todo: go button actions, display next action
 
    <a href="">reload</a>
 

	
 
<script type="text/javascript">
 
// <![CDATA[
 
$(function () {
 

	
 
    var times = { // need to get these from server
 
	intro: 4,
 
	post: 4
 
    };
 

	
 
    var currentDuration = 0;
 
    var currentHighlightedSong = "";
 
    var lastPlaying;
 
    function updateCurrent() {
 
    function updateCurrent(doneCallback) {
 
	$.getJSON("time", {}, function (data, status) {
 
	    $("#currentSong").text(data.song);
 
	    if (data.song != currentHighlightedSong) {
 
		showCurrentSong(data.song);
 
	    }
 
	    $("#currentTime").text(data.t.toFixed(1));
 
	    $("#leftTime").text((data.duration - data.t).toFixed(1));
 
	    $("#leftAutoStopTime").text(
 
		Math.max(0, data.duration - times.post - data.t).toFixed(1));
 
	    currentDuration = data.duration;
 
	    $("#timeSlider").slider({value: data.t,
 
				     max: data.duration});
 
	    if (data.playing != lastPlaying) {
 
		$(".playMode").removeClass("active");
 
		$(data.playing ? "#cmd-play" : "#cmd-stop").addClass("active");
 
		lastPlaying = data.playing;
 
	    }
 
	    doneCallback();
 
	});
 
    }
 
    function showCurrentSong(uri) {
 
	$(".songs div").each(function (i, row) {
 
	    row = $(row);
 
	    if (row.find("button").data("uri") == uri) {
 
		row.addClass("currentSong");
 
	    } else {
 
		row.removeClass("currentSong");
 
	    }
 
	});
 
	currentHighlightedSong = uri;
 
    }
 
    $.getJSON("songs", {}, function (data, status) {
 
	$.each(data.songs, function (i, song) {
 
	    var button = $("<button>");
 
	    button.text(song.label);
 
	    button.data(song);
 
	    button.click(function () {
 
		$.post("song", button.data("uri"), 
 
		       function (data, textStatus, xhr) {
 
			   showCurrentSong(song.uri);
 
		       });
 
	    });
 
@@ -110,36 +111,45 @@
 
	$.post("time", tojs({t: times.intro, resume: true}))
 
    });
 
    $("#cmd-post").click(function () { 
 
	$.post("time", tojs({t: currentDuration - times.post, resume: true}))
 
    });
 
    $("#cmd-go").click(function () {
 
	// todo
 
    });
 

	
 
    var pendingSlide = false;
 
    $("#timeSlider").slider({
 
	step: .01,
 
	slide: function (event, ui) {
 
	    if (pendingSlide) {
 
		return;
 
	    }
 
	    pendingSlide = true;
 
	    $.post("time", '{"t" : '+ui.value+'}', 
 
		   function (data, status, xhr) {
 
		       pendingSlide = false;
 
		   });
 
	},
 
    });
 
    
 
    var raf = window.requestAnimationFrame ||
 
	window.mozRequestAnimationFrame || 
 
	window.webkitRequestAnimationFrame;
 

	
 
    function updateLoop() {
 
	updateCurrent();
 
	setTimeout(updateLoop, 200);
 
	var whenDone = function () {
 
	    setTimeout(function () { 
 
		raf(updateLoop);
 
	    }, 50);
 
	};
 
	updateCurrent(whenDone);
 
    }
 
    updateLoop();
 

	
 
});
 
// ]]>
 
</script>
 

	
 

	
 
  </body>
 
</html>
 
\ No newline at end of file
0 comments (0 inline, 0 general)