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

split the Javascript code in multiple modules

parent b4cd7963
No related branches found
No related tags found
No related merge requests found
// backend.js
// Backend API stub.
djr.Backend = function() {
// Nothing yet.
};
// Search.
djr.Backend.prototype.search = function(query, callback, ctx) {
$.ajax({url: '/json/search',
data: {'q': query},
dataType: 'json',
type: 'GET',
context: ctx || this,
success: function(data, status, jqxhr) {
callback(data.results);
}
});
};
// More like these.
djr.Backend.prototype.moreLikeThese = function(uuids, callback, ctx) {
$.ajax({url: '/json/morelikethese',
data: {'h': uuids.join(',')},
dataType: 'json',
type: 'POST',
context: ctx || this,
success: function(data, status, jqxhr) {
callback(data.results);
}
});
};
// Get information about a specific song.
// Read a playlist, calls callback(Playlist).
djr.Backend.prototype.getPlaylist = function(uuid, callback, ctx) {
$.ajax({url: '/json/playlist/get/' + uuid,
dataType: 'json',
type: 'GET',
context: ctx || this,
success: function(data, status, jqxhr) {
callback(new djr.PlaylistChunk(data.songs, uuid));
}
});
};
// Save a playlist (song array).
djr.Backend.prototype.savePlaylist = function(uuid, songs) {
$.ajax({url: '/json/playlist/save',
data: {uuid: uuid,
h: songs.join(',')},
type: 'POST'
});
};
// Stream a playlist.
djr.Backend.prototype.streamPlaylist = function(uuid, streaming, callback, ctx) {
$.ajax({url: '/json/playlist/stream',
data: {uuid: uuid,
stream: streaming ? 'y' : 'n'},
dataType: 'json',
type: 'POST',
context: ctx || this,
success: function(data, status, jqxhr) {
callback(data);
}
});
};
// Return the HTML fragment for an array of songs.
djr.Backend.prototype.getHtmlForSongs = function(songs, callback, ctx) {
$.ajax({url: '/fragment/songs',
data: {'h': songs.join(',')},
dataType: 'html',
type: 'POST',
context: ctx || this,
success: callback,
});
};
// Ping a song that is currently playing.
djr.Backend.prototype.nowPlaying = function(song, old_songs) {
$.ajax({url: '/json/playing',
data: {'cur': song,
'prev': old_songs.join(',')},
type: 'POST',
});
};
// djr.js
// Globals and namespace definition.
// Namespace.
djr = {};
// Utility functions.
var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
djr.generateRandomId = function() {
var uuid = [], chars = CHARS, i;
var len = 40, radix = chars.length;
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
return uuid.join('');
};
// player.js
// Namespace.
djr = {};
// Utility functions.
var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
djr.generateRandomId = function() {
var uuid = [], chars = CHARS, i;
var len = 40, radix = chars.length;
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
return uuid.join('');
};
// Backend API stub.
djr.Backend = function() {
// Nothing yet.
};
// Search.
djr.Backend.prototype.search = function(query, callback, ctx) {
$.ajax({url: '/json/search',
data: {'q': query},
dataType: 'json',
type: 'GET',
context: ctx || this,
success: function(data, status, jqxhr) {
callback(data.results);
}
});
};
// More like these.
djr.Backend.prototype.moreLikeThese = function(uuids, callback, ctx) {
$.ajax({url: '/json/morelikethese',
data: {'h': uuids.join(',')},
dataType: 'json',
type: 'POST',
context: ctx || this,
success: function(data, status, jqxhr) {
callback(data.results);
}
});
};
// Get information about a specific song.
// Read a playlist, calls callback(Playlist).
djr.Backend.prototype.getPlaylist = function(uuid, callback, ctx) {
$.ajax({url: '/json/playlist/get/' + uuid,
dataType: 'json',
type: 'GET',
context: ctx || this,
success: function(data, status, jqxhr) {
callback(new djr.PlaylistChunk(data.songs, uuid));
}
});
};
// Save a playlist (song array).
djr.Backend.prototype.savePlaylist = function(uuid, songs) {
$.ajax({url: '/json/playlist/save',
data: {uuid: uuid,
h: songs.join(',')},
type: 'POST'
});
};
// Stream a playlist.
djr.Backend.prototype.streamPlaylist = function(uuid, streaming, callback, ctx) {
$.ajax({url: '/json/playlist/stream',
data: {uuid: uuid,
stream: streaming ? 'y' : 'n'},
dataType: 'json',
type: 'POST',
context: ctx || this,
success: function(data, status, jqxhr) {
callback(data);
}
});
};
// Return the HTML fragment for an array of songs.
djr.Backend.prototype.getHtmlForSongs = function(songs, callback, ctx) {
$.ajax({url: '/fragment/songs',
data: {'h': songs.join(',')},
dataType: 'html',
type: 'POST',
context: ctx || this,
success: callback,
});
};
// Ping a song that is currently playing.
djr.Backend.prototype.nowPlaying = function(song, old_songs) {
$.ajax({url: '/json/playing',
data: {'cur': song,
'prev': old_songs.join(',')},
type: 'POST',
});
};
// A Playlist chunk (basically, an array of songs).
djr.PlaylistChunk = function(songs, title) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment