Skip to content
Snippets Groups Projects
Commit e06678cc authored by ale's avatar ale
Browse files

make the URL reflect the current playlist id

parent a6439c0b
Branches
No related tags found
No related merge requests found
......@@ -20,6 +20,9 @@ djr.init = function (userid) {
djr.state.backend = new djr.Backend();
djr.state.player = new djr.Player(djr.state.backend, '#djr_player');
// Set a callback on URL hash changes.
$(window).bind('hashchange', djr.history.restore);
// Set autocompletion and search handlers.
$('#queryField').autocomplete('/autocomplete', {
queryParamName: 'term',
......
// djrandom.js
djr = {};
// Global state.
djr.state = {
userid: null
};
// Debugging.
djr.debug = function(msg) {
$('#debug').append(msg + '<br>');
};
// history.js
// History and state
......@@ -20,9 +7,8 @@ djr.history = {
};
// Save current state to hashtag.
djr.history.save = function() {
var curPlaylist = djr.state.player.getCurrentPlaylistID();
var hash_tag = '#pl:' + curPlaylist;
djr.history.save = function(pl) {
var hash_tag = '#pl:' + pl;
djr.history.cur_hash = hash_tag;
window.location.hash = hash_tag;
};
......@@ -35,30 +21,19 @@ djr.history.restore = function() {
}
djr.history.cur_hash = hash_tag;
// Parse the hash tag.
var hash_info = {};
$.each(hash_tag.substr(1).split(','), function(idx, value) {
var kv = value.split(':');
hash_info[kv[0]] = unescape(kv.slice(1).join(':'));
});
// Load the new playlist if specified.
if (hash_info.pl) {
var newPlaylistID = hash_info.pl;
djr.state.player.loadPlaylist(newPlaylistID, function() {
djr.loadPlaylistHtml();
});
djr.state.player.loadPlaylist(hash_info.pl);
}
};
djr.getQuery = function() {
return $('#queryField').val();
};
djr.setQuery = function(query) {
djr.debug('setQuery:' + query);
$('#queryField').val(query);
djr.doSearch(query);
};
djr.doSearch = function() {
$('#loading').show();
$.getJSON('/json/search', {'q': djr.getQuery()},
......@@ -85,16 +60,5 @@ djr.doSearch = function() {
};
// Initialization.
djr.init = function(userid) {
djr.state.userid = userid;
// Restore state if the URL changes.
$(window).bind('hashchange', djr.history.restore);
// Initialize the global Player instance.
djr.state.player = new djr.Player('#djr_player');
};
// Puppa.
......@@ -248,6 +248,9 @@ djr.Player.prototype.createChunk = function(songs, chunk_title) {
// Save the current playlist.
this.savePlaylist();
// Set the URL hash fragment to point to the current playlist.
djr.history.save(this.playlist.uuid);
// Load the HTML fragment for the chunk and display it. Also,
// minimize all the other chunks.
var player = this;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment