/* gui interactions here * set- functions only set/update the gui elements * do- functions interact with the server * show- functions do both */ /******************** * Song Info Sreen ********************/ function resetSong() { if (!posChanging) { pausePosTimer(); setPlayState(false); setPosition(0); var data = new Object; data.name = ''; data.artists = ''; data.length = 0; data.uri = ' '; setSongInfo(data); } } function resizeMb() { $("#infoname").html(songdata.name); $("#infoartist").html(artiststext); // //set height of playlist scrollers /* if ($(window).width() > 960) { $('#playlisttracksdiv').show(); $('#playlistslistdiv').show(); $('.scroll').removeClass('height').removeClass('width'); $('#playlistspane').removeClass('height').removeClass('width'); } else { if ( $('#playlisttracksdiv').is(':visible') == $('#playlistslistdiv').is(':visible')) { $('#playlisttracksdiv').hide(); $('#playlistslistdiv').show(); $('.scroll').addClass('height', '99%').addClass('width', '99%'); $('#playlistspane').addClass('height', '99%').addClass('width', '99%'); } } if ($('#playlisttracksdiv').is(':visible') && !$('#playlisttracksback').is(':visible') ) { $('.scroll').height($(window).height() - 96); //jqm added something which it shouldnt (at least in this case) I guess // $('#playlistspane').removeClass('height').height($(window).height() - 110); $('.scroll').removeClass('height').removeClass('width'); $('#playlistspane').removeClass('height').removeClass('width'); $('#playlisttracksdiv').show(); $('#playlistslistdiv').show(); } else { $('.scroll').addClass('height', '99%').addClass('width', '99%'); $('#playlistspane').addClass('height', '99%').addClass('width', '99%'); $('#playlisttracksdiv').show(); $('#playlistslistdiv').show(); } if (isMobileWebkit && ($(window).width() > 480)) { playlistslistScroll.refresh(); playlisttracksScroll.refresh(); } */ } function setSongInfo(data) { // console.log(data, songdata); if (!data ) { return; } if ( (data.uri == songdata.uri) ) { return;} if (!data.name || data.name == '') { var name = data.uri.split('/'); data.name = decodeURI(name[name.length - 1]); }; updatePlayIcons(data.uri); artistshtml = ''; artiststext = ''; if (validUri(data.name)) { for (var key in radioStations) { rs = radioStations[key]; if (rs && rs[1] == data.name) { data.name = (rs[0] || rs[1]); } }; } songdata = data; $("#modalname").html(data.name); if (!data.length || data.length == 0) { songlength = 0; $("#songlength").html(''); pausePosTimer(); $('#trackslider').slider('disable'); $('#radionameinput').val(data.name); $('#radiouriinput').val(data.uri); } else { songlength = data.length; $("#songlength").html(timeFromSeconds(data.length / 1000)); $('#trackslider').slider('enable'); } var arttmp = ''; if(data.artists) { for (var j = 0; j < data.artists.length; j++) { artistshtml += '' + data.artists[j].name + ''; artiststext += data.artists[j].name; if (j != data.artists.length - 1) { artistshtml += ', '; artiststext += ', '; } } arttmp = artistshtml; } if (data.album && data.album.name) { $("#modalalbum").html('' + data.album.name + ''); getCover(artiststext, data.album.name, '#infocover, #controlspopupimage', 'extralarge'); } else { $("#modalalbum").html(''); $("#infocover").attr('src', './images/default_cover.png'); $("#controlspopupimage").attr('src', '../images/default_cover.png'); } $("#modalartist").html(arttmp); $("#trackslider").attr("min", 0); $("#trackslider").attr("max", data.length); resizeMb(); } /*************** * display popups */ function closePopups() { $('#popupTracks').popup('close'); $('#artistpopup').popup('close'); $('#coverpopup').popup('close'); $('#popupQueue').popup('close'); $('#controlspopup').popup('close'); } function popupTracks(e, listuri, trackuri) { if (!e) var e = window.event; $('.popupTrackName').html(popupData[trackuri].name); $('.popupAlbumName').html(popupData[trackuri].album.name); var child = ""; if (popupData[trackuri].artists) { if (popupData[trackuri].artists.length == 1) { child = 'Show Artist'; $('.popupArtistName').html(popupData[trackuri].artists[0].name); $('.popupArtistHref').attr('onclick', 'showArtist("' + popupData[trackuri].artists[0].uri + '");' ); $('.popupArtistsDiv').hide(); $('.popupArtistsLi').show(); } else { for (var j = 0; j < popupData[trackuri].artists.length; j++) { child += '
Sorry. Your browser isn\'t modern enough for this webapp. Modern versions of Chrome, Firefox, Safari all will do. Maybe Opera and Internet Explorer 10 also work, but it\'s not tested.
'); exit; } //workaround for a bug in jQuery Mobile, without that the panel doesn't close on mobile devices... $('.ui-panel-dismiss').on( "tap", function() { $("#panel").panel("close"); } ); //end of workaround $(window).hashchange(); // Connect to server // mopidy = new Mopidy(); // console.log(wsLocation); // $.getScript( wsLocation + '/mopidy/mopidy.min.js'); mopidy = new Mopidy({ webSocketUrl: 'ws://' + wsLocation + '/mopidy/ws/' // wslocation is set in index.html "ws://localhost:6680/mopidy/ws/" }); // mopidy.on(console.log.bind(console)); // Log all events // mopidy.on(console.error.bind(console)); //initialize events initSocketevents(); resetSong(); if (location.hash.length < 2) { switchContent("playlists"); } initgui = false; window.onhashchange = locationHashChanged; //update gui status every x seconds from mopdidy setInterval(updateStatusTimer, STATUS_TIMER); //only show backbutton if in UIWebview if (window.navigator.standalone) { $("#btback").show(); } else { $("#btback").hide(); } $(window).resize(function() { resizeMb(); }); //navigation temporary, rewrite this! $('#songinfo').click( function() {return switchContent('nowPlaying')} ); $('#controlspopupimage').click( function() { return switchContent('current')} ); $('#navEnterFullscreen').click(function(){ enterFullscreen(); }); $('#navExitFullscreen').click(function(){ exitFullscreen(); }); //navigation stuff $(document).keypress( function (event) { //console.log('kp: '+event); if (event.target.tagName != 'INPUT') { event.preventDefault(); switch(event.which) { case 32: doPlay(); break; case '>': doNext(); break; case '<': doPrevious(); break; } return true; } }); initRadio(); if ($(window).width() < 980) { $("#panel").panel("close"); }else{ $("#panel").panel("open"); } //hide fullscreen button if in UIWebview if (window.navigator.standalone) { $('#navExitFullscreen').hide(); } $.event.special.swipe.horizontalDistanceThreshold = 125; // (default: 30px) Swipe horizontal displacement must be more than this. $.event.special.swipe.verticalDistanceThreshold = 50; // (default: 75px) Swipe vertical displacement must be less than this. // $.event.special.swipe.scrollSupressionThreshold = 20; $.event.special.swipe.durationThreshold = 500; // swipe songinfo and panel $( "#normalFooter, #nowPlayingFooter" ).on( "swiperight", doPrevious ); $( "#normalFooter, #nowPlayingFooter" ).on( "swipeleft", doNext ); $( "#nowPlayingpane, .ui-body-c, #header, #panel, .pane" ).on( "swiperight", function() { if(!$(event.target).is("#normalFooter") && !$(event.target).is("#nowPlayingFooter")) { $("#panel").panel("open"); event.stopImmediatePropagation(); } } ); $( "#nowPlayingpane, .ui-body-c, #header, #panel, .pane" ).on( "swipeleft", function() { if(!$(event.target).is("#normalFooter") && !$(event.target).is("#nowPlayingFooter")) { $("#panel").panel("close"); event.stopImmediatePropagation(); } } ); }); function updatePlayIcons (uri) { //update styles of listviews $('#currenttable li').each(function() { if (this.id == 'currenttable-' + uri) { $(this).addClass('currenttrack'); } else { $(this).removeClass("currenttrack"); } }); $('#playlisttracks li').each(function() { if (this.id == 'playlisttracks-' + uri) { $(this).addClass('currenttrack2'); } else { $(this).removeClass("currenttrack2"); } }); $('#trackresulttable li').each(function() { if (this.id == 'trackresulttable-' + uri) { $(this).addClass('currenttrack2'); } else { $(this).removeClass("currenttrack2"); } }); $('#artiststable li').each(function() { if (this.id == 'artiststable-' + uri) { $(this).addClass('currenttrack2'); } else { $(this).removeClass("currenttrack2"); } }); $('#albumstable li').each(function() { if (this.id == 'albumstable-' + uri) { $(this).addClass('currenttrack2'); } else { $(this).removeClass("currenttrack2"); } }); $('#browselist li').each(function() { if (this.id == 'browselisttracks-' + uri) { $(this).addClass('currenttrack2'); } else { $(this).removeClass("currenttrack2"); } }); }