<div data-role="page">
[% content %]
<div data-role="footer" data-position="fixed">
- <div data-role="navbar">
+ <div id="controls-pause" data-role="navbar">
<ul id="controls">
<li><a href="#" data-href="prev" data-ajax="false" data-icon="arrow-l">Prev</a></li>
- <li id="play-pause">
- <a href="#" data-href="pause" data-ajax="false" data-icon="pause" >Pause</a>
- </li>
+ <li><a href="#" data-href="pause" data-ajax="false" data-icon="pause" >Pause</a></li>
+ <li><a href="#" data-href="next" data-ajax="false" data-icon="arrow-r">Next</a></li>
+ </ul>
+ </div>
+ <div id="controls-play" data-role="navbar" style="display: none">
+ <ul id="controls">
+ <li><a href="#" data-href="prev" data-ajax="false" data-icon="arrow-l">Prev</a></li>
+ <li><a href="#" data-href="play" data-ajax="false" data-icon="play" >Play</a></li>
<li><a href="#" data-href="next" data-ajax="false" data-icon="arrow-r">Next</a></li>
</ul>
</div>
</div>
<script type="text/javascript">
+ var current_state = 'play';
+ $(document).bind( 'pageinit', fetchCurrent());
+
$(document).bind( 'pageshow', function() {
[% IF msg %]
$( "#notification" ).popup( "open", { y: 10 });
[% END %]
});
+function show_control(state) {
+ if (state == current_state) {
+ return;
+ }
+
+ if (state == 'pause') {
+ show_control_play();
+ } else {
+ show_control_pause();
+ }
+
+ current_state = state;
+}
+
function show_control_pause() {
- $( '#play-pause').html('<a href="#" data-href="pause" data-ajax="false" data-icon="pause" >Pause</a>');
- $( '#controls' ).navbar();
+ $( '#controls-play' ).hide();
+ $( '#controls-pause').show();
}
function show_control_play() {
- $( '#play-pause').html('<a href="#" data-href="play" data-ajax="false" data-icon="play" >Play</a>');
- $( '#controls' ).navbar();
+ $( '#controls-pause').hide();
+ $( '#controls-play' ).show();
}
+function fetchCurrent() {
+ $.getJSON( "/current/", {} )
+ .done(function( json ) {
+ $('#status').empty();
+ if (json.title == 'No song playing') {
+ $('#status').append(json.title);
+ } else {
+ $('#status').append(json.title + '<br />' + json.artist + '<br /><smaller>' + json.sofar + ' of ' + json.total + '</smaller>');
+ }
+
+ show_control(json.state);
+ })
+ .fail(function( jqxhr, textStatus, error ) {
+ var err = textStatus + ', ' + error;
+ console.log( "Request Failed: " + err);
+ })
+};
+
+setInterval(function(){fetchCurrent()}, 10000 );
// For thr navbar, send ajax queries.
$(document).delegate('#controls li > a', 'click', function () {
dataType: 'json',
async: true,
success: function(data) {
+ show_control(data.state);
fetchCurrent();
- if ( data.state == 'pause' ) {
- show_control_play();
- } else {
- show_control_pause();
- }
},
});