summaryrefslogtreecommitdiffstats
path: root/templates/javascript_refresh.inc
diff options
context:
space:
mode:
Diffstat (limited to 'templates/javascript_refresh.inc')
-rw-r--r--templates/javascript_refresh.inc43
1 files changed, 27 insertions, 16 deletions
diff --git a/templates/javascript_refresh.inc b/templates/javascript_refresh.inc
index 3ef563aa..a7ccff43 100644
--- a/templates/javascript_refresh.inc
+++ b/templates/javascript_refresh.inc
@@ -1,6 +1,8 @@
<script type="text/javascript" language="javascript">
<!-- Begin
// JS variables mpd_elapsed, mpd_song_length and mpd_state set in show_mpdplay.inc
+// when a page/song is loaded, we get starttime and mpd_elapsed.
+// mpd_elapsed is # of seconds elapsed in the now playing song when the page/song was refreshed
// Set refresh interval (in seconds)
var refreshinterval=<?php echo conf('refresh_limit'); ?>
@@ -24,10 +26,12 @@ function starttime() {
}
function fmt_time (timenum) {
-var min = Math.floor(timenum / 60)
-var sec = Math.floor(timenum % 60)
-var fmted = min + ':' + ((sec < 10) ? "0" : "") + sec
-return fmted
+var sec = Math.floor(timenum % 60);
+/*var min = Math.floor(timenum / 60);
+var fmted = min + ':' + ((sec < 10) ? "0" : "") + sec ;
+return fmted;*/
+return Math.floor((1/60) * timenum) + ':' + ((sec < 10) ? '0' : '') + sec;
+
}
function countdown() {
@@ -41,25 +45,32 @@ function countdown() {
else
{ reloadseconds = Math.round(refreshinterval - secondssinceloaded) }
- if (displaycountdown=="1")
- {
+ if (displaycountdown==1) {
window.status="Refreshing in "+reloadseconds+" seconds";
if (mpd_notstoppause) {
- NodeList = document.getElementsByName ('mpd_cur_track_pos');
- for (var i = 0; i < NodeList.length; i++)
- { NodeList.item(i).firstChild.data = fmt_time (mpd_elapsed + secondssinceloaded); }
- NodeList = document.getElementsByName ('mpd_on_deck_in');
- for (var i = 0; i < NodeList.length; i++)
- { NodeList.item(i).firstChild.data = fmt_time (mpd_song_length - mpd_elapsed - secondssinceloaded); }
+ NodeList = document.getElementById ('mpd_cur_track_pos');
+ { NodeList.firstChild.data = fmt_time((mpd_elapsed) + (secondssinceloaded)); }
+ NodeList = document.getElementById ('mpd_on_deck_in');
+ { NodeList.firstChild.data = fmt_time (mpd_song_length - mpd_elapsed - secondssinceloaded); }
+ NodeList = document.getElementById ('mpd_pctplayed');
+ { NodeList.firstChild.data = Math.floor (100*(mpd_elapsed + secondssinceloaded)/mpd_song_length); }
}
if (reloadseconds > 0) {
var timer=setTimeout("countdown()",1000)
- }
+ }
else {
clearTimeout(timer)
- window.location.reload(true)
- } //if reloadseconds > 0
- } // if displaycountdown
+ if (true) { /* rig it for AJAX for now; later replace with conf('AJAX') */
+ startRequest('action=now_playing');
+ starttime = new Date();
+ starttime=starttime.getTime()
+ var timer=setTimeout("countdown()",1000)
+ }
+ else {
+ window.location.reload(true)
+ }
+ } //if reloadseconds > 0
+ } // if displaycountdown
}
// start with page-load