2018-05-14 23:13:43 +00:00
|
|
|
|
/* myMPD
|
|
|
|
|
(c) 2018 Juergen Mang <mail@jcgames.de>
|
|
|
|
|
This project's homepage is: https://github.com/jcorporation/ympd
|
|
|
|
|
|
|
|
|
|
myMPD ist fork of:
|
|
|
|
|
|
|
|
|
|
ympd
|
2014-02-22 00:57:26 +00:00
|
|
|
|
(c) 2013-2014 Andrew Karpow <andy@ndyk.de>
|
2016-09-11 15:54:25 +00:00
|
|
|
|
This project's homepage is: https://www.ympd.org
|
2014-02-22 00:57:26 +00:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2014-01-17 18:41:41 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2013-11-04 17:18:38 +00:00
|
|
|
|
var socket;
|
2013-11-05 13:59:12 +00:00
|
|
|
|
var last_state;
|
2015-04-28 09:08:21 +00:00
|
|
|
|
var last_outputs;
|
2013-11-07 12:47:31 +00:00
|
|
|
|
var current_app;
|
2014-02-22 01:11:45 +00:00
|
|
|
|
var pagination = 0;
|
2018-05-13 20:45:23 +00:00
|
|
|
|
var browsepath = "";
|
2014-01-17 17:34:22 +00:00
|
|
|
|
var lastSongTitle = "";
|
2014-01-16 17:32:20 +00:00
|
|
|
|
var current_song = new Object();
|
2018-05-27 21:34:39 +00:00
|
|
|
|
var MAX_ELEMENTS_PER_PAGE = 100;
|
2015-10-22 15:48:42 +00:00
|
|
|
|
var isTouch = Modernizr.touch ? 1 : 0;
|
2018-05-16 23:19:03 +00:00
|
|
|
|
var playstate = "";
|
2018-05-21 23:36:05 +00:00
|
|
|
|
var progressBar;
|
|
|
|
|
var volumeBar;
|
2018-05-27 14:14:56 +00:00
|
|
|
|
var coverImageFile = "";
|
2013-11-04 17:18:38 +00:00
|
|
|
|
|
2013-11-07 12:47:31 +00:00
|
|
|
|
var app = $.sammy(function() {
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
2014-02-22 01:11:45 +00:00
|
|
|
|
function prepare() {
|
2018-05-17 22:10:57 +00:00
|
|
|
|
$('#navbar-bottom > div').removeClass('active');
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#cardPlayback').addClass('hide');
|
|
|
|
|
$('#cardQueue').addClass('hide');
|
|
|
|
|
$('#cardBrowse').addClass('hide');
|
|
|
|
|
$('#cardSearch').addClass('hide');
|
2018-05-24 22:21:19 +00:00
|
|
|
|
$('.pagination').addClass('hide');
|
2018-05-24 23:08:33 +00:00
|
|
|
|
$('#searchqueue > input').val('');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
$('#cardBrowsePlaylists').addClass('hide');
|
|
|
|
|
$('#cardBrowseDatabase').addClass('hide');
|
|
|
|
|
$('#cardBrowseFilesystem').addClass('hide');
|
|
|
|
|
$('#cardBrowseNavPlaylists').removeClass('active');
|
|
|
|
|
$('#cardBrowseNavDatabase').removeClass('active');
|
|
|
|
|
$('#cardBrowseNavFilesystem').removeClass('active');
|
2014-02-22 01:11:45 +00:00
|
|
|
|
pagination = 0;
|
|
|
|
|
browsepath = '';
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-13 23:06:12 +00:00
|
|
|
|
this.get (/\#\/playing\//, function() {
|
|
|
|
|
prepare();
|
|
|
|
|
current_app = 'nowplaying';
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#cardPlayback').removeClass('hide');
|
|
|
|
|
$('#navPlayback').addClass('active');
|
2018-05-13 23:06:12 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-05-29 20:12:11 +00:00
|
|
|
|
this.get(/\#\/queue\/(\d+)\/([^\/]+)\/(.*)/, function() {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
current_app = 'queue';
|
2014-02-22 01:11:45 +00:00
|
|
|
|
pagination = parseInt(this.params['splat'][0]);
|
2018-05-29 20:12:11 +00:00
|
|
|
|
var mpdtag = this.params['splat'][1];
|
|
|
|
|
var searchstr = this.params['splat'][2];
|
|
|
|
|
|
|
|
|
|
if ($('#cardQueue').hasClass('hide')) {
|
|
|
|
|
prepare();
|
|
|
|
|
if (searchstr == '') {
|
|
|
|
|
setPagination(pagination);
|
|
|
|
|
}
|
|
|
|
|
$('#searchtags2 > button').each(function() {
|
|
|
|
|
if ($(this).text == mpdtag) { $(this).removeClass('btn-secondary').addClass('btn-success'); }
|
|
|
|
|
});
|
|
|
|
|
$('#cardQueue').removeClass('hide');
|
|
|
|
|
$('#navQueue').addClass('active');
|
|
|
|
|
}
|
|
|
|
|
$('#queueList > tbody').empty();
|
|
|
|
|
if (searchstr.length >= 3) {
|
|
|
|
|
socket.send('MPD_API_SEARCH_QUEUE,' + mpdtag + ','+pagination+',' + searchstr);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
socket.send('MPD_API_GET_QUEUE,'+pagination);
|
|
|
|
|
}
|
2014-01-16 17:32:20 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-05-28 22:05:56 +00:00
|
|
|
|
this.get(/\#\/browse\/playlists\/(\d+)/, function() {
|
2014-02-22 01:11:45 +00:00
|
|
|
|
prepare();
|
|
|
|
|
browsepath = this.params['splat'][1];
|
|
|
|
|
pagination = parseInt(this.params['splat'][0]);
|
2018-05-28 22:05:56 +00:00
|
|
|
|
current_app = 'browsePlaylists';
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#navBrowse').addClass('active');
|
|
|
|
|
$('#cardBrowse').removeClass('hide');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
$('#cardBrowsePlaylists').removeClass('hide');
|
|
|
|
|
$('#cardBrowseNavPlaylists').addClass('active');
|
2018-05-29 16:07:06 +00:00
|
|
|
|
$('#browsePlaylistsList').find("tr:gt(0)").remove();
|
2018-05-28 22:05:56 +00:00
|
|
|
|
socket.send('MPD_API_GET_PLAYLISTS,'+pagination);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.get(/\#\/browse\/database\/(\d+)/, function() {
|
|
|
|
|
prepare();
|
|
|
|
|
browsepath = this.params['splat'][1];
|
|
|
|
|
pagination = parseInt(this.params['splat'][0]);
|
|
|
|
|
current_app = 'browseDatabase';
|
|
|
|
|
$('#navBrowse').addClass('active');
|
|
|
|
|
$('#cardBrowse').removeClass('hide');
|
|
|
|
|
$('#cardBrowseDatabase').removeClass('hide');
|
|
|
|
|
$('#cardBrowseNavDatabase').addClass('active');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.get(/\#\/browse\/filesystem\/(\d+)\/(.*)/, function() {
|
|
|
|
|
prepare();
|
|
|
|
|
browsepath = this.params['splat'][1];
|
|
|
|
|
pagination = parseInt(this.params['splat'][0]);
|
|
|
|
|
current_app = 'browseFilesystem';
|
|
|
|
|
$('#navBrowse').addClass('active');
|
|
|
|
|
$('#cardBrowse').removeClass('hide');
|
|
|
|
|
$('#cardBrowseFilesystem').removeClass('hide');
|
|
|
|
|
$('#cardBrowseNavFilesystem').addClass('active');
|
2018-05-29 20:12:11 +00:00
|
|
|
|
$('#browseFilesystemList > tbody').empty();
|
|
|
|
|
$('#browseBreadcrumb').empty().append("<li class=\"breadcrumb-item\"><a uri=\"\">root</a></li>");
|
2014-02-22 01:11:45 +00:00
|
|
|
|
socket.send('MPD_API_GET_BROWSE,'+pagination+','+(browsepath ? browsepath : "/"));
|
2015-08-17 21:01:47 +00:00
|
|
|
|
// Don't add all songs from root
|
2018-05-22 23:07:34 +00:00
|
|
|
|
var add_all_songs = $('#add-all-songs');
|
2015-08-17 21:01:47 +00:00
|
|
|
|
if (browsepath) {
|
|
|
|
|
add_all_songs.off(); // remove previous binds
|
|
|
|
|
add_all_songs.on('click', function() {
|
|
|
|
|
socket.send('MPD_API_ADD_TRACK,'+browsepath);
|
|
|
|
|
});
|
2018-05-14 23:13:43 +00:00
|
|
|
|
add_all_songs.removeClass('hide');
|
2018-05-22 23:07:34 +00:00
|
|
|
|
} else {
|
|
|
|
|
add_all_songs.addClass('hide');
|
2015-08-17 21:01:47 +00:00
|
|
|
|
}
|
2018-05-13 23:06:12 +00:00
|
|
|
|
|
2014-02-22 01:11:45 +00:00
|
|
|
|
var path_array = browsepath.split('/');
|
2014-01-16 17:32:20 +00:00
|
|
|
|
var full_path = "";
|
|
|
|
|
$.each(path_array, function(index, chunk) {
|
|
|
|
|
if(path_array.length - 1 == index) {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#browseBreadcrumb').append("<li class=\"breadcrumb-item active\">"+ chunk + "</li>");
|
2014-01-16 17:32:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
full_path = full_path + chunk;
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#browseBreadcrumb').append("<li class=\"breadcrumb-item\"><a uri=\"" + full_path + "\">"+chunk+"</a></li>");
|
2014-01-16 17:32:20 +00:00
|
|
|
|
full_path += "/";
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-29 20:12:11 +00:00
|
|
|
|
this.get(/\#\/search\/(\d+)\/([^\/]+)\/(.*)/, function() {
|
2014-02-22 00:57:26 +00:00
|
|
|
|
current_app = 'search';
|
2018-05-29 20:12:11 +00:00
|
|
|
|
pagination = parseInt(this.params['splat'][0]);
|
|
|
|
|
var mpdtag = this.params['splat'][1];
|
|
|
|
|
var searchstr = this.params['splat'][2];
|
|
|
|
|
|
|
|
|
|
if ($('#cardSearch').hasClass('hide')) {
|
|
|
|
|
prepare();
|
|
|
|
|
if (searchstr != '') {
|
|
|
|
|
$('#searchList > tbody').append(
|
|
|
|
|
"<tr><td><span class=\"material-icons\">search</span></td>" +
|
|
|
|
|
"<td colspan=\"3\">Searching</td>" +
|
|
|
|
|
"<td></td><td></td></tr>");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
setPagination(pagination);
|
|
|
|
|
}
|
|
|
|
|
$('#search > input').val(searchstr);
|
|
|
|
|
$('#searchstr2').val(searchstr);
|
|
|
|
|
$('#searchtags2 > button').each(function() {
|
|
|
|
|
if ($(this).text == mpdtag) { $(this).removeClass('btn-secondary').addClass('btn-success'); }
|
|
|
|
|
});
|
|
|
|
|
$('#cardSearch').removeClass('hide');
|
|
|
|
|
$('#navSearch').addClass('active');
|
|
|
|
|
}
|
|
|
|
|
$('#searchList > tbody').empty();
|
|
|
|
|
if (searchstr.length >= 3) {
|
|
|
|
|
socket.send('MPD_API_SEARCH,' + mpdtag + ','+pagination+',' + searchstr);
|
|
|
|
|
}
|
2015-08-27 14:15:23 +00:00
|
|
|
|
});
|
|
|
|
|
|
2014-01-16 17:32:20 +00:00
|
|
|
|
this.get("/", function(context) {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
context.redirect("#/playing/");
|
2014-01-16 17:32:20 +00:00
|
|
|
|
});
|
2018-05-13 23:06:12 +00:00
|
|
|
|
|
2013-11-07 12:47:31 +00:00
|
|
|
|
});
|
|
|
|
|
|
2013-11-07 09:09:40 +00:00
|
|
|
|
$(document).ready(function(){
|
2014-01-16 17:32:20 +00:00
|
|
|
|
webSocketConnect();
|
2018-05-21 23:36:05 +00:00
|
|
|
|
|
|
|
|
|
volumeBar=$('#volumebar').slider();
|
|
|
|
|
volumeBar.slider('setValue',0);
|
|
|
|
|
volumeBar.slider('on','slideStop', function(value){
|
|
|
|
|
socket.send("MPD_API_SET_VOLUME,"+value);
|
2014-01-16 17:32:20 +00:00
|
|
|
|
});
|
2018-05-21 23:36:05 +00:00
|
|
|
|
|
|
|
|
|
progressBar=$('#progressbar').slider();
|
|
|
|
|
progressBar.slider('setValue',0);
|
|
|
|
|
|
|
|
|
|
progressBar.slider('on','slideStop', function(value){
|
2014-01-17 15:41:54 +00:00
|
|
|
|
if(current_song && current_song.currentSongId >= 0) {
|
2018-05-21 23:36:05 +00:00
|
|
|
|
var seekVal = Math.ceil(current_song.totalTime*(value/100));
|
2014-01-16 17:32:20 +00:00
|
|
|
|
socket.send("MPD_API_SET_SEEK,"+current_song.currentSongId+","+seekVal);
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-01-17 17:34:22 +00:00
|
|
|
|
|
2018-05-27 21:34:39 +00:00
|
|
|
|
$('#about').on('shown.bs.modal', function () {
|
|
|
|
|
socket.send("MPD_API_GET_STATS");
|
2018-05-29 21:05:34 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
$('#settings').on('shown.bs.modal', function () {
|
|
|
|
|
socket.send("MPD_API_GET_SETTINGS");
|
|
|
|
|
})
|
2018-05-27 21:34:39 +00:00
|
|
|
|
|
2015-07-16 09:50:54 +00:00
|
|
|
|
$('#addstream').on('shown.bs.modal', function () {
|
|
|
|
|
$('#streamurl').focus();
|
2018-05-29 21:05:34 +00:00
|
|
|
|
})
|
|
|
|
|
|
2015-07-16 09:50:54 +00:00
|
|
|
|
$('#addstream form').on('submit', function (e) {
|
|
|
|
|
addStream();
|
|
|
|
|
});
|
2018-05-23 22:32:01 +00:00
|
|
|
|
|
|
|
|
|
$('#mainMenu').on('shown.bs.dropdown', function () {
|
|
|
|
|
$('#search > input').val('');
|
|
|
|
|
$('#search > input').focus();
|
2018-05-27 13:10:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
2014-01-17 17:34:22 +00:00
|
|
|
|
if(!notificationsSupported())
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#btnnotifyWeb').addClass("disabled");
|
2014-01-17 17:34:22 +00:00
|
|
|
|
else
|
2018-05-24 17:50:05 +00:00
|
|
|
|
if (Cookies.get('notificationWeb') === 'true')
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#btnnotifyWeb').removeClass('btn-secondary').addClass("btn-success")
|
|
|
|
|
|
2018-05-24 17:50:05 +00:00
|
|
|
|
if (Cookies.get('notificationPage') === 'true')
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#btnnotifyPage').removeClass('btn-secondary').addClass("btn-success")
|
2016-06-08 21:20:27 +00:00
|
|
|
|
|
|
|
|
|
add_filter();
|
2013-11-07 09:09:40 +00:00
|
|
|
|
});
|
|
|
|
|
|
2013-11-05 13:59:12 +00:00
|
|
|
|
function webSocketConnect() {
|
2014-01-16 17:32:20 +00:00
|
|
|
|
if (typeof MozWebSocket != "undefined") {
|
2014-02-16 18:46:53 +00:00
|
|
|
|
socket = new MozWebSocket(get_appropriate_ws_url());
|
2014-01-16 17:32:20 +00:00
|
|
|
|
} else {
|
2014-02-16 18:46:53 +00:00
|
|
|
|
socket = new WebSocket(get_appropriate_ws_url());
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
socket.onopen = function() {
|
2014-02-16 18:46:53 +00:00
|
|
|
|
console.log("connected");
|
2018-05-22 23:07:34 +00:00
|
|
|
|
showNotification('Connected to myMPD','','','success');
|
2018-05-27 13:10:34 +00:00
|
|
|
|
$('#modalConnectionError').modal('hide');
|
2014-01-16 17:32:20 +00:00
|
|
|
|
app.run();
|
2018-05-29 21:05:34 +00:00
|
|
|
|
/* emit request for mympd settings */
|
|
|
|
|
socket.send('MPD_API_GET_SETTINGS');
|
2015-04-28 09:08:21 +00:00
|
|
|
|
/* emit initial request for output names */
|
2018-02-04 11:50:44 +00:00
|
|
|
|
socket.send('MPD_API_GET_OUTPUTS');
|
2018-05-27 14:14:56 +00:00
|
|
|
|
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-22 01:11:45 +00:00
|
|
|
|
socket.onmessage = function got_packet(msg) {
|
|
|
|
|
if(msg.data === last_state || msg.data.length == 0)
|
2014-02-22 00:57:26 +00:00
|
|
|
|
return;
|
2018-05-17 22:10:57 +00:00
|
|
|
|
try {
|
|
|
|
|
var obj = JSON.parse(msg.data);
|
|
|
|
|
} catch(e) {
|
2018-05-27 15:30:36 +00:00
|
|
|
|
console.log('Invalid JSON data received: '+ msg.data);
|
2018-05-17 22:10:57 +00:00
|
|
|
|
}
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
|
|
|
|
switch (obj.type) {
|
2018-05-24 22:21:19 +00:00
|
|
|
|
case 'queuesearch':
|
|
|
|
|
//Do the same as queue
|
2018-02-02 01:14:31 +00:00
|
|
|
|
case 'queue':
|
2014-02-22 00:57:26 +00:00
|
|
|
|
if(current_app !== 'queue')
|
2014-01-16 17:32:20 +00:00
|
|
|
|
break;
|
2018-05-27 12:37:50 +00:00
|
|
|
|
$('#panel-heading-queue').empty();
|
|
|
|
|
|
|
|
|
|
if (obj.totalSongs > 0) {
|
|
|
|
|
$('#panel-heading-queue').text(obj.totalSongs+' Songs');
|
|
|
|
|
}
|
|
|
|
|
if (typeof(obj.totalTime) != undefined && obj.totalTime > 0 ) {
|
2018-05-27 21:52:01 +00:00
|
|
|
|
$('#panel-heading-queue').append(' – ' + beautifyDuration(obj.totalTime));
|
2018-04-04 17:40:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#queueList > tbody').empty();
|
2018-05-25 16:20:26 +00:00
|
|
|
|
var nrItems=0;
|
2014-01-16 17:32:20 +00:00
|
|
|
|
for (var song in obj.data) {
|
2018-05-25 16:20:26 +00:00
|
|
|
|
nrItems++;
|
2014-01-16 17:32:20 +00:00
|
|
|
|
var minutes = Math.floor(obj.data[song].duration / 60);
|
|
|
|
|
var seconds = obj.data[song].duration - minutes * 60;
|
2018-05-29 20:12:11 +00:00
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#queueList > tbody').append(
|
2014-01-17 15:26:26 +00:00
|
|
|
|
"<tr trackid=\"" + obj.data[song].id + "\"><td>" + (obj.data[song].pos + 1) + "</td>" +
|
2018-05-27 15:30:36 +00:00
|
|
|
|
"<td>"+ obj.data[song].title +"</td>" +
|
2014-11-11 17:41:39 +00:00
|
|
|
|
"<td>"+ obj.data[song].artist +"</td>" +
|
2018-04-23 11:38:58 +00:00
|
|
|
|
"<td>"+ obj.data[song].album +"</td>" +
|
2014-01-16 17:32:20 +00:00
|
|
|
|
"<td>"+ minutes + ":" + (seconds < 10 ? '0' : '') + seconds +
|
2014-01-17 15:26:26 +00:00
|
|
|
|
"</td><td></td></tr>");
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
2018-05-25 16:20:26 +00:00
|
|
|
|
if (obj.type == 'queuesearch' && nrItems == 0) {
|
|
|
|
|
$('#queueList > tbody').append(
|
|
|
|
|
"<tr><td><span class=\"material-icons\">error_outline</span></td>" +
|
|
|
|
|
"<td colspan=\"3\">No results, please refine your search!</td>" +
|
|
|
|
|
"<td></td><td></td></tr>"
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-05-28 22:05:56 +00:00
|
|
|
|
setPagination(obj.totalSongs);
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
2015-10-22 15:48:42 +00:00
|
|
|
|
if ( isTouch ) {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#queueList > tbody > tr > td:last-child').append(
|
2018-05-29 16:27:17 +00:00
|
|
|
|
'<a class="pull-right btn-group-hover color-darkgrey" href="#/queue/' + pagination + '" '+
|
2018-05-29 20:12:11 +00:00
|
|
|
|
'onclick="delQueueSong($(this).parents(\'tr\'));">' +
|
2018-05-29 16:27:17 +00:00
|
|
|
|
'<span class="material-icons">delete</span></a>');
|
2015-10-22 15:48:42 +00:00
|
|
|
|
} else {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#queueList > tbody > tr').on({
|
2015-10-22 15:48:42 +00:00
|
|
|
|
mouseover: function(){
|
2017-04-08 09:25:40 +00:00
|
|
|
|
var doomed = $(this);
|
2018-05-17 22:10:57 +00:00
|
|
|
|
if ( $('#btntrashmodeup').hasClass('btn-success') )
|
2018-05-29 16:27:17 +00:00
|
|
|
|
doomed = $('#queueList > tbody > tr:lt(' + ($(this).index() + 1) + ')');
|
2018-05-17 22:10:57 +00:00
|
|
|
|
if ( $('#btntrashmodedown').hasClass('btn-success') )
|
2018-05-29 16:27:17 +00:00
|
|
|
|
doomed = $('#queueList > tbody > tr:gt(' + ($(this).index() - 1) + ')');
|
2017-04-08 09:25:40 +00:00
|
|
|
|
$.each(doomed, function(){
|
2015-10-22 15:48:42 +00:00
|
|
|
|
if($(this).children().last().has("a").length == 0)
|
|
|
|
|
$(this).children().last().append(
|
2018-05-29 16:27:17 +00:00
|
|
|
|
'<a class="pull-right btn-group-hover color-darkgrey" href="#/queue/' + pagination + '" ' +
|
2018-05-29 20:12:11 +00:00
|
|
|
|
'onclick="delQueueSong($(this).parents(\'tr\'));">' +
|
2018-05-29 16:27:17 +00:00
|
|
|
|
'<span class="material-icons">delete</span></a>')
|
2015-10-22 15:48:42 +00:00
|
|
|
|
.find('a').fadeTo('fast',1);
|
2017-04-08 09:25:40 +00:00
|
|
|
|
});
|
2015-10-22 15:48:42 +00:00
|
|
|
|
},
|
|
|
|
|
mouseleave: function(){
|
2017-04-08 09:25:40 +00:00
|
|
|
|
var doomed = $(this);
|
2018-05-17 22:10:57 +00:00
|
|
|
|
if ( $('#btntrashmodeup').hasClass('btn-success') )
|
2018-05-22 23:07:34 +00:00
|
|
|
|
doomed = $("#queueList > tbody > tr:lt(" + ($(this).index() + 1) + ")");
|
2018-05-17 22:10:57 +00:00
|
|
|
|
if ( $('#btntrashmodedown').hasClass('btn-success') )
|
2018-05-22 23:07:34 +00:00
|
|
|
|
doomed = $("#queueList > tbody > tr:gt(" + ($(this).index() - 1) + ")");
|
2017-04-08 09:25:40 +00:00
|
|
|
|
$.each(doomed, function(){$(this).children().last().find("a").stop().remove();});
|
2015-10-22 15:48:42 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2014-02-22 01:11:45 +00:00
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#queueList > tbody > tr').on({
|
2014-01-16 17:32:20 +00:00
|
|
|
|
click: function() {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#queueList > tbody > tr').removeClass('active');
|
2014-01-16 17:32:20 +00:00
|
|
|
|
socket.send('MPD_API_PLAY_TRACK,'+$(this).attr('trackid'));
|
|
|
|
|
$(this).addClass('active');
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
break;
|
2018-05-28 22:05:56 +00:00
|
|
|
|
case 'playlists':
|
|
|
|
|
if(current_app !== 'browsePlaylists')
|
|
|
|
|
break;
|
|
|
|
|
var nrItems=0;
|
|
|
|
|
for (var item in obj.data) {
|
|
|
|
|
nrItems++;
|
|
|
|
|
var d = new Date(obj.data[item].last_modified * 1000);
|
|
|
|
|
$('#'+current_app+'List > tbody').append(
|
|
|
|
|
'<tr uri="' + encodeURI(obj.data[item].plist) + '">' +
|
|
|
|
|
'<td><span class="material-icons">list</span></td>' +
|
|
|
|
|
'<td><a>' + basename(obj.data[item].plist) + '</a></td>' +
|
|
|
|
|
'<td>'+d.toUTCString()+'</td><td></td></tr>'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
setPagination(obj.totalEntities);
|
|
|
|
|
if ( isTouch ) {
|
|
|
|
|
$('#'+current_app+'List > tbody > tr > td:last-child').append(
|
2018-05-29 20:12:11 +00:00
|
|
|
|
'<a class="pull-right btn-group-hover color-darkgrey" href="#/browse/playlists/' + pagination + '" '+
|
|
|
|
|
'onclick="delPlaylist($(this).parents(\'tr\'));">' +
|
|
|
|
|
'<span class="material-icons">delete</span></a>');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
} else {
|
|
|
|
|
$('#'+current_app+'List > tbody > tr').on({
|
|
|
|
|
mouseover: function(){
|
2018-05-29 20:12:11 +00:00
|
|
|
|
if($(this).children().last().has('a').length == 0)
|
2018-05-28 22:05:56 +00:00
|
|
|
|
$(this).children().last().append(
|
2018-05-29 20:12:11 +00:00
|
|
|
|
'<a class="pull-right btn-group-hover color-darkgrey" href="#/browse/playlists/' + pagination + '" '+
|
|
|
|
|
'onclick="delPlaylist($(this).parents(\'tr\'));">' +
|
|
|
|
|
'<span class="material-icons">delete</span></a>');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
},
|
|
|
|
|
mouseleave: function(){
|
|
|
|
|
var doomed = $(this);
|
|
|
|
|
$(this).children().last().find("a").stop().remove();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
$('#'+current_app+'List > tbody > tr').on({
|
|
|
|
|
click: function() {
|
|
|
|
|
socket.send("MPD_API_ADD_PLAYLIST," + decodeURI($(this).attr("uri")));
|
|
|
|
|
showNotification('"' + $('td:nth-last-child(3)', this).text() + '" added','','','success');
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-05-29 16:07:06 +00:00
|
|
|
|
if (nrItems == 0) {
|
|
|
|
|
$('#'+current_app+'List > tbody').append(
|
|
|
|
|
"<tr><td><span class=\"material-icons\">error_outline</span></td>" +
|
|
|
|
|
"<td colspan=\"3\">No results</td>" +
|
|
|
|
|
"<td></td><td></td></tr>"
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-05-28 22:05:56 +00:00
|
|
|
|
break;
|
2018-02-02 01:14:31 +00:00
|
|
|
|
case 'search':
|
2018-05-29 20:12:11 +00:00
|
|
|
|
$('#searchList > tbody').empty();
|
|
|
|
|
$('#panel-heading-search').text(obj.totalEntities + ' Songs found');
|
2018-02-02 01:14:31 +00:00
|
|
|
|
case 'browse':
|
2018-05-28 22:05:56 +00:00
|
|
|
|
if(current_app !== 'browseFilesystem' && current_app !== 'search')
|
2014-01-16 17:32:20 +00:00
|
|
|
|
break;
|
2018-05-22 23:07:34 +00:00
|
|
|
|
|
Fix browsing for non-ascii entity URI under Safari
Previously, browsing entities with non-ascii characters in their URI
under Safari wouldn't work. Directories would be empty, songs wouldn't
be added. I haven't tried it, but this behavior seems to be common to
Webkit-based browsers, so Chrome would be affected too.
This turned out to be because Safari normalizes all unicode strings to
NFC, breaking the link with MPD-spewed URIs, which are in NFD.
An obvious fix would have been to normalize all URIs to NFD, but
unfortunately, Safari doesn't have `str.normalize()`. Adding
normalization capabilities to our JS side would have involved
introductiing libraries such as `unorm`, which is rather big.
We could have done it on the C side, but it involves introducing `icu`,
which is far from trivial too.
After much fussing around, I stumbled on a simple solution: URI-encode
our URI when creating our browser table row. This magically prevents
Safari from trying to mess with our unicode form before we get the
chance to send it back to our server.
2015-06-21 02:39:42 +00:00
|
|
|
|
/* The use of encodeURI() below might seem useless, but it's not. It prevents
|
|
|
|
|
* some browsers, such as Safari, from changing the normalization form of the
|
|
|
|
|
* URI from NFD to NFC, breaking our link with MPD.
|
|
|
|
|
*/
|
2018-05-22 23:07:34 +00:00
|
|
|
|
var nrItems=0;
|
2014-01-16 17:32:20 +00:00
|
|
|
|
for (var item in obj.data) {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
nrItems++;
|
2014-01-16 17:32:20 +00:00
|
|
|
|
switch(obj.data[item].type) {
|
2018-02-02 01:14:31 +00:00
|
|
|
|
case 'directory':
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#'+current_app+'List > tbody').append(
|
2018-05-29 20:12:11 +00:00
|
|
|
|
'<tr uri="' + encodeURI(obj.data[item].dir) + '" class="dir">' +
|
|
|
|
|
'<td><span class="material-icons">folder_open</span></td>' +
|
|
|
|
|
'<td colspan="3"><a>' + basename(obj.data[item].dir) + '</a></td>' +
|
|
|
|
|
'<td></td><td></td></tr>'
|
2014-02-22 00:57:26 +00:00
|
|
|
|
);
|
|
|
|
|
break;
|
2018-02-02 01:14:31 +00:00
|
|
|
|
case 'song':
|
2014-02-22 00:57:26 +00:00
|
|
|
|
var minutes = Math.floor(obj.data[item].duration / 60);
|
|
|
|
|
var seconds = obj.data[item].duration - minutes * 60;
|
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#'+current_app+'List > tbody').append(
|
2018-05-29 20:12:11 +00:00
|
|
|
|
'<tr uri="' + encodeURI(obj.data[item].uri) + '" class="song">' +
|
|
|
|
|
'<td><span class="material-icons">music_note</span></td>' +
|
|
|
|
|
'<td>' + obj.data[item].title + '</td>' +
|
|
|
|
|
'<td>' + obj.data[item].artist + '</td>' +
|
|
|
|
|
'<td>' + obj.data[item].album + '</td>' +
|
|
|
|
|
'<td>' + minutes + ':' + (seconds < 10 ? '0' : '') + seconds +
|
|
|
|
|
'</td><td></td></tr>'
|
2014-02-22 00:57:26 +00:00
|
|
|
|
);
|
2014-01-16 17:32:20 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-22 23:07:34 +00:00
|
|
|
|
|
2018-05-29 20:12:11 +00:00
|
|
|
|
setPagination(obj.totalEntities);
|
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
if (current_app == 'search')
|
|
|
|
|
if (nrItems == 0) {
|
|
|
|
|
$('#'+current_app+'List > tbody').append(
|
|
|
|
|
"<tr><td><span class=\"material-icons\">error_outline</span></td>" +
|
|
|
|
|
"<td colspan=\"3\">No results, please refine your search!</td>" +
|
|
|
|
|
"<td></td><td></td></tr>"
|
|
|
|
|
);
|
|
|
|
|
}
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
2014-01-17 15:26:26 +00:00
|
|
|
|
function appendClickableIcon(appendTo, onClickAction, glyphicon) {
|
2015-10-22 15:48:42 +00:00
|
|
|
|
$(appendTo).append(
|
2018-05-14 23:13:43 +00:00
|
|
|
|
'<a role="button" class="pull-right btn-group-hover">' +
|
|
|
|
|
'<span class="material-icons">' + glyphicon + '</span></a>')
|
2014-01-17 15:26:26 +00:00
|
|
|
|
.find('a').click(function(e) {
|
|
|
|
|
e.stopPropagation();
|
2015-07-13 18:31:56 +00:00
|
|
|
|
socket.send(onClickAction + "," + decodeURI($(this).parents("tr").attr("uri")));
|
2018-05-22 23:07:34 +00:00
|
|
|
|
showNotification('"' + $('td:nth-last-child(3)', $(this).parents('tr')).text() + '" added','','','success');
|
2018-05-17 22:10:57 +00:00
|
|
|
|
});
|
2014-01-17 15:26:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 15:48:42 +00:00
|
|
|
|
if ( isTouch ) {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
appendClickableIcon($('#'+current_app+'List > tbody > tr.dir > td:last-child'), 'MPD_API_ADD_TRACK', 'playlist_add');
|
|
|
|
|
appendClickableIcon($('#'+current_app+'List > tbody > tr.song > td:last-child'), 'MPD_API_ADD_TRACK', 'playlist_add');
|
2015-10-22 15:48:42 +00:00
|
|
|
|
} else {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#'+current_app+'List > tbody > tr').on({
|
2015-10-22 15:48:42 +00:00
|
|
|
|
mouseenter: function() {
|
|
|
|
|
if($(this).is(".dir"))
|
2018-05-14 23:13:43 +00:00
|
|
|
|
appendClickableIcon($(this).children().last(), 'MPD_API_ADD_TRACK', 'playlist_add');
|
2015-10-22 15:48:42 +00:00
|
|
|
|
else if($(this).is(".song"))
|
2018-05-17 22:10:57 +00:00
|
|
|
|
appendClickableIcon($(this).children().last(), 'MPD_API_ADD_TRACK', 'playlist_add');
|
2015-10-22 15:48:42 +00:00
|
|
|
|
},
|
|
|
|
|
mouseleave: function(){
|
|
|
|
|
$(this).children().last().find("a").stop().remove();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#'+current_app+'List > tbody > tr').on({
|
2014-01-16 17:32:20 +00:00
|
|
|
|
click: function() {
|
2014-02-22 01:11:45 +00:00
|
|
|
|
switch($(this).attr('class')) {
|
|
|
|
|
case 'dir':
|
2015-10-22 09:44:50 +00:00
|
|
|
|
pagination = 0;
|
|
|
|
|
browsepath = $(this).attr("uri");
|
2018-05-28 22:05:56 +00:00
|
|
|
|
$("#browseFilesystemList > a").attr("href", '#/browse/filesystem/'+pagination+'/'+browsepath);
|
|
|
|
|
app.setLocation('#/browse/filesystem/'+pagination+'/'+browsepath);
|
2014-02-22 01:11:45 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'song':
|
2015-07-13 18:31:56 +00:00
|
|
|
|
socket.send("MPD_API_ADD_TRACK," + decodeURI($(this).attr("uri")));
|
2018-05-22 23:07:34 +00:00
|
|
|
|
showNotification('"' + $('td:nth-last-child(3)', this).text() + '" added','','','success');
|
2014-02-22 01:11:45 +00:00
|
|
|
|
break;
|
2014-02-22 00:57:26 +00:00
|
|
|
|
}
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#browseBreadcrumb > li > a').on({
|
|
|
|
|
click: function() {
|
|
|
|
|
pagination = 0;
|
|
|
|
|
browsepath = $(this).attr("uri");
|
2018-05-28 22:05:56 +00:00
|
|
|
|
$("#browseFilesystemList > a").attr("href", '#/browse/filesystem/'+pagination+'/'+browsepath);
|
|
|
|
|
app.setLocation('#/browse/filesystem/'+pagination+'/'+browsepath);
|
2018-05-22 23:07:34 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2018-05-13 20:45:23 +00:00
|
|
|
|
|
2014-01-16 17:32:20 +00:00
|
|
|
|
break;
|
2018-02-04 00:11:41 +00:00
|
|
|
|
case 'state':
|
2014-01-16 17:32:20 +00:00
|
|
|
|
updatePlayIcon(obj.data.state);
|
|
|
|
|
updateVolumeIcon(obj.data.volume);
|
|
|
|
|
|
|
|
|
|
if(JSON.stringify(obj) === JSON.stringify(last_state))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
current_song.totalTime = obj.data.totalTime;
|
|
|
|
|
current_song.currentSongId = obj.data.currentsongid;
|
|
|
|
|
var total_minutes = Math.floor(obj.data.totalTime / 60);
|
|
|
|
|
var total_seconds = obj.data.totalTime - total_minutes * 60;
|
|
|
|
|
|
|
|
|
|
var elapsed_minutes = Math.floor(obj.data.elapsedTime / 60);
|
|
|
|
|
var elapsed_seconds = obj.data.elapsedTime - elapsed_minutes * 60;
|
|
|
|
|
|
2018-05-21 23:36:05 +00:00
|
|
|
|
volumeBar.slider('setValue',obj.data.volume);
|
2014-01-16 17:32:20 +00:00
|
|
|
|
var progress = Math.floor(100*obj.data.elapsedTime/obj.data.totalTime);
|
2018-05-21 23:36:05 +00:00
|
|
|
|
progressBar.slider('setValue',progress);
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
2018-05-27 16:31:47 +00:00
|
|
|
|
var counterText=elapsed_minutes + ":" +
|
2014-01-16 17:32:20 +00:00
|
|
|
|
(elapsed_seconds < 10 ? '0' : '') + elapsed_seconds + " / " +
|
2018-05-27 16:31:47 +00:00
|
|
|
|
total_minutes + ":" + (total_seconds < 10 ? '0' : '') + total_seconds;
|
|
|
|
|
|
|
|
|
|
$('#counter').text(counterText);
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
2018-05-27 16:22:16 +00:00
|
|
|
|
if (last_state) {
|
|
|
|
|
$('#queueList > tbody > tr[trackid='+last_state.data.currentsongid+'] > td').eq(4).text(last_state.data.totalTime);
|
|
|
|
|
$('#queueList > tbody > tr[trackid='+last_state.data.currentsongid+'] > td').eq(0).removeClass('material-icons').text(last_state.data.songpos);
|
|
|
|
|
}
|
2018-05-23 22:32:01 +00:00
|
|
|
|
$('#queueList > tbody > tr').removeClass('active').css("font-weight", "");
|
2018-05-27 16:22:16 +00:00
|
|
|
|
|
2018-05-27 16:31:47 +00:00
|
|
|
|
$('#queueList > tbody > tr[trackid='+obj.data.currentsongid+'] > td').eq(4).text(counterText);
|
2018-05-27 16:22:16 +00:00
|
|
|
|
$('#queueList > tbody > tr[trackid='+obj.data.currentsongid+'] > td').eq(0).addClass('material-icons').text('play_arrow');
|
2018-05-23 22:32:01 +00:00
|
|
|
|
$('#queueList > tbody > tr[trackid='+obj.data.currentsongid+']').addClass('active').css("font-weight", "bold");
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
2018-05-28 18:48:43 +00:00
|
|
|
|
|
2014-01-16 17:32:20 +00:00
|
|
|
|
last_state = obj;
|
|
|
|
|
break;
|
2018-02-04 00:11:41 +00:00
|
|
|
|
case 'outputnames':
|
2015-04-28 09:08:21 +00:00
|
|
|
|
$('#btn-outputs-block button').remove();
|
2018-04-23 11:38:58 +00:00
|
|
|
|
if ( Object.keys(obj.data).length ) {
|
2018-02-03 23:30:45 +00:00
|
|
|
|
$.each(obj.data, function(id, name){
|
2018-05-17 22:10:57 +00:00
|
|
|
|
var btn = $('<button id="btnoutput'+id+'" class="btn btn-secondary btn-block" onclick="toggleoutput(this, '+id+')">'+
|
|
|
|
|
'<span class="material-icons" style="float:left;">volume_up</span> '+name+'</button>');
|
2018-02-03 23:30:45 +00:00
|
|
|
|
btn.appendTo($('#btn-outputs-block'));
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2018-02-04 00:11:41 +00:00
|
|
|
|
$('#btn-outputs-block').addClass('hide');
|
2018-02-03 23:30:45 +00:00
|
|
|
|
}
|
2015-04-28 09:08:21 +00:00
|
|
|
|
/* remove cache, since the buttons have been recreated */
|
|
|
|
|
last_outputs = '';
|
|
|
|
|
break;
|
2018-02-04 00:11:41 +00:00
|
|
|
|
case 'outputs':
|
2015-04-28 09:08:21 +00:00
|
|
|
|
if(JSON.stringify(obj) === JSON.stringify(last_outputs))
|
|
|
|
|
break;
|
|
|
|
|
$.each(obj.data, function(id, enabled){
|
|
|
|
|
if (enabled)
|
2018-05-14 23:13:43 +00:00
|
|
|
|
$('#btnoutput'+id).removeClass('btn-secondary').addClass("btn-success")
|
2015-04-28 09:08:21 +00:00
|
|
|
|
else
|
2018-05-14 23:13:43 +00:00
|
|
|
|
$('#btnoutput'+id).removeClass("btn-success").addClass("btn-secondary");
|
2015-04-28 09:08:21 +00:00
|
|
|
|
});
|
|
|
|
|
last_outputs = obj;
|
|
|
|
|
break;
|
2018-02-04 00:11:41 +00:00
|
|
|
|
case 'disconnected':
|
2018-05-22 23:07:34 +00:00
|
|
|
|
showNotification('myMPD lost connection to MPD','','','danger');
|
2018-05-27 13:10:34 +00:00
|
|
|
|
|
2014-01-16 17:32:20 +00:00
|
|
|
|
break;
|
2018-02-04 00:11:41 +00:00
|
|
|
|
case 'update_queue':
|
2018-05-23 22:32:01 +00:00
|
|
|
|
if(current_app === 'queue') {
|
2014-02-22 01:11:45 +00:00
|
|
|
|
socket.send('MPD_API_GET_QUEUE,'+pagination);
|
2018-05-23 22:32:01 +00:00
|
|
|
|
}
|
2014-01-16 17:32:20 +00:00
|
|
|
|
break;
|
2018-05-24 17:50:05 +00:00
|
|
|
|
case "song_change":
|
2018-05-23 23:42:20 +00:00
|
|
|
|
songChange(obj.data.title, obj.data.artist, obj.data.album, obj.data.uri);
|
2014-02-04 16:58:10 +00:00
|
|
|
|
break;
|
2018-05-29 21:05:34 +00:00
|
|
|
|
case 'settings':
|
|
|
|
|
if(obj.data.random)
|
|
|
|
|
$('#btnrandom').removeClass('btn-secondary').addClass("btn-success")
|
|
|
|
|
else
|
|
|
|
|
$('#btnrandom').removeClass("btn-success").addClass("btn-secondary");
|
|
|
|
|
|
|
|
|
|
if(obj.data.consume)
|
|
|
|
|
$('#btnconsume').removeClass('btn-secondary').addClass("btn-success")
|
|
|
|
|
else
|
|
|
|
|
$('#btnconsume').removeClass("btn-success").addClass("btn-secondary");
|
|
|
|
|
|
|
|
|
|
if(obj.data.single)
|
|
|
|
|
$('#btnsingle').removeClass('btn-secondary').addClass("btn-success")
|
|
|
|
|
else
|
|
|
|
|
$('#btnsingle').removeClass("btn-success").addClass("btn-secondary");
|
|
|
|
|
|
|
|
|
|
if(obj.data.crossfade != undefined) {
|
|
|
|
|
$('#inputCrossfade').removeAttr('disabled');
|
|
|
|
|
$('#inputCrossfade').val(obj.data.crossfade);
|
|
|
|
|
} else {
|
|
|
|
|
$('#inputCrossfade').attr('disabled', 'disabled');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(obj.data.mixrampdb != undefined) {
|
|
|
|
|
$('#inputMixrampdb').removeAttr('disabled');
|
|
|
|
|
$('#inputMixrampdb').val(obj.data.mixrampdb);
|
|
|
|
|
} else {
|
|
|
|
|
$('#inputMixrampdb').attr('disabled', 'disabled');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(obj.data.mixrampdelay != undefined) {
|
|
|
|
|
$('#inputMixrampdelay').removeAttr('disabled');
|
|
|
|
|
$('#inputMixrampdelay').val(obj.data.mixrampdelay);
|
|
|
|
|
} else {
|
|
|
|
|
$('#inputMixrampdb').attr('disabled', 'disabled');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(obj.data.repeat)
|
|
|
|
|
$('#btnrepeat').removeClass('btn-secondary').addClass("btn-success")
|
|
|
|
|
else
|
|
|
|
|
$('#btnrepeat').removeClass("btn-success").addClass("btn-secondary");
|
|
|
|
|
|
2018-05-24 17:50:05 +00:00
|
|
|
|
setLocalStream(obj.data.mpdhost,obj.data.streamport);
|
2018-05-27 14:14:56 +00:00
|
|
|
|
coverImageFile=obj.data.coverimage;
|
2013-11-07 09:09:40 +00:00
|
|
|
|
break;
|
2018-05-27 21:34:39 +00:00
|
|
|
|
case 'mpdstats':
|
|
|
|
|
$('#mpdstats_artists').text(obj.data.artists);
|
|
|
|
|
$('#mpdstats_albums').text(obj.data.albums);
|
|
|
|
|
$('#mpdstats_songs').text(obj.data.songs);
|
|
|
|
|
$('#mpdstats_dbplaytime').text(beautifyDuration(obj.data.dbplaytime));
|
|
|
|
|
$('#mpdstats_playtime').text(beautifyDuration(obj.data.playtime));
|
|
|
|
|
$('#mpdstats_uptime').text(beautifyDuration(obj.data.uptime));
|
|
|
|
|
var d = new Date(obj.data.dbupdated * 1000);
|
|
|
|
|
$('#mpdstats_dbupdated').text(d.toUTCString());
|
2018-05-29 21:05:34 +00:00
|
|
|
|
$('#mympdVersion').text(obj.data.mympd_version);
|
2018-05-27 21:34:39 +00:00
|
|
|
|
break;
|
2018-02-04 00:11:41 +00:00
|
|
|
|
case 'error':
|
2018-05-22 23:07:34 +00:00
|
|
|
|
showNotification(obj.data,'','','danger');
|
2014-01-16 17:32:20 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-04 11:50:44 +00:00
|
|
|
|
|
2014-01-16 17:32:20 +00:00
|
|
|
|
socket.onclose = function(){
|
2018-05-27 13:10:34 +00:00
|
|
|
|
console.log('disconnected');
|
|
|
|
|
$('#modalConnectionError').modal('show');
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
console.log('reconnect');
|
|
|
|
|
webSocketConnect();
|
|
|
|
|
},3000);
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch(exception) {
|
|
|
|
|
alert('<p>Error' + exception);
|
|
|
|
|
}
|
2013-11-04 17:18:38 +00:00
|
|
|
|
|
2013-11-05 13:59:12 +00:00
|
|
|
|
}
|
2013-11-04 23:17:28 +00:00
|
|
|
|
|
2013-11-04 17:18:38 +00:00
|
|
|
|
function get_appropriate_ws_url()
|
|
|
|
|
{
|
2014-01-16 17:32:20 +00:00
|
|
|
|
var pcol;
|
|
|
|
|
var u = document.URL;
|
2016-07-07 13:22:15 +00:00
|
|
|
|
var separator;
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
/* We open the websocket encrypted if this page came on an
|
|
|
|
|
/* https:// url itself, otherwise unencrypted
|
|
|
|
|
/*/
|
|
|
|
|
|
|
|
|
|
if (u.substring(0, 5) == "https") {
|
|
|
|
|
pcol = "wss://";
|
|
|
|
|
u = u.substr(8);
|
|
|
|
|
} else {
|
|
|
|
|
pcol = "ws://";
|
|
|
|
|
if (u.substring(0, 4) == "http")
|
|
|
|
|
u = u.substr(7);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-02 13:29:43 +00:00
|
|
|
|
u = u.split('#');
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
2016-07-07 13:22:15 +00:00
|
|
|
|
if (/\/$/.test(u[0])) {
|
|
|
|
|
separator = "";
|
|
|
|
|
} else {
|
|
|
|
|
separator = "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pcol + u[0] + separator + "ws";
|
2013-11-04 17:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-28 22:05:56 +00:00
|
|
|
|
function setPagination(number) {
|
|
|
|
|
var totalPages=Math.ceil(number / MAX_ELEMENTS_PER_PAGE);
|
|
|
|
|
if (totalPages==0) { totalPages=1; }
|
|
|
|
|
$('#'+current_app+'PaginationTopPage').text('Page '+(pagination / MAX_ELEMENTS_PER_PAGE + 1)+' / '+totalPages);
|
|
|
|
|
$('#'+current_app+'PaginationBottomPage').text('Page '+(pagination / MAX_ELEMENTS_PER_PAGE + 1)+' / '+totalPages);
|
|
|
|
|
if (totalPages > 1) {
|
|
|
|
|
$('#'+current_app+'PaginationTopPage').removeClass('disabled');
|
|
|
|
|
$('#'+current_app+'PaginationBottomPage').removeClass('disabled');
|
|
|
|
|
$('#'+current_app+'PaginationTopPages').empty();
|
|
|
|
|
$('#'+current_app+'PaginationBottomPages').empty();
|
|
|
|
|
for (var i=0;i<totalPages;i++) {
|
|
|
|
|
$('#'+current_app+'PaginationTopPages').append('<button onclick="gotoPage('+(i * MAX_ELEMENTS_PER_PAGE)+',this,event)" type="button" class="mr-1 mb-1 btn btn-secondary">'+(i+1)+'</button>');
|
|
|
|
|
$('#'+current_app+'PaginationBottomPages').append('<button onclick="gotoPage('+(i * MAX_ELEMENTS_PER_PAGE)+',this,event)" type="button" class="mr-1 mb-1 btn btn-secondary">'+(i+1)+'</button>');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$('#'+current_app+'PaginationTopPage').addClass('disabled');
|
|
|
|
|
$('#'+current_app+'PaginationBottomPage').addClass('disabled');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(number > pagination + MAX_ELEMENTS_PER_PAGE) {
|
|
|
|
|
$('#'+current_app+'PaginationTopNext').removeClass('disabled');
|
|
|
|
|
$('#'+current_app+'PaginationBottomNext').removeClass('disabled');
|
|
|
|
|
$('#'+current_app+'ButtonsBottom').removeClass('hide');
|
|
|
|
|
} else {
|
|
|
|
|
$('#'+current_app+'PaginationTopNext').addClass('disabled');
|
|
|
|
|
$('#'+current_app+'PaginationBottomNext').addClass('disabled');
|
|
|
|
|
$('#'+current_app+'ButtonsBottom').addClass('hide');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(pagination > 0) {
|
|
|
|
|
$('#'+current_app+'PaginationTopPrev').removeClass('disabled');
|
|
|
|
|
$('#'+current_app+'PaginationBottomPrev').removeClass('disabled');
|
|
|
|
|
} else {
|
|
|
|
|
$('#'+current_app+'PaginationTopPrev').addClass('disabled');
|
|
|
|
|
$('#'+current_app+'PaginationBottomPrev').addClass('disabled');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-23 23:42:20 +00:00
|
|
|
|
function updateVolumeIcon(volume) {
|
2018-05-28 18:48:43 +00:00
|
|
|
|
if (volume == -1) {
|
|
|
|
|
$('#volumePrct').text('Volumecontrol disabled');
|
|
|
|
|
$('#volumeControl').addClass('hide');
|
2014-01-16 17:32:20 +00:00
|
|
|
|
} else {
|
2018-05-28 18:48:43 +00:00
|
|
|
|
$('#volumeControl').removeClass('hidden');
|
|
|
|
|
$('#volumePrct').text(volume+' %');
|
|
|
|
|
if(volume == 0) {
|
|
|
|
|
$("#volume-icon").text("volume_off");
|
|
|
|
|
} else if (volume < 50) {
|
|
|
|
|
$("#volume-icon").text("volume_down");
|
|
|
|
|
} else {
|
|
|
|
|
$("#volume-icon").text("volume_up");
|
|
|
|
|
}
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
2013-11-04 17:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-23 23:42:20 +00:00
|
|
|
|
function updatePlayIcon(state) {
|
2018-05-14 23:13:43 +00:00
|
|
|
|
$("#play-icon").text('play_arrow');
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
|
|
|
|
if(state == 1) { // stop
|
2018-05-14 23:13:43 +00:00
|
|
|
|
$("#play-icon").text('play_arrow');
|
2018-05-16 23:19:03 +00:00
|
|
|
|
playstate = 'stop';
|
2015-12-08 15:42:03 +00:00
|
|
|
|
} else if(state == 2) { // play
|
2018-05-14 23:13:43 +00:00
|
|
|
|
$("#play-icon").text('pause');
|
2018-05-16 23:19:03 +00:00
|
|
|
|
playstate = 'play';
|
2015-12-08 15:42:03 +00:00
|
|
|
|
} else { // pause
|
2018-05-14 23:13:43 +00:00
|
|
|
|
$("#play-icon").text('play_arrow');
|
2018-05-16 23:19:03 +00:00
|
|
|
|
playstate = 'pause';
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
2013-11-04 23:17:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-17 15:26:26 +00:00
|
|
|
|
function updateDB() {
|
2014-01-16 17:32:20 +00:00
|
|
|
|
socket.send('MPD_API_UPDATE_DB');
|
2018-05-22 23:07:34 +00:00
|
|
|
|
showNotification('Updating MPD Database...','','','success');
|
2013-11-04 17:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-17 15:26:26 +00:00
|
|
|
|
function clickPlay() {
|
2018-05-16 23:19:03 +00:00
|
|
|
|
if( playstate != 'play')
|
2014-01-17 15:26:26 +00:00
|
|
|
|
socket.send('MPD_API_SET_PLAY');
|
|
|
|
|
else
|
|
|
|
|
socket.send('MPD_API_SET_PAUSE');
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-24 17:50:05 +00:00
|
|
|
|
function setLocalStream(mpdhost,streamport) {
|
|
|
|
|
var mpdstream = 'http://';
|
|
|
|
|
if ( mpdhost == '127.0.0.1' || mpdhost == 'localhost')
|
|
|
|
|
mpdstream += window.location.hostname;
|
|
|
|
|
else
|
|
|
|
|
mpdstream += mpdhost;
|
|
|
|
|
mpdstream += ':'+streamport+'/';
|
|
|
|
|
Cookies.set('mpdstream', mpdstream, { expires: 424242 });
|
2014-05-24 16:23:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-29 20:12:11 +00:00
|
|
|
|
function delQueueSong(tr) {
|
2018-05-17 22:10:57 +00:00
|
|
|
|
if ( $('#btntrashmodeup').hasClass('btn-success') ) {
|
2017-04-08 09:25:40 +00:00
|
|
|
|
socket.send('MPD_API_RM_RANGE,0,' + (tr.index() + 1));
|
|
|
|
|
tr.remove();
|
2018-05-17 22:10:57 +00:00
|
|
|
|
} else if ( $('#btntrashmodesingle').hasClass('btn-success') ) {
|
2017-04-08 09:25:40 +00:00
|
|
|
|
socket.send('MPD_API_RM_TRACK,' + tr.attr('trackid'));
|
|
|
|
|
tr.remove();
|
2018-05-17 22:10:57 +00:00
|
|
|
|
} else if ( $('#btntrashmodedown').hasClass('btn-success') ) {
|
2017-04-08 09:25:40 +00:00
|
|
|
|
socket.send('MPD_API_RM_RANGE,' + tr.index() + ',-1');
|
|
|
|
|
tr.remove();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-29 20:12:11 +00:00
|
|
|
|
function delPlaylist(tr) {
|
|
|
|
|
socket.send("MPD_API_RM_PLAYLIST," + decodeURI(tr.attr("uri")));
|
|
|
|
|
tr.remove();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-13 14:30:54 +00:00
|
|
|
|
function basename(path) {
|
2014-01-16 17:32:20 +00:00
|
|
|
|
return path.split('/').reverse()[0];
|
2013-11-13 14:30:54 +00:00
|
|
|
|
}
|
2013-11-07 09:09:40 +00:00
|
|
|
|
|
2018-05-29 21:05:34 +00:00
|
|
|
|
function toggleBtn(btn) {
|
|
|
|
|
if ($(btn).hasClass('btn-success')) {
|
|
|
|
|
$(btn).removeClass('btn-success').addClass('btn-secondary');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$(btn).removeClass('btn-secondary').addClass('btn-success');
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-07 09:09:40 +00:00
|
|
|
|
|
2018-05-29 21:05:34 +00:00
|
|
|
|
$('#btnrandom').on('click', function (e) {
|
|
|
|
|
socket.send("MPD_API_TOGGLE_RANDOM," + ($(this).hasClass('btn-success') ? 0 : 1));
|
|
|
|
|
toggleBtn(this);
|
2013-11-07 09:09:40 +00:00
|
|
|
|
});
|
|
|
|
|
$('#btnconsume').on('click', function (e) {
|
2018-05-14 23:13:43 +00:00
|
|
|
|
socket.send("MPD_API_TOGGLE_CONSUME," + ($(this).hasClass('btn-success') ? 0 : 1));
|
2018-05-29 21:05:34 +00:00
|
|
|
|
toggleBtn(this);
|
2013-11-07 09:09:40 +00:00
|
|
|
|
});
|
|
|
|
|
$('#btnsingle').on('click', function (e) {
|
2018-05-14 23:13:43 +00:00
|
|
|
|
socket.send("MPD_API_TOGGLE_SINGLE," + ($(this).hasClass('btn-success') ? 0 : 1));
|
2018-05-29 21:05:34 +00:00
|
|
|
|
toggleBtn(this);
|
2013-11-07 09:09:40 +00:00
|
|
|
|
});
|
2018-05-28 18:48:43 +00:00
|
|
|
|
|
2013-11-07 09:09:40 +00:00
|
|
|
|
$('#btnrepeat').on('click', function (e) {
|
2018-05-14 23:13:43 +00:00
|
|
|
|
socket.send("MPD_API_TOGGLE_REPEAT," + ($(this).hasClass('btn-success') ? 0 : 1));
|
2018-05-29 21:05:34 +00:00
|
|
|
|
toggleBtn(this);
|
2013-11-07 09:09:40 +00:00
|
|
|
|
});
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
2018-05-28 18:48:43 +00:00
|
|
|
|
function confirmSettings() {
|
|
|
|
|
var value=parseInt($('#inputCrossfade').val());
|
|
|
|
|
if (!isNaN(value)) {
|
|
|
|
|
$('#inputCrossfade').val(value);
|
|
|
|
|
socket.send("MPD_API_SET_CROSSFADE," + value);
|
|
|
|
|
} else {
|
|
|
|
|
$('#inputCrossfade').popover({"content":"Must be a number","trigger":"manual"});
|
|
|
|
|
$('#inputCrossfade').popover('show');
|
|
|
|
|
$('#inputCrossfade').focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
value=parseFloat($('#inputMixrampdb').val());
|
|
|
|
|
if (!isNaN(value)) {
|
|
|
|
|
$('#inputMixrampdb').val(value);
|
|
|
|
|
socket.send("MPD_API_SET_MIXRAMPDB," + value);
|
|
|
|
|
} else {
|
|
|
|
|
$('#inputMixrampdb').popover({"content":"Must be a number","trigger":"manual"});
|
|
|
|
|
$('#inputMixrampdb').popover('show');
|
|
|
|
|
$('#inputMixrampdb').focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
value=parseFloat($('#inputMixrampdelay').val());
|
|
|
|
|
if (!isNaN(value)) {
|
|
|
|
|
$('#inputMixrampdelay').val(value);
|
|
|
|
|
socket.send("MPD_API_SET_MIXRAMPDELAY," + value);
|
|
|
|
|
} else {
|
|
|
|
|
$('#inputMixrampdelay').popover({"content":"Must be a number","trigger":"manual"});
|
|
|
|
|
$('#inputMixrampdelay').popover('show');
|
|
|
|
|
$('#inputMixrampdelay').focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$('#settings').modal('hide');
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-28 09:08:21 +00:00
|
|
|
|
function toggleoutput(button, id) {
|
2018-05-14 23:13:43 +00:00
|
|
|
|
socket.send("MPD_API_TOGGLE_OUTPUT,"+id+"," + ($(button).hasClass('btn-success') ? 0 : 1));
|
2015-04-28 09:08:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-27 12:37:50 +00:00
|
|
|
|
$('#trashmodebtns > button').on('click', function(e) {
|
|
|
|
|
$('#trashmodebtns').children("button").removeClass("btn-success").addClass('btn-secondary');
|
2018-05-14 23:13:43 +00:00
|
|
|
|
$(this).removeClass("btn-secondary").addClass("btn-success");
|
2017-04-08 09:25:40 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#btnnotifyWeb').on('click', function (e) {
|
2018-05-24 17:50:05 +00:00
|
|
|
|
if(Cookies.get('notificationWeb') === 'true') {
|
|
|
|
|
Cookies.set('notificationWeb', false, { expires: 424242 });
|
2018-05-25 16:12:46 +00:00
|
|
|
|
$('#btnnotifyWeb').removeClass('btn-success').addClass('btn-secondary');
|
2014-05-24 00:57:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
Notification.requestPermission(function (permission) {
|
|
|
|
|
if(!('permission' in Notification)) {
|
|
|
|
|
Notification.permission = permission;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
if (permission === 'granted') {
|
2018-05-24 17:50:05 +00:00
|
|
|
|
Cookies.set('notificationWeb', true, { expires: 424242 });
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#btnnotifyWeb').removeClass('btn-secondary').addClass('btn-success');
|
2014-05-24 00:57:30 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2014-01-17 17:34:22 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#btnnotifyPage').on('click', function (e) {
|
2018-05-24 17:50:05 +00:00
|
|
|
|
if(Cookies.get("notificationPage") === 'true') {
|
|
|
|
|
Cookies.set("notificationPage", false, { expires: 424242 });
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#btnnotifyPage').removeClass('btn-success').addClass('btn-secondary');
|
|
|
|
|
} else {
|
2018-05-24 17:50:05 +00:00
|
|
|
|
Cookies.set('notificationPage', true, { expires: 424242 });
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#btnnotifyPage').removeClass('btn-secondary').addClass('btn-success');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-23 22:32:01 +00:00
|
|
|
|
$('#search > input').keypress(function (event) {
|
|
|
|
|
if ( event.which == 13 ) {
|
|
|
|
|
$('#mainMenu > a').dropdown('toggle');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2014-02-22 00:57:26 +00:00
|
|
|
|
$('#search').submit(function () {
|
2018-05-29 20:12:11 +00:00
|
|
|
|
doSearch($('#search > input').val());
|
2014-02-22 00:57:26 +00:00
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-29 20:12:11 +00:00
|
|
|
|
function doSearch(searchstr) {
|
|
|
|
|
var mpdtag='Any Tag';
|
|
|
|
|
$('#searchtags2 > button').each(function() {
|
|
|
|
|
if ($(this).hasClass('btn-success')) { mpdtag=$(this).text(); }
|
|
|
|
|
});
|
|
|
|
|
app.setLocation('#/search/' + pagination + '/' + mpdtag + '/' + searchstr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#searchstr2').keyup(function (event) {
|
|
|
|
|
pagination=0;
|
|
|
|
|
doSearch($(this).val());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#searchtags2 > button').on('click',function (e) {
|
|
|
|
|
$('#searchtags2 > button').removeClass('btn-success').addClass('btn-secondary');
|
|
|
|
|
$(this).removeClass('btn-secondary').addClass('btn-success');
|
|
|
|
|
doSearch($('#searchstr2').val());
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-27 12:37:50 +00:00
|
|
|
|
$('#searchqueuestr').keyup(function (event) {
|
2018-05-27 20:21:18 +00:00
|
|
|
|
pagination=0;
|
2018-05-27 12:37:50 +00:00
|
|
|
|
doQueueSearch();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#searchqueuetag > button').on('click',function (e) {
|
|
|
|
|
$('#searchqueuetag > button').removeClass('btn-success').addClass('btn-secondary');
|
|
|
|
|
$(this).removeClass('btn-secondary').addClass('btn-success');
|
|
|
|
|
doQueueSearch();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function doQueueSearch() {
|
|
|
|
|
var searchstr=$('#searchqueuestr').val();
|
|
|
|
|
var mpdtag='Any Tag';
|
|
|
|
|
$('#searchqueuetag > button').each(function() {
|
|
|
|
|
if ($(this).hasClass('btn-success')) { mpdtag=$(this).text(); }
|
|
|
|
|
});
|
2018-05-29 20:12:11 +00:00
|
|
|
|
app.setLocation('#/queue/' + pagination + '/' + mpdtag + '/' + searchstr);
|
2018-05-27 12:37:50 +00:00
|
|
|
|
}
|
2018-05-24 22:21:19 +00:00
|
|
|
|
|
|
|
|
|
$('#searchqueue').submit(function () {
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-27 20:21:18 +00:00
|
|
|
|
function scrollToTop() {
|
|
|
|
|
document.body.scrollTop = 0; // For Safari
|
|
|
|
|
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function gotoPage(x,element,event) {
|
|
|
|
|
if ($(element).hasClass('disabled')) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (x) {
|
|
|
|
|
case "next":
|
|
|
|
|
pagination += MAX_ELEMENTS_PER_PAGE;
|
|
|
|
|
break;
|
|
|
|
|
case "prev":
|
|
|
|
|
pagination -= MAX_ELEMENTS_PER_PAGE;
|
|
|
|
|
if(pagination <= 0)
|
|
|
|
|
pagination = 0;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
pagination = x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(current_app) {
|
|
|
|
|
case "queue":
|
|
|
|
|
if ($('#searchqueuestr').val().length >=3) {
|
|
|
|
|
doQueueSearch();
|
|
|
|
|
} else {
|
|
|
|
|
app.setLocation('#/queue/'+pagination);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2018-05-29 20:12:11 +00:00
|
|
|
|
case "search":
|
|
|
|
|
doSearch($('#searchstr2').val());
|
|
|
|
|
break;
|
2018-05-28 22:05:56 +00:00
|
|
|
|
case "browseFilesystem":
|
|
|
|
|
app.setLocation('#/browse/filesystem/'+pagination+'/'+browsepath);
|
|
|
|
|
break;
|
|
|
|
|
case "browsePlaylists":
|
|
|
|
|
app.setLocation('#/browse/playlists/'+pagination);
|
2018-05-27 20:21:18 +00:00
|
|
|
|
break;
|
2018-05-28 22:05:56 +00:00
|
|
|
|
case "browseDatabase":
|
|
|
|
|
app.setLocation('#/browse/database/'+pagination);
|
|
|
|
|
break;
|
2018-05-27 20:21:18 +00:00
|
|
|
|
}
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-06 11:40:14 +00:00
|
|
|
|
function addStream() {
|
|
|
|
|
if($('#streamurl').val().length > 0) {
|
2017-04-08 09:25:40 +00:00
|
|
|
|
socket.send('MPD_API_ADD_TRACK,'+$('#streamurl').val());
|
2015-03-06 11:40:14 +00:00
|
|
|
|
}
|
2015-07-16 09:50:54 +00:00
|
|
|
|
$('#streamurl').val("");
|
2015-03-06 11:40:14 +00:00
|
|
|
|
$('#addstream').modal('hide');
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-02 17:24:52 +00:00
|
|
|
|
function saveQueue() {
|
|
|
|
|
if($('#playlistname').val().length > 0) {
|
2017-04-08 09:25:40 +00:00
|
|
|
|
socket.send('MPD_API_SAVE_QUEUE,'+$('#playlistname').val());
|
2015-09-02 17:24:52 +00:00
|
|
|
|
}
|
|
|
|
|
$('#savequeue').modal('hide');
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
function showNotification(notificationTitle,notificationText,notificationHtml,notificationType) {
|
2018-05-24 17:50:05 +00:00
|
|
|
|
if (Cookies.get('notificationWeb') === 'true') {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
var notification = new Notification(notificationTitle, {icon: 'assets/favicon.ico', body: notificationText});
|
|
|
|
|
setTimeout(function(notification) {
|
|
|
|
|
notification.close();
|
|
|
|
|
}, 3000, notification);
|
|
|
|
|
}
|
2018-05-24 17:50:05 +00:00
|
|
|
|
if (Cookies.get('notificationPage') === 'true') {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$.notify({ title: notificationTitle, message: notificationHtml},{ type: notificationType, offset: { y: 60, x:20 },
|
|
|
|
|
template: '<div data-notify="container" class="col-xs-11 col-sm-3 alert alert-{0}" role="alert">' +
|
|
|
|
|
'<button type="button" aria-hidden="true" class="close" data-notify="dismiss">×</button>' +
|
|
|
|
|
'<span data-notify="icon"></span> ' +
|
|
|
|
|
'<span data-notify="title">{1}</span> ' +
|
|
|
|
|
'<span data-notify="message">{2}</span>' +
|
|
|
|
|
'<div class="progress" data-notify="progressbar">' +
|
|
|
|
|
'<div class="progress-bar progress-bar-{0}" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"></div>' +
|
|
|
|
|
'</div>' +
|
|
|
|
|
'<a href="{3}" target="{4}" data-notify="url"></a>' +
|
|
|
|
|
'</div>'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-17 17:34:22 +00:00
|
|
|
|
function notificationsSupported() {
|
2014-05-24 00:57:30 +00:00
|
|
|
|
return "Notification" in window;
|
2014-01-17 17:34:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-23 23:42:20 +00:00
|
|
|
|
function songChange(title, artist, album, uri) {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
var textNotification = '';
|
|
|
|
|
var htmlNotification = '';
|
|
|
|
|
var pageTitle = 'myMPD: ';
|
2018-05-23 23:42:20 +00:00
|
|
|
|
|
|
|
|
|
if (typeof uri != 'undefined' && uri.length > 0) {
|
2018-05-24 00:07:34 +00:00
|
|
|
|
var coverImg='';
|
|
|
|
|
if (uri.indexOf('http://') == 0) {
|
|
|
|
|
coverImg='/assets/httpstream.png';
|
|
|
|
|
} else {
|
2018-05-27 14:14:56 +00:00
|
|
|
|
coverImg='/library/'+uri.replace(/\/[^\/]+$/,'\/'+coverImageFile);
|
2018-05-24 00:07:34 +00:00
|
|
|
|
}
|
2018-05-23 23:42:20 +00:00
|
|
|
|
$('#album-cover').css('backgroundImage','url("'+coverImg+'")');
|
|
|
|
|
}
|
|
|
|
|
if(typeof artist != 'undefined' && artist.length > 0 && artist != '-') {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
textNotification += artist;
|
|
|
|
|
htmlNotification += '<br/>' + artist;
|
|
|
|
|
pageTitle += artist + ' - ';
|
2018-05-23 23:42:20 +00:00
|
|
|
|
$('#artist').text(artist);
|
|
|
|
|
} else {
|
|
|
|
|
$('#artist').text('');
|
2018-05-22 23:07:34 +00:00
|
|
|
|
}
|
2018-05-23 23:42:20 +00:00
|
|
|
|
if(typeof album != 'undefined' && album.length > 0 && album != '-') {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
textNotification += ' - ' + album;
|
|
|
|
|
htmlNotification += '<br/>' + album;
|
2018-05-23 23:42:20 +00:00
|
|
|
|
$('#album').text(album);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$('#album').text('');
|
2018-05-22 23:07:34 +00:00
|
|
|
|
}
|
|
|
|
|
if(typeof title != 'undefined' && title.length > 0) {
|
|
|
|
|
pageTitle += title;
|
2018-05-23 23:42:20 +00:00
|
|
|
|
$('#currenttrack').text(title);
|
|
|
|
|
} else {
|
|
|
|
|
$('#currenttrack').text('');
|
2018-05-22 23:07:34 +00:00
|
|
|
|
}
|
|
|
|
|
document.title = pageTitle;
|
|
|
|
|
showNotification(title,textNotification,htmlNotification,'success');
|
2014-01-17 17:34:22 +00:00
|
|
|
|
}
|
2015-09-13 08:38:18 +00:00
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
|
2015-09-13 08:38:18 +00:00
|
|
|
|
$(document).keydown(function(e){
|
|
|
|
|
if (e.target.tagName == 'INPUT') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (e.which) {
|
|
|
|
|
case 37: //left
|
|
|
|
|
socket.send('MPD_API_SET_PREV');
|
|
|
|
|
break;
|
|
|
|
|
case 39: //right
|
|
|
|
|
socket.send('MPD_API_SET_NEXT');
|
|
|
|
|
break;
|
|
|
|
|
case 32: //space
|
|
|
|
|
clickPlay();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
2015-09-02 17:38:42 +00:00
|
|
|
|
|
2016-06-08 21:20:27 +00:00
|
|
|
|
function add_filter () {
|
|
|
|
|
for (i = 65; i <= 90; i++) {
|
|
|
|
|
var c = String.fromCharCode(i);
|
2018-05-29 20:12:11 +00:00
|
|
|
|
$('#browseFilesystemGotoLetters').append('<a class="btn btn-secondary" onclick="gotoLetter(\'' + c + '\');" href="#/browse/filesystem/' + pagination + '/' + browsepath + '">' + c + '</a>');
|
2016-06-08 21:20:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-21 23:36:05 +00:00
|
|
|
|
|
|
|
|
|
function chVolume (increment) {
|
|
|
|
|
var aktValue=volumeBar.slider('getValue');
|
|
|
|
|
var newValue=aktValue+increment;
|
|
|
|
|
if (newValue<0) { newValue=0; }
|
|
|
|
|
else if (newValue > 100) { newValue=100; }
|
|
|
|
|
volumeBar.slider('setValue',newValue);
|
|
|
|
|
socket.send("MPD_API_SET_VOLUME,"+newValue);
|
2018-05-27 21:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function beautifyDuration(x) {
|
|
|
|
|
var days = Math.floor(x / 86400);
|
|
|
|
|
var hours = Math.floor(x / 3600) - days * 24;
|
|
|
|
|
var minutes = Math.floor(x / 60) - hours * 60 - days * 1440;
|
|
|
|
|
var seconds = x - days * 86400 - hours * 3600 - minutes * 60;
|
|
|
|
|
|
|
|
|
|
return (days > 0 ? days + '\u2009d ' : '') +
|
|
|
|
|
(hours > 0 ? hours + '\u2009h ' + (minutes < 10 ? '0' : '') : '') +
|
|
|
|
|
minutes + '\u2009m ' + (seconds < 10 ? '0' : '') + seconds + '\u2009s';
|
2018-05-21 23:36:05 +00:00
|
|
|
|
}
|