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

Merge branch 'master' of https://git.autistici.org/djrandom

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