1.8 display changes, folder picker

This commit is contained in:
Trevor Squillario 2012-03-27 13:51:16 -04:00
parent ed43a7875d
commit c79720b923
18 changed files with 1627 additions and 1165 deletions

118
js/app.js
View file

@ -19,7 +19,12 @@ var version = '1.7.0';
function loadTabContent(tab) {
switch (tab) {
case '#tabLibrary':
loadArtists();
if ($.cookie('MusicFolders')) {
loadArtists($.cookie('MusicFolders'), false);
} else {
loadArtists();
}
getMusicFolders();
break;
case '#tabCurrent':
var header = generateSongHeaderHTML();
@ -35,22 +40,39 @@ function loadTabContent(tab) {
}
}
function loadArtists(refresh) {
function loadArtists(id, refresh) {
if (refresh) {
$('#ArtistContainer').empty();
}
var url;
if (id == "all") {
url = baseURL + '/getIndexes.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp';
} else if (id) {
url = baseURL + '/getIndexes.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp&musicFolderId=' + id;
} else {
url = baseURL + '/getIndexes.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp';
}
var content = $('#ArtistContainer').html();
if (content === "") {
// Load Artist List
$.ajax({
url: baseURL + '/getIndexes.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp',
url: url,
method: 'GET',
dataType: 'jsonp',
timeout: 10000,
success: function (data) {
if (data["subsonic-response"].status === 'ok') {
var indexlist, indexname;
$.each(data["subsonic-response"].indexes.index, function (i, index) {
// There is a bug in the API that doesn't return a JSON array for one artist
var indexes = [];
if (data["subsonic-response"].indexes.index.length > 0) {
indexes = data["subsonic-response"].indexes.index;
} else {
indexes[0] = data["subsonic-response"].indexes.index;
}
$.each(indexes, function (i, index) {
if (index.name === '#') {
indexname = '0-9';
} else {
@ -89,6 +111,41 @@ function loadArtists(refresh) {
});
}
}
function getMusicFolders() {
$.ajax({
url: baseURL + '/getMusicFolders.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp',
method: 'GET',
dataType: 'jsonp',
timeout: 10000,
beforeSend: function (req) {
req.setRequestHeader('Authorization', auth);
},
success: function (data) {
if (data["subsonic-response"].musicFolders.musicFolder !== undefined) {
// There is a bug in the API that doesn't return a JSON array for one artist
var folders = [];
if (data["subsonic-response"].musicFolders.musicFolder.length > 0) {
folders = data["subsonic-response"].musicFolders.musicFolder;
} else {
folders[0] = data["subsonic-response"].musicFolders.musicFolder;
}
var savedMusicFolder = $.cookie('MusicFolders');
var options = [];
options.push('<option value="all">All Folders</option>');
$.each(folders, function (i, folder) {
if (savedMusicFolder == folder.id) {
options.push('<option value="' + folder.id + '" selected>' + folder.name + '</option>');
} else {
options.push('<option value="' + folder.id + '">' + folder.name + '</option>');
}
});
$('#MusicFolders').html(options.join(''));
} else {
}
}
});
}
function getAlbums(id, action, appendto) {
$.ajax({
url: baseURL + '/getMusicDirectory.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp&id=' + id,
@ -135,6 +192,9 @@ function getAlbums(id, action, appendto) {
}
$(albumhtml).appendTo(appendto);
});
if (appendto === '#CurrentPlaylistContainer') {
updateMessage(children.length + ' Song(s) Added');
}
if (appendto === '#AlbumRows' && isDir === true) {
header = generateAlbumHeaderHTML();
}
@ -243,6 +303,9 @@ function getRandomSongList(action, appendto) {
html = generateSongHTML(rowcolor, item.id, item.parent, track, item.title, item.artist, item.album, item.coverArt, item.userRating, time['m'], time['s']);
$(html).appendTo(appendto);
});
if (appendto === '#CurrentPlaylistContainer') {
updateMessage(items.length + ' Song(s) Added');
}
if (action === 'autoplay') {
autoPlay();
}
@ -262,6 +325,7 @@ function generateAlbumHTML(rowcolor, childid, parentid, coverart, title, artist,
html = '<tr class=\"album ' + rowcolor + '\" childid=\"' + childid + '\" parentid=\"' + parentid + '\" userrating=\"' + rating + '\">';
html += '<td class=\"itemactions\"><a class=\"add\" href=\"\" title=\"Add To Current Playlist\"></a>';
html += '<a class=\"play\" href=\"\" title=\"Play\"></a>';
html += '<a class=\"download\" href=\"\" title=\"Download\"></a>';
if (rating === 5) {
html += '<a class=\"favorite\" href=\"\" title=\"Favorite\"></a>';
} else {
@ -358,9 +422,9 @@ function playSong(el, songid, albumid) {
}
if ($.cookie('ScrollTitle')) {
//clearTimeout(timer);
scrollTitle(artist + ' - ' + title);
scrollTitle(toHTML.un(artist) + ' - ' + toHTML.un(title));
} else {
setTitle(artist + ' - ' + title);
setTitle(toHTML.un(artist) + ' - ' + toHTML.un(title));
}
}
});
@ -781,11 +845,29 @@ function addToPlaylist(playlistid, from) {
}
}
function addToCurrent() {
var count = $('table.songlist tr.selected').length;
var count = $('#AlbumContainer tr.selected').length;
if (count > 0) {
$('#AlbumContainer tr.selected').each(function (index) {
$(this).clone().appendTo('#CurrentPlaylistContainer tbody');
updateMessage(count + ' Song(s) Added');
});
}
}
function downloadItem(id) {
var url;
if (id) {
url = baseURL + '/download.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp&id=' + id;
window.location = url;
}
/*
$('table.songlist tr.selected').each(function (index) {
$(this).clone().appendTo('#CurrentPlaylistContainer tbody');
updateMessage(count + ' Song(s) Added');
id = $(this).attr('childid');
if (id) {
url = baseURL + '/download.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp&id=' + id;
window.location = url;
}
});
*/
}
function savePlaylist(playlistid) {
var songs = [];
@ -851,6 +933,9 @@ function getPlaylist(id, action, appendto) {
html = generateSongHTML(rowcolor, child.id, child.parent, track, child.title, child.artist, child.album, child.coverArt, child.userRating, time['m'], time['s']);
$(html).appendTo(appendto);
});
if (appendto === '#CurrentPlaylistContainer tbody') {
updateMessage(children.length + ' Song(s) Added');
}
if (action === 'autoplay') {
autoPlay();
}
@ -951,6 +1036,21 @@ function updateMessage(msg) {
$('#messages').fadeIn();
setTimeout(function () { $('#messages').fadeOut(); }, 5000);
}
// Convert to unicode support
var toHTML = {
on: function(str) {
var a = [],
i = 0;
for (; i < str.length;) a[i] = str.charCodeAt(i++);
return "&#" + a.join(";&#") + ";"
},
un: function(str) {
return str.replace(/&#(x)?([^&]{1,5});?/g,
function(a, b, c) {
return String.fromCharCode(parseInt(c, b ? 16 : 10))
})
}
};
function setTitle(text) {
if (text != "") {
document.title = text;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,59 @@
/* Generic context menu styles */
.contextMenu {
position: absolute;
width: 115px;
z-index: 99999;
border: solid 1px #DEDEDE;
background: #fff;
padding: 0px;
margin: 0px;
display: none;
}
.contextMenu LI {
list-style: none;
padding: 0px;
margin: 0px;
}
.contextMenu A {
color: #333;
text-decoration: none;
display: block;
line-height: 20px;
height: 20px;
background-position: 9px center;
background-repeat: no-repeat;
outline: none;
padding: 3px 5px;
padding-left: 32px;
font-size: 16px;
font-variant: small-caps;
}
.contextMenu LI.hover A {
color: #FFF;
background-color: #3399FF;
}
.contextMenu LI.disabled A {
color: #AAA;
cursor: default;
}
.contextMenu LI.hover.disabled A {
background-color: transparent;
}
.contextMenu LI.separator {
border-top: solid 1px #CCC;
}
/*
Adding Icons
You can add icons to the context menu by adding
classes to the respective LI element(s)
*/
.contextMenu LI.download A { background-image: url(../../images/download_gd_12x16.png); }

View file

@ -0,0 +1,209 @@
// jQuery Context Menu Plugin
//
// Version 1.01
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
//
// More info: http://abeautifulsite.net/2008/09/jquery-context-menu-plugin/
//
// Terms of Use
//
// This plugin is dual-licensed under the GNU General Public License
// and the MIT License and is copyright A Beautiful Site, LLC.
//
if (jQuery) (function () {
$.extend($.fn, {
contextMenu: function (o, callback) {
// Defaults
if (o.menu == undefined) return false;
if (o.inSpeed == undefined) o.inSpeed = 150;
if (o.outSpeed == undefined) o.outSpeed = 75;
// 0 needs to be -1 for expected results (no fade)
if (o.inSpeed == 0) o.inSpeed = -1;
if (o.outSpeed == 0) o.outSpeed = -1;
// Loop each context menu
$(this).live("mousedown", function (e) {
var el = $(this);
var offset = $(el).offset();
// Add contextMenu class
$('#' + o.menu).addClass('contextMenu');
var evt = e;
evt.stopPropagation();
$(this).mouseup(function (e) {
e.stopPropagation();
var srcElement = $(this);
$(this).unbind('mouseup');
if (evt.button == 2) {
// Hide context menus that may be showing
$(".contextMenu").hide();
// Get this context menu
var menu = $('#' + o.menu);
if ($(el).hasClass('disabled')) return false;
// Detect mouse position
var d = {}, x, y;
if (self.innerHeight) {
d.pageYOffset = self.pageYOffset;
d.pageXOffset = self.pageXOffset;
d.innerHeight = self.innerHeight;
d.innerWidth = self.innerWidth;
} else if (document.documentElement &&
document.documentElement.clientHeight) {
d.pageYOffset = document.documentElement.scrollTop;
d.pageXOffset = document.documentElement.scrollLeft;
d.innerHeight = document.documentElement.clientHeight;
d.innerWidth = document.documentElement.clientWidth;
} else if (document.body) {
d.pageYOffset = document.body.scrollTop;
d.pageXOffset = document.body.scrollLeft;
d.innerHeight = document.body.clientHeight;
d.innerWidth = document.body.clientWidth;
}
(e.pageX) ? x = e.pageX : x = e.clientX + d.scrollLeft;
(e.pageY) ? y = e.pageY : y = e.clientY + d.scrollTop;
// Show the menu
//$(document).unbind('click');
$(menu).css({ top: y, left: x }).fadeIn(o.inSpeed);
// Hover events
$(menu).find('A').mouseover(function () {
$(menu).find('LI.hover').removeClass('hover');
$(this).parent().addClass('hover');
}).mouseout(function () {
$(menu).find('LI.hover').removeClass('hover');
});
// Keyboard
$(document).keypress(function (e) {
switch (e.keyCode) {
case 38: // up
if ($(menu).find('LI.hover').size() == 0) {
$(menu).find('LI:last').addClass('hover');
} else {
$(menu).find('LI.hover').removeClass('hover').prevAll('LI:not(.disabled)').eq(0).addClass('hover');
if ($(menu).find('LI.hover').size() == 0) $(menu).find('LI:last').addClass('hover');
}
break;
case 40: // down
if ($(menu).find('LI.hover').size() == 0) {
$(menu).find('LI:first').addClass('hover');
} else {
$(menu).find('LI.hover').removeClass('hover').nextAll('LI:not(.disabled)').eq(0).addClass('hover');
if ($(menu).find('LI.hover').size() == 0) $(menu).find('LI:first').addClass('hover');
}
break;
case 13: // enter
$(menu).find('LI.hover A').trigger('click');
break;
case 27: // esc
$(document).trigger('click');
break
}
});
// When items are selected
$('#' + o.menu).find('A').unbind('click');
$('#' + o.menu).find('LI:not(.disabled) A').click(function () {
//$(document).unbind('click').unbind('keypress');
$(".contextMenu").hide();
// Callback
if (callback) callback($(this).attr('href').substr(1), $(srcElement), { x: x - offset.left, y: y - offset.top, docX: x, docY: y });
return false;
});
// Hide bindings
setTimeout(function () { // Delay for Mozilla
$(document).click(function () {
//$(document).unbind('click').unbind('keypress');
$(menu).fadeOut(o.outSpeed);
return false;
});
}, 0);
}
});
// Disable text selection
if ($.browser.mozilla) {
$('#' + o.menu).each(function () { $(this).css({ 'MozUserSelect': 'none' }); });
} else if ($.browser.msie) {
$('#' + o.menu).each(function () { $(this).bind('selectstart.disableTextSelect', function () { return false; }); });
} else {
$('#' + o.menu).each(function () { $(this).bind('mousedown.disableTextSelect', function () { return false; }); });
}
// Disable browser context menu (requires both selectors to work in IE/Safari + FF/Chrome)
$(el).add($('UL.contextMenu')).bind('contextmenu', function () { return false; });
});
return $(this);
},
// Disable context menu items on the fly
disableContextMenuItems: function (o) {
if (o == undefined) {
// Disable all
$(this).find('LI').addClass('disabled');
return ($(this));
}
$(this).each(function () {
if (o != undefined) {
var d = o.split(',');
for (var i = 0; i < d.length; i++) {
$(this).find('A[href="' + d[i] + '"]').parent().addClass('disabled');
}
}
});
return ($(this));
},
// Enable context menu items on the fly
enableContextMenuItems: function (o) {
if (o == undefined) {
// Enable all
$(this).find('LI.disabled').removeClass('disabled');
return ($(this));
}
$(this).each(function () {
if (o != undefined) {
var d = o.split(',');
for (var i = 0; i < d.length; i++) {
$(this).find('A[href="' + d[i] + '"]').parent().removeClass('disabled');
}
}
});
return ($(this));
},
// Disable context menu(s)
disableContextMenu: function () {
$(this).each(function () {
$(this).addClass('disabled');
});
return ($(this));
},
// Enable context menu(s)
enableContextMenu: function () {
$(this).each(function () {
$(this).removeClass('disabled');
});
return ($(this));
},
// Destroy context menu(s)
destroyContextMenu: function () {
// Destroy specified context menus
$(this).each(function () {
// Disable action
$(this).unbind('mousedown').unbind('mouseup');
});
return ($(this));
}
});
})(jQuery);

67
js/ui-load.js Normal file
View file

@ -0,0 +1,67 @@
$(window).load(function () {
if ($.cookie('defaultsmwidth')) {
var width = $.cookie('defaultsmwidth');
resizeSMSection(width);
}
if ($.cookie('sidebar') && $.cookie('username') && $.cookie('password')) {
$('#SideBar').show();
updateChatMessages();
updateNowPlaying();
}
if ($.cookie('HideAZ')) {
$('#BottomContainer').hide();
}
$('ul#ChangeLog li.log').each(function (i, el) {
if (i > 3) {
$(el).hide();
}
});
resizeContent();
});
window.onbeforeunload = function () {
closeAllNotifications();
};
$(window).resize(function () {
resizeContent();
});
function resizeContent() {
var screenwidth = $(window).width();
$('.tabcontent').css({ 'height': (($(window).height() - 112)) + 'px' });
$('.smsection').css({ 'height': (($(window).height() - 152)) + 'px' });
var smheight = $('.smsection').height();
var smwidth = $('.smsection').width();
$('#BottomContainer').css({ 'top': smheight + 34 + 'px' });
if ($.cookie('sidebar')) {
var tabwidth = $(window).width() - 268;
if (tabwidth >= 700) {
$('.tabcontent').css({ 'width': tabwidth + 'px' });
}
var sbheight = $(window).height() - 152;
$('#SideBar').css({ 'height': (sbheight + 108) + 'px' });
$('#ChatMsgs').css({ 'height': (sbheight - 166) + 'px' });
} else {
var tabwidth = $(window).width() - 61;
if (tabwidth >= 700) {
$('.tabcontent').css({ 'width': tabwidth + 'px' });
}
}
var tabwidth = $('.tabcontent').width();
$('#AlbumContainer, #TrackContainer, #CurrentPlaylistContainer').css({ 'width': (tabwidth - smwidth - 30) + 'px' });
$('#CurrentPlaylistContainer').css({ 'width': (tabwidth - 30) + 'px' });
$('#player').css({ 'width': tabwidth + 'px' });
}
function resizeSMSection(x) {
var defwidth = 200;
var smwidth = $('.smsection').width();
var newsmwidth = smwidth + parseInt(x);
var newwidth = newsmwidth - defwidth;
if (smwidth != newsmwidth && newsmwidth > 150 && newsmwidth < 500) {
$('.smsection').css({ 'width': (newsmwidth) + 'px' });
$('.actions').css({ 'width': (newsmwidth - 5) + 'px' });
$('#BottomContainer').css({ 'width': (newsmwidth - 16) + 'px' });
$.cookie('defaultsmwidth', newwidth, { expires: 365, path: '/' });
var ulwidth = newsmwidth + 6;
$('#AlbumContainer').css({ 'margin-left': ulwidth + 'px' });
$('#TrackContainer').css({ 'margin-left': ulwidth + 'px' });
}
}

488
js/ui-ready.js Normal file
View file

@ -0,0 +1,488 @@
$(document).ready(function () {
// Tabs
$(".tabcontent").hide(); //Hide all content
if ($.cookie('username') == null) {
$('ul.tabs li a').each(function () {
if ($(this).attr("href") == '#tabPreferences') {
$(this).addClass("active"); //Add "active" class to selected tab
}
});
$("#tabPreferences").show(); //Show first tab content
loadTabContent('#tabPreferences');
} else {
if (window.location.hash) {
var hash = window.location.hash;
$('ul.tabs li a').each(function () {
if ($(this).attr("href") == hash) {
$(this).addClass("active"); //Add "active" class to selected tab
}
});
$(hash).show(); //Fade in the active ID content
loadTabContent(hash);
} else {
$("ul.tabs li:first a").addClass("active").show(); //Activate first tab
$(".tabcontent:first").show(); //Show first tab content
var firstTab = $("ul.tabs li:first a").attr("href");
loadTabContent(firstTab);
}
}
// Tabs - Click Event
$("ul.tabs li a").click(function () {
$("ul.tabs li a").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tabcontent").hide(); //Hide all tab content
var activeTab = $(this).attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).show(); //Fade in the active ID content
loadTabContent(activeTab);
});
// Ajax Loading Screen
$(".toploading").ajaxStart(function () {
$(this).show();
});
$(".toploading").ajaxStop(function () {
$(this).hide();
});
// Keyboard shortcuts
$(document).keydown(function (e) {
var source = e.target.id;
if (source != 'Search' && source != 'ChatMsg') {
var unicode = e.charCode ? e.charCode : e.keyCode;
// a-z
if (unicode >= 65 && unicode <= 90) {
var key = findKeyForCode(unicode);
var el = '#index_' + key.toUpperCase();
$('#Artists').stop().scrollTo(el, 400);
// right arrow
} else if (unicode == 39 || unicode == 176) {
var next = $('#CurrentPlaylistContainer tr.playing').next();
if (!next.length) next = $('#CurrentPlaylistContainer li').first();
changeTrack(next);
// back arrow
} else if (unicode == 37 || unicode == 177) {
var prev = $('#CurrentPlaylistContainer tr.playing').prev();
if (!prev.length) prev = $('#CurrentPlaylistContainer tr').last();
changeTrack(prev);
// spacebar
} else if (unicode == 32 || unicode == 179 || unicode == 0179) {
playPauseSong();
} else if (unicode == 36) {
$('#Artists').stop().scrollTo('#auto', 400);
}
}
});
// Main Click Events
// Albums Click Event
$('#MusicFolders').live('change', function () {
var folder = $(this).val();
loadArtists(folder, true);
$.cookie('MusicFolders', folder, { expires: 365 });
});
$('#ArtistContainer li.item').live('click', function () {
$('#AutoAlbumContainer li').removeClass('selected');
$('#ArtistContainer li').removeClass('selected');
$(this).addClass('selected');
getAlbums($(this).attr("id"), '', '#AlbumRows');
});
$('#BottomIndex li a').live('click', function () {
var el = '#index_' + $(this).text();
$('#Artists').stop().scrollTo(el, 400);
return false;
});
$('#AutoAlbumContainer li.item').live('click', function () {
$('#AutoAlbumContainer li').removeClass('selected');
$('#ArtistContainer li').removeClass('selected');
$(this).addClass('selected');
getAlbumListBy($(this).attr("id"));
});
$('tr.album a.play').live('click', function (e) {
var albumid = $(this).parent().parent().attr('childid');
var artistid = $(this).parent().parent().attr('parentid');
getAlbums(albumid, 'autoplay', '#CurrentPlaylistContainer');
return false;
});
$('tr.album a.add').live('click', function (e) {
var albumid = $(this).parent().parent().attr('childid');
var artistid = $(this).parent().parent().attr('parentid');
getAlbums(albumid, 'add', '#CurrentPlaylistContainer');
return false;
});
$('tr.album a.download').live('click', function (event) {
var itemid = $(this).parent().parent().attr('childid');
downloadItem(itemid);
return false;
});
$('tr.album a.rate').live('click', function (event) {
var itemid = $(this).parent().parent().attr('childid');
rateSong(itemid, 5);
$(this).removeClass('rate');
$(this).addClass('favorite');
return false;
});
$('tr.album a.favorite').live('click', function (event) {
var itemid = $(this).parent().parent().attr('childid');
rateSong(itemid, 0);
$(this).removeClass('favorite');
$(this).addClass('rate');
return false;
});
$('tr.album').live('click', function (e) {
var albumid = $(this).attr('childid');
var artistid = $(this).attr('parentid');
getAlbums(albumid, '', '#AlbumRows');
return false;
});
// Track - Click Events
// Multiple Select
$('.noselect').disableTextSelect();
var lastChecked = null;
$('table.songlist tr.song').live('click', function (event) {
var checkboxclass = 'table.songlist tr.song';
var songid = $(this).attr('childid');
var albumid = $(this).attr('parentid');
if (!event.ctrlKey) {
$(checkboxclass).removeClass('selected');
}
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
} else {
$(this).addClass('selected');
}
if (!lastChecked) {
lastChecked = this;
return;
}
if (event.shiftKey) {
var start = $(checkboxclass).index(this);
var end = $(checkboxclass).index(lastChecked);
for (i = Math.min(start, end); i <= Math.max(start, end); i++) {
$(checkboxclass).eq(i).addClass('selected');
}
}
lastChecked = this;
});
// Double Click
$('table.songlist tr.song').live('dblclick', function (e) {
e.preventDefault();
//$(this).addClass('playing').siblings().removeClass('playing');
var songid = $(this).attr('childid');
var albumid = $(this).attr('parentid');
playSong('', this, songid, albumid);
});
$('table.songlist tr.song a.play').live('click', function (event) {
var songid = $(this).parent().parent().attr('childid');
var albumid = $(this).parent().parent().attr('parentid');
playSong($(this).parent().parent(), songid, albumid);
return false;
});
$('table.songlist tr.song a.add').live('click', function (event) {
var track = $(this).parent().parent();
$(track).clone().appendTo('#CurrentPlaylistContainer');
return false;
});
$('table.songlist tr.song a.remove').live('click', function (event) {
var track = $(this).parent().parent();
$(track).remove();
refreshRowColor();
return false;
});
$('table.songlist tr.song a.rate').live('click', function (event) {
var songid = $(this).parent().parent().attr('childid');
rateSong(songid, 5);
$(this).removeClass('rate');
$(this).addClass('favorite');
return false;
});
$('table.songlist tr.song a.favorite').live('click', function (event) {
var songid = $(this).parent().parent().attr('childid');
rateSong(songid, 0);
$(this).removeClass('favorite');
$(this).addClass('rate');
return false;
});
$('li.index').live('click', function (e) {
$('#Artists').stop().scrollTo('#auto', 400);
return false;
});
// Music Library Click Events
$('a#action_AddToPlaylist').click(function () {
var submenu = $('div#submenu_AddToPlaylist');
if (submenu.is(":visible")) {
submenu.fadeOut();
} else {
loadPlaylistsForMenu('submenu_AddToPlaylist');
//get the position of the placeholder element
pos = $(this).offset();
width = $(this).width();
height = $(this).height();
//show the menu directly over the placeholder
submenu.css({ "left": (pos.left) + "px", "top": (pos.top + height + 14) + "px" }).fadeIn(400);
}
return false;
});
var submenu_active = false;
$('div.submenu').mouseenter(function () {
submenu_active = true;
});
$('div.submenu').mouseleave(function () {
submenu_active = false;
setTimeout(function () { if (submenu_active == false) $('div.submenu').fadeOut(); }, 400);
});
$('a#action_AddToCurrent').click(function () {
addToCurrent();
return false;
});
$('#action_RefreshArtists').click(function () {
loadArtists("", true);
return false;
});
$('#action_IncreaseWidth').click(function () {
resizeSMSection(50);
return false;
});
$('#action_DecreaseWidth').click(function () {
resizeSMSection(-50);
return false;
});
$('#action_SelectAll').click(function () {
$('#Albums tr.song').each(function () {
$(this).addClass('selected');
});
return false;
});
$('#action_SelectNone').click(function () {
$('#Albums tr.song').each(function () {
$(this).removeClass('selected');
});
return false;
});
$('input#Search').keydown(function (e) {
var unicode = e.charCode ? e.charCode : e.keyCode;
if (unicode == 13) {
$('#action_Search').click();
}
});
$('#action_Search').click(function () {
var query = $('#Search').val();
search('song', query);
$('#Search').val("");
return false;
});
// Current Playlist Click Events
$('#action_Shuffle').live('click', function () {
$('#CurrentPlaylistContainer tr.song').shuffle();
refreshRowColor();
return false;
});
$('#action_Empty').live('click', function () {
$('#CurrentPlaylistContainer tbody').empty();
return false;
});
$('a#action_AddCurrentToPlaylist').click(function () {
var submenu = $('div#submenu_AddCurrentToPlaylist');
if (submenu.is(":visible")) {
submenu.fadeOut();
} else {
loadPlaylistsForMenu('submenu_AddCurrentToPlaylist');
//get the position of the placeholder element
pos = $(this).offset();
width = $(this).width();
height = $(this).height();
//show the menu directly over the placeholder
submenu.css({ "left": (pos.left) + "px", "top": (pos.top + height + 14) + "px" }).fadeIn(400);
}
});
$('#action_CurrentSelectAll').click(function () {
$('#CurrentPlaylist tr.song').each(function () {
$(this).addClass('selected');
});
return false;
});
$('#action_CurrentSelectNone').click(function () {
$('#CurrentPlaylist tr.song').each(function () {
$(this).removeClass('selected');
});
return false;
});
// Playlist Click Events
$('#AutoPlaylistContainer li.item').live('click', function () {
$('#AutoPlaylistContainer li').removeClass('selected');
$('#PlaylistContainer li').removeClass('selected');
$(this).addClass('selected');
getRandomSongList('', '#TrackContainer');
});
$('#AutoPlaylistContainer li.item a.play').live('click', function () {
getRandomSongList('autoplay', '#CurrentPlaylistContainer');
return false;
});
$('#AutoPlaylistContainer li.item a.add').live('click', function () {
getRandomSongList('', '#CurrentPlaylistContainer');
return false;
});
$('#PlaylistContainer li.item').live('click', function () {
$('#AutoPlaylistContainer li').removeClass('selected');
$('#PlaylistContainer li').removeClass('selected');
$(this).addClass('selected');
getPlaylist($(this).attr("id"), '', '#TrackContainer tbody');
});
$('#PlaylistContainer li.item a.play').live('click', function () {
getPlaylist($(this).parent().parent().attr("id"), 'autoplay', '#CurrentPlaylistContainer tbody');
return false;
});
$('#PlaylistContainer li.item a.add').live('click', function () {
getPlaylist($(this).parent().parent().attr("id"), '', '#CurrentPlaylistContainer tbody');
return false;
});
$('#action_DeletePlaylist').click(function () {
if ($('#PlaylistContainer li.selected').length > 0) {
if (confirmDelete()) {
$('#PlaylistContainer li.selected').each(function () {
deletePlaylist($(this).attr("id"));
});
}
}
return false;
});
$('#action_SavePlaylist').click(function () {
if ($('#PlaylistContainer li.selected').length > 0) {
$('#PlaylistContainer li.selected').each(function () {
savePlaylist($(this).attr("id"));
});
}
return false;
});
$('#action_RemoveSongs').click(function () {
if ($('#TrackContainer tr.selected').length > 0) {
$('#TrackContainer tr.selected').each(function () {
$(this).remove();
});
}
return false;
});
$('#action_ShufflePlaylist').live('click', function () {
$('#TrackContainer tr.song').shuffle();
refreshRowColor();
return false;
});
// Player Click Events
$('#PlayTrack').live('click', function () {
playPauseSong();
return false;
});
$('#NextTrack').live('click', function () {
var next = $('#CurrentPlaylistContainer tr.playing').next();
changeTrack(next);
return false;
});
$('#PreviousTrack').live('click', function () {
var prev = $('#CurrentPlaylistContainer tr.playing').prev();
changeTrack(prev);
return false;
});
$("a#coverartimage").fancybox({
'hideOnContentClick': true,
'type': 'image'
});
// Side Bar Click Events
$('#action_ToggleSideBar').live('click', function () {
if ($.cookie('sidebar')) {
$.cookie('sidebar', null);
$('#SideBar').hide();
stopUpdateChatMessages();
stopUpdateNowPlaying();
} else {
$.cookie('sidebar', true, { expires: 365 });
$('#SideBar').show();
updateChatMessages();
updateNowPlaying();
}
resizeContent();
return false;
});
$('input#ChatMsg').keydown(function (e) {
var unicode = e.charCode ? e.charCode : e.keyCode;
if (unicode == 13) {
var msg = $('#ChatMsg').val();
if (msg != '') {
addChatMessage(msg);
}
$('#ChatMsg').val("");
}
});
// Preferences Click Events
$('#SavePreferences').live('click', function () {
var username = $('#Username').val();
var password = $('#Password').val();
$.cookie('username', username, { expires: 365 });
$.cookie('password', password, { expires: 365 });
var AutoAlbumSize = $('#AutoAlbumSize').val();
var AutoPlaylistSize = $('#AutoPlaylistSize').val();
$.cookie('AutoAlbumSize', AutoAlbumSize, { expires: 365 });
$.cookie('AutoPlaylistSize', AutoPlaylistSize, { expires: 365 });
var server = $('#Server').val();
if (server != "") {
$.cookie('Server', server, { expires: 365 });
}
var applicationname = $('#ApplicationName').val();
if (applicationname != "") {
$.cookie('ApplicationName', applicationname, { expires: 365 });
}
location.reload(true);
});
$('#HideAZ').live('click', function () {
if ($('#HideAZ').is(':checked')) {
$.cookie('HideAZ', '1', { expires: 365 });
$('#BottomContainer').hide();
} else {
$.cookie('HideAZ', null);
$('#BottomContainer').show();
}
});
$('#EnableNotifications').live('click', function () {
if ($('#EnableNotifications').is(':checked')) {
requestPermissionIfRequired();
if (hasNotificationPermission()) {
$.cookie('EnableNotifications', '1', { expires: 365 });
}
} else {
$.cookie('EnableNotifications', null);
}
});
$('#ScrollTitle').live('click', function () {
if ($('#ScrollTitle').is(':checked')) {
$.cookie('ScrollTitle', '1', { expires: 365 });
}
});
$('input#Password').keydown(function (e) {
var unicode = e.charCode ? e.charCode : e.keyCode;
if (unicode == 13) {
$('#SavePreferences').click();
}
});
$('#ResetPreferences').live('click', function () {
$.cookie('username', null);
$.cookie('password', null);
$.cookie('AutoAlbumSize', null);
$.cookie('AutoPlaylistSize', null);
$.cookie('Server', null);
$.cookie('ApplicationName', null);
$.cookie('HideAZ', null);
location.reload(true);
});
$('#ChangeLogShowMore').live('click', function () {
$('ul#ChangeLog li.log').each(function (i, el) {
$(el).show();
});
return false;
});
}); // End document.ready