diff --git a/server/djrandom/frontend/static/js/djr/djr.js b/server/djrandom/frontend/static/js/djr/djr.js index 43551b1cd1d056c3bd1444512582428fdf11a028..d12da4ad2525e275870552b4ce4bf6ba29dc9740 100644 --- a/server/djrandom/frontend/static/js/djr/djr.js +++ b/server/djrandom/frontend/static/js/djr/djr.js @@ -6,6 +6,156 @@ // Namespace. djr = {}; +// Global state (with Player instance). +djr.state = { + backend: null, + player: null +}; + +// Initialize the Player and add all our onclick handlers. +djr.init = function () { + djr.state.backend = new djr.Backend(); + djr.state.player = new djr.Player(djr.state.backend, '#djr_player'); + + // Set autocompletion and search handlers. + $('#queryField').autocomplete({ + source: djr.state.backend.autocomplete, + autoFocus: true, + delay: 200, + minLength: 1 + }); + $('#queryField').focus(); + $('#searchForm').submit(function() { + var query_string = $('#queryField').val(); + djr.state.player.search(query_string); + return false; + }); + + // Add onclick hooks to the playlist controls. + $('#playlistClearBtn').click(function() { + djr.state.player.clearPlaylist(); + }); + $('#playlistStreamBtn').click(function() { + djr.state.player.streamCurrentPlaylist(); + }); + $('#playlistExtendBtn').click(function() { + djr.state.player.extendCurrentPlaylist(); + }); + $('#playlistLast5').click(function() { + djr.state.player.lastPlaylist(5); + }); + $('#playlistLast25').click(function() { + djr.state.player.lastPlaylist(25); + }); + $('#playlistRandom5').click(function() { + djr.state.player.randomPlaylist(5); + }); + $('#playlistRandom25').click(function() { + djr.state.player.randomPlaylist(25); + }); + $('#playlistMost5').click(function() { + djr.state.player.mostPlayedPlaylist(5); + }); + $('#playlistMost25').click(function() { + djr.state.player.mostPlayedPlaylist(25); + }); + $('#playlistNever5').click(function() { + djr.state.player.neverPlayedPlaylist(5); + }); + $('#playlistNever25').click(function() { + djr.state.player.neverPlayedPlaylist(25); + }); + $('#playlistSave').click(function() { + if ( $('#saveForm').is(':visible') == false ) { + $('#savetext').val(djr.playlist.title); + $('#saveForm').show('slow'); + } else { + $('#savetext').val(''); + $('#saveForm').hide('slow'); + } + }); + $('#playlistSaveBtn').click(function() { + if ( $('#savetext').val() != '' ) { + djr.player.saveNewPlaylist($('#savetext').val()); + } + }); + $('#wikibtn').click(function () { + var stitle = $('#song_' + djr.state.player.cur_song + ' .artist').text(); + if ( $('#wikipedia').is(':visible') == false ) { + if ( stitle != "" ) { + stitle = stitle.split(' ').join('+'); + $('#wikipedia').show('slow'); + //$('#wikipedia').attr("src", "/ext?url=" + escape("http://en.wikipedia.org/wiki/Special:Search?search=" + stitle + "&go=Go")); + $('#wikipedia').attr("src", "http://en.m.wikipedia.org/w/index.php?search=" + stitle); + } + } else { + $('#wikipedia').hide('slow') + } + }); + $('#lastfmbtn').click(function () { + var stitle = $('#song_' + djr.state.player.cur_song + ' .title').text(); + var sartist = $('#song_' + djr.state.player.cur_song + ' .artist').text(); + if ( $('#lastfm').is(':visible') == false ) { + if ( stitle != "" ) { + stitle = stitle.split(' ').join('+'); + sartist = sartist.split(' ').join('+'); + $('#lastfm').show('slow'); + //$('#lastfm').attr("src", "/ext?url=" + escape("http://www.lastfm.com/#&q=" + stitle + sartist)); + $('#lastfm').attr("src", "http://m.last.fm/search?q=" + stitle + sartist ); + } + } else { + $('#lastfm').hide('slow') + } + }); + $('#lyricsbtn').click(function () { + var stitle = $('#song_' + djr.state.player.cur_song + ' .title').text(); + if ( $('#lyrics').is(':visible') == false ) { + if ( stitle != "" ) { + stitle = stitle.split(' ').join('+'); + $('#lyrics').show('slow'); + //$('#lyrics').attr("src", "/ext?url=" + escape("http://www.lyrics.com/#&q=" + stitle)); + $('#lyrics').attr("src", "http://lyrics.wikia.com/index.php?search=" + stitle + "&fulltext=0" ); + } + } else { + $('#lyrics').hide('slow') + } + }); + $('#pllistbtn').click(function () { + if ( $('#pllist').is(':visible') == false ) { + $('#pllist').show('slow'); + this.backend.getPlList(uid, function(results) { + var pllist = results; + if (pllist.length == 0) { + djr.debug('No results found.'); + return; + } + var output = "<ul>"; + for (var i; i < pllist.lenght; i++) { + output += "<il><a id='" + pllist[i].uuid + "' onclick='djm.player.showPlaylist(\"" + pllist[i].uuid + "\"' >" + pllist[i].title + "</a></il>"; + //output += "<il><a id='" + pllist[i].uuid + "' onclick='djr.Playlist.saveNewPlaylist();djr.player.createChunk(djr.Playlist.getPlaylist(\"" + pllist[i].uuid + "\"), \"" + pllist[i].title + "\");' >" + pllist[i].title + "</a></il>"; + } + output += "</ul>"; + $('#pllist').html(output); + }); + } else { + $('#pllist').hide('slow') + } + }); + + // Set the album art image to auto-fullscreen on load. + $('#albumart_fs').load(function() { + $(this).fullBg(); + $(this).show(); + }); + + djr.debug('initialization done.'); +}; + +// Export the player for quick onclick access +djr.player = function() { + return djr.state.player; +}; + // Show/hide the 'loader' animated GIF. djr.loading = function(active) { var loader = $('#loaderImg'); diff --git a/server/djrandom/frontend/static/js/djr/player.js b/server/djrandom/frontend/static/js/djr/player.js index 13c14a2ff5fb97f8ac1180c019a967798921f494..11996e3a1a5f859680203ab1604585fc9400ee23 100644 --- a/server/djrandom/frontend/static/js/djr/player.js +++ b/server/djrandom/frontend/static/js/djr/player.js @@ -353,155 +353,5 @@ djr.Player.prototype.reportError = function(event) { } }; -// Global state (with Player instance). -djr.state = { - backend: null, - player: null -}; - -// Initialize the Player and add all our onclick handlers. -djr.init = function () { - djr.state.backend = new djr.Backend(); - djr.state.player = new djr.Player(djr.state.backend, '#djr_player'); - - // Set autocompletion and search handlers. - $('#queryField').autocomplete({ - source: djr.state.backend.autocomplete, - autoFocus: true, - delay: 200, - minLength: 1 - }); - $('#queryField').focus(); - $('#searchForm').submit(function() { - var query_string = $('#queryField').val(); - djr.state.player.search(query_string); - return false; - }); - - // Add onclick hooks to the playlist controls. - $('#playlistClearBtn').click(function() { - djr.state.player.clearPlaylist(); - }); - $('#playlistStreamBtn').click(function() { - djr.state.player.streamCurrentPlaylist(); - }); - $('#playlistExtendBtn').click(function() { - djr.state.player.extendCurrentPlaylist(); - }); - $('#playlistLast5').click(function() { - djr.state.player.lastPlaylist(5); - }); - $('#playlistLast25').click(function() { - djr.state.player.lastPlaylist(25); - }); - $('#playlistRandom5').click(function() { - djr.state.player.randomPlaylist(5); - }); - $('#playlistRandom25').click(function() { - djr.state.player.randomPlaylist(25); - }); - $('#playlistMost5').click(function() { - djr.state.player.mostPlayedPlaylist(5); - }); - $('#playlistMost25').click(function() { - djr.state.player.mostPlayedPlaylist(25); - }); - $('#playlistNever5').click(function() { - djr.state.player.neverPlayedPlaylist(5); - }); - $('#playlistNever25').click(function() { - djr.state.player.neverPlayedPlaylist(25); - }); - $('#playlistSave').click(function() { - if ( $('#saveForm').is(':visible') == false ) { - $('#savetext').val(djr.playlist.title); - $('#saveForm').show('slow'); - } else { - $('#savetext').val(''); - $('#saveForm').hide('slow'); - } - }); - $('#playlistSaveBtn').click(function() { - if ( $('#savetext').val() != '' ) { - djr.player.saveNewPlaylist($('#savetext').val()); - } - }); - $('#wikibtn').click(function () { - var stitle = $('#song_' + djr.state.player.cur_song + ' .artist').text(); - if ( $('#wikipedia').is(':visible') == false ) { - if ( stitle != "" ) { - stitle = stitle.split(' ').join('+'); - $('#wikipedia').show('slow'); - //$('#wikipedia').attr("src", "/ext?url=" + escape("http://en.wikipedia.org/wiki/Special:Search?search=" + stitle + "&go=Go")); - $('#wikipedia').attr("src", "http://en.m.wikipedia.org/w/index.php?search=" + stitle); - } - } else { - $('#wikipedia').hide('slow') - } - }); - $('#lastfmbtn').click(function () { - var stitle = $('#song_' + djr.state.player.cur_song + ' .title').text(); - var sartist = $('#song_' + djr.state.player.cur_song + ' .artist').text(); - if ( $('#lastfm').is(':visible') == false ) { - if ( stitle != "" ) { - stitle = stitle.split(' ').join('+'); - sartist = sartist.split(' ').join('+'); - $('#lastfm').show('slow'); - //$('#lastfm').attr("src", "/ext?url=" + escape("http://www.lastfm.com/#&q=" + stitle + sartist)); - $('#lastfm').attr("src", "http://m.last.fm/search?q=" + stitle + sartist ); - } - } else { - $('#lastfm').hide('slow') - } - }); - $('#lyricsbtn').click(function () { - var stitle = $('#song_' + djr.state.player.cur_song + ' .title').text(); - if ( $('#lyrics').is(':visible') == false ) { - if ( stitle != "" ) { - stitle = stitle.split(' ').join('+'); - $('#lyrics').show('slow'); - //$('#lyrics').attr("src", "/ext?url=" + escape("http://www.lyrics.com/#&q=" + stitle)); - $('#lyrics').attr("src", "http://lyrics.wikia.com/index.php?search=" + stitle + "&fulltext=0" ); - } - } else { - $('#lyrics').hide('slow') - } - }); - $('#pllistbtn').click(function () { - if ( $('#pllist').is(':visible') == false ) { - $('#pllist').show('slow'); - this.backend.getPlList(uid, function(results) { - var pllist = results; - if (pllist.length == 0) { - djr.debug('No results found.'); - return; - } - var output = "<ul>"; - for (var i; i < pllist.lenght; i++) { - output += "<il><a id='" + pllist[i].uuid + "' onclick='djm.player.showPlaylist(\"" + pllist[i].uuid + "\"' >" + pllist[i].title + "</a></il>"; - //output += "<il><a id='" + pllist[i].uuid + "' onclick='djr.Playlist.saveNewPlaylist();djr.player.createChunk(djr.Playlist.getPlaylist(\"" + pllist[i].uuid + "\"), \"" + pllist[i].title + "\");' >" + pllist[i].title + "</a></il>"; - } - output += "</ul>"; - $('#pllist').html(output); - }); - } else { - $('#pllist').hide('slow') - } - }); - - // Set the album art image to auto-fullscreen on load. - $('#albumart_fs').load(function() { - $(this).fullBg(); - $(this).show(); - }); - - djr.debug('initialization done.'); -}; - -// Export the player for quick onclick access -djr.player = function() { - return djr.state.player; -}; - // Fine