last used radio stations are saved now
This commit is contained in:
parent
006396cc2a
commit
11be63c110
@ -237,9 +237,10 @@
|
|||||||
<h4>Radio</h4>
|
<h4>Radio</h4>
|
||||||
<div class="">
|
<div class="">
|
||||||
<form>
|
<form>
|
||||||
<input id="radioinput" placeholder="Playlist URI" class="span2" data-clear-btn="true" onkeypress="return radioPressed(event.keyCode);" id="appendedInputButton" type="text" />
|
<input id="radionameinput" placeholder="Name" class="span2" data-clear-btn="true" onkeypress="return radioPressed(event.keyCode);" id="appendedInputButton" type="text" />
|
||||||
|
<input id="radiouriinput" placeholder="Playlist URI" class="span2" data-clear-btn="true" onkeypress="return radioPressed(event.keyCode);" id="appendedInputButton" type="text" />
|
||||||
<button class="btn" type="button" onclick="return addRadioUri();" >
|
<button class="btn" type="button" onclick="return addRadioUri();" >
|
||||||
Play
|
Play / Save
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@ -271,7 +272,7 @@
|
|||||||
<script type="text/javascript" src="/mopidy/mopidy.js"></script>
|
<script type="text/javascript" src="/mopidy/mopidy.js"></script>
|
||||||
<script type="text/javascript" src="js/iscroll-lite.js"></script>
|
<script type="text/javascript" src="js/iscroll-lite.js"></script>
|
||||||
<!-- <script type="text/javascript" src="js/jquery.mobile.iscrollview-closure-min.js"></script> -->
|
<!-- <script type="text/javascript" src="js/jquery.mobile.iscrollview-closure-min.js"></script> -->
|
||||||
|
<script src="js/jquery.cookie.js"></script>
|
||||||
<script src="js/jquery.truncate.min.js"></script>
|
<script src="js/jquery.truncate.min.js"></script>
|
||||||
<!-- <script type="text/javascript" src="js/add2home.js" charset="utf-8"></script> -->
|
<!-- <script type="text/javascript" src="js/add2home.js" charset="utf-8"></script> -->
|
||||||
<script src="js/controls.js"></script>
|
<script src="js/controls.js"></script>
|
||||||
|
|||||||
50
webclient/js/controls.js
vendored
50
webclient/js/controls.js
vendored
@ -297,9 +297,17 @@ function radioPressed(key) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addRadioUri(value) {
|
function addRadioUri(name, uri) {
|
||||||
var value = value || $('#radioinput').val();
|
//value of name is based on the passing of an uri as a parameter or not
|
||||||
if (validUrl(value)) {
|
var name = '';
|
||||||
|
if (!uri) {
|
||||||
|
name = $('#radionameinput').val();
|
||||||
|
} else {
|
||||||
|
$('#radionameinput').val('');
|
||||||
|
}
|
||||||
|
uri = uri || $('#radiouriinput').val();
|
||||||
|
// console.log( name , uri);
|
||||||
|
if (validUri(uri)) {
|
||||||
showLoading(true);
|
showLoading(true);
|
||||||
//stop directly, for user feedback
|
//stop directly, for user feedback
|
||||||
mopidy.playback.stop(true);
|
mopidy.playback.stop(true);
|
||||||
@ -307,15 +315,26 @@ function addRadioUri(value) {
|
|||||||
document.activeElement.blur();
|
document.activeElement.blur();
|
||||||
$("input").blur();
|
$("input").blur();
|
||||||
clearQueue();
|
clearQueue();
|
||||||
mopidy.tracklist.add(null,null, value );
|
mopidy.tracklist.add(null,null, uri );
|
||||||
//add station to list and check for doubles
|
var tmpname = name || '';
|
||||||
|
var i = 0;
|
||||||
|
//add station to list and check for doubles and add no more than 25
|
||||||
for (var key in radioStations) {
|
for (var key in radioStations) {
|
||||||
rs = radioStations[key];
|
rs = radioStations[key];
|
||||||
if (rs[1] == value) {
|
if (i > 25) {
|
||||||
|
delete radioStations[key];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
if (rs && rs[1] == uri) {
|
||||||
|
tmpname = name || radioStations[key][0];
|
||||||
delete radioStations[key];
|
delete radioStations[key];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
radioStations.unshift(['', value]);
|
$('#radionameinput').val(tmpname);
|
||||||
|
$('#radiouriinput').val(uri);
|
||||||
|
radioStations.unshift([tmpname, uri]);
|
||||||
|
saveRadioStations();
|
||||||
mopidy.playback.play();
|
mopidy.playback.play();
|
||||||
updateRadioStations();
|
updateRadioStations();
|
||||||
showLoading(false);
|
showLoading(false);
|
||||||
@ -333,7 +352,7 @@ function updateRadioStations() {
|
|||||||
var rs = radioStations[key];
|
var rs = radioStations[key];
|
||||||
if(rs) {
|
if(rs) {
|
||||||
name = rs[0] || rs[1];
|
name = rs[0] || rs[1];
|
||||||
child = '<li><a href="#" onclick="return addRadioUri(\'' + rs[1] + '\');">';
|
child = '<li><a href="#" onclick="return addRadioUri(\'' + rs[0] + '\', \'' + rs[1] + '\');">';
|
||||||
child += '<h1>' + name + '</h1></a></li>';
|
child += '<h1>' + name + '</h1></a></li>';
|
||||||
tmp += child;
|
tmp += child;
|
||||||
}
|
}
|
||||||
@ -342,9 +361,14 @@ function updateRadioStations() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initRadio() {
|
function initRadio() {
|
||||||
radioStations.push(['3FM', 'http://icecast.omroep.nl/3fm-bb-mp3']);
|
$.cookie.json = true;
|
||||||
radioStations.push(['', 'http://icecast-bnr.cdp.triple-it.nl/bnr_mp3_128_03']);
|
tmpRS = $.cookie('radioStations');
|
||||||
radioStations.push(['Arrow', 'http://81.173.3.132:8082']);
|
radioStations = tmpRS || radioStations;
|
||||||
radioStations.push(['', 'http://icecast.omroep.nl/radio1-bb-mp3']);
|
|
||||||
updateRadioStations();
|
updateRadioStations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function saveRadioStations() {
|
||||||
|
$.cookie.json = true;
|
||||||
|
$.cookie('radioStations', radioStations);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -73,6 +73,12 @@ TRACK_TIMER = 1000;
|
|||||||
STATUS_TIMER = 10000;
|
STATUS_TIMER = 10000;
|
||||||
|
|
||||||
var radioStations = [];
|
var radioStations = [];
|
||||||
|
//fill with defaults
|
||||||
|
radioStations.push(['NPR 24', 'http://nprdmp.ic.llnwd.net/stream/nprdmp_live01_mp3']);
|
||||||
|
radioStations.push(['3FM Dutch', 'http://icecast.omroep.nl/3fm-bb-mp3']);
|
||||||
|
radioStations.push(['BBC WorldService', 'http://vprbbc.streamguys.net:8000/vprbbc24.mp3']);
|
||||||
|
radioStations.push(['Arrow Jazz', 'http://81.173.3.132:8082']);
|
||||||
|
radioStations.push(['PBS Australia', 'http://eno.emit.com:8000/pbsfm_live_64.mp3']);
|
||||||
|
|
||||||
/*******
|
/*******
|
||||||
*
|
*
|
||||||
@ -309,13 +315,8 @@ function toast (message, delay) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* from stackoverflow */
|
// from http://dzone.com/snippets/validate-url-regexp
|
||||||
function validUrl(str) {
|
function validUri(str) {
|
||||||
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
|
var regexp = /(mms|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
|
||||||
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
|
return regexp.test(str);
|
||||||
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
|
|
||||||
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
|
|
||||||
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
|
|
||||||
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
|
|
||||||
return ( pattern.test(str) );
|
|
||||||
}
|
}
|
||||||
@ -126,11 +126,22 @@ function setSongInfo(data) {
|
|||||||
artistshtml = '';
|
artistshtml = '';
|
||||||
artiststext = '';
|
artiststext = '';
|
||||||
|
|
||||||
|
if (validUri(data.name)) {
|
||||||
|
for (var key in radioStations) {
|
||||||
|
rs = radioStations[key];
|
||||||
|
if (rs && rs[1] == data.name) {
|
||||||
|
data.name = (rs[0] || rs[1]) + ' [Stream]';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (data.album) {
|
if (data.album) {
|
||||||
$("#modalalbum").html('Album: <a href="#" onclick="return showAlbum(\'' + data.album.uri + '\');">' + data.album.name + '</a>');
|
$("#modalalbum").html('Album: <a href="#" onclick="return showAlbum(\'' + data.album.uri + '\');">' + data.album.name + '</a>');
|
||||||
getCover(artiststext, data.album.name, '#infocover, #controlspopupimage', 'extralarge');
|
getCover(artiststext, data.album.name, '#infocover, #controlspopupimage', 'extralarge');
|
||||||
|
} else {
|
||||||
|
$("#modalalbum").html('');
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#modalname").html(data.name);
|
$("#modalname").html(data.name);
|
||||||
|
|
||||||
if (!data.length || data.length == 0) {
|
if (!data.length || data.length == 0) {
|
||||||
@ -144,6 +155,8 @@ function setSongInfo(data) {
|
|||||||
$('#trackslider').slider('enable');
|
$('#trackslider').slider('enable');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var arttmp = '';
|
||||||
|
|
||||||
if(data.artists) {
|
if(data.artists) {
|
||||||
for (var j = 0; j < data.artists.length; j++) {
|
for (var j = 0; j < data.artists.length; j++) {
|
||||||
artistshtml += '<a href="#" onclick="return showArtist(\'' + data.artists[j].uri + '\');">' + data.artists[j].name + '</a>';
|
artistshtml += '<a href="#" onclick="return showArtist(\'' + data.artists[j].uri + '\');">' + data.artists[j].name + '</a>';
|
||||||
@ -153,14 +166,14 @@ function setSongInfo(data) {
|
|||||||
artiststext += ', ';
|
artiststext += ', ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var arttmp = 'Artist';
|
arttmp = 'Artist';
|
||||||
|
|
||||||
if (data.artists.length > 1) {
|
if (data.artists.length > 1) {
|
||||||
arttmp += 's';
|
arttmp += 's';
|
||||||
}
|
}
|
||||||
|
arttmp += ': ' + artistshtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#modalartist").html(arttmp + ': ' + artistshtml);
|
$("#modalartist").html(arttmp);
|
||||||
|
|
||||||
$("#trackslider").attr("min", 0);
|
$("#trackslider").attr("min", 0);
|
||||||
$("#trackslider").attr("max", data.length);
|
$("#trackslider").attr("max", data.length);
|
||||||
@ -448,6 +461,9 @@ function locationHashChanged() {
|
|||||||
initSearch($('#searchinput').val());
|
initSearch($('#searchinput').val());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'radio':
|
||||||
|
$('#navradio a').addClass('ui-state-active ui-state-persist ui-btn-active');
|
||||||
|
break;
|
||||||
case 'artists':
|
case 'artists':
|
||||||
if (uri != '') {
|
if (uri != '') {
|
||||||
showArtist(uri);
|
showArtist(uri);
|
||||||
|
|||||||
96
webclient/js/jquery.cookie.js
Normal file
96
webclient/js/jquery.cookie.js
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
/*!
|
||||||
|
* jQuery Cookie Plugin v1.3.1
|
||||||
|
* https://github.com/carhartl/jquery-cookie
|
||||||
|
*
|
||||||
|
* Copyright 2013 Klaus Hartl
|
||||||
|
* Released under the MIT license
|
||||||
|
*/
|
||||||
|
(function (factory) {
|
||||||
|
if (typeof define === 'function' && define.amd) {
|
||||||
|
// AMD. Register as anonymous module.
|
||||||
|
define(['jquery'], factory);
|
||||||
|
} else {
|
||||||
|
// Browser globals.
|
||||||
|
factory(jQuery);
|
||||||
|
}
|
||||||
|
}(function ($) {
|
||||||
|
|
||||||
|
var pluses = /\+/g;
|
||||||
|
|
||||||
|
function decode(s) {
|
||||||
|
if (config.raw) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
return decodeURIComponent(s.replace(pluses, ' '));
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodeAndParse(s) {
|
||||||
|
if (s.indexOf('"') === 0) {
|
||||||
|
// This is a quoted cookie as according to RFC2068, unescape...
|
||||||
|
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
|
||||||
|
}
|
||||||
|
|
||||||
|
s = decode(s);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return config.json ? JSON.parse(s) : s;
|
||||||
|
} catch(e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
var config = $.cookie = function (key, value, options) {
|
||||||
|
|
||||||
|
// Write
|
||||||
|
if (value !== undefined) {
|
||||||
|
options = $.extend({}, config.defaults, options);
|
||||||
|
|
||||||
|
if (typeof options.expires === 'number') {
|
||||||
|
var days = options.expires, t = options.expires = new Date();
|
||||||
|
t.setDate(t.getDate() + days);
|
||||||
|
}
|
||||||
|
|
||||||
|
value = config.json ? JSON.stringify(value) : String(value);
|
||||||
|
|
||||||
|
return (document.cookie = [
|
||||||
|
config.raw ? key : encodeURIComponent(key),
|
||||||
|
'=',
|
||||||
|
config.raw ? value : encodeURIComponent(value),
|
||||||
|
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
|
||||||
|
options.path ? '; path=' + options.path : '',
|
||||||
|
options.domain ? '; domain=' + options.domain : '',
|
||||||
|
options.secure ? '; secure' : ''
|
||||||
|
].join(''));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read
|
||||||
|
var cookies = document.cookie.split('; ');
|
||||||
|
var result = key ? undefined : {};
|
||||||
|
for (var i = 0, l = cookies.length; i < l; i++) {
|
||||||
|
var parts = cookies[i].split('=');
|
||||||
|
var name = decode(parts.shift());
|
||||||
|
var cookie = parts.join('=');
|
||||||
|
|
||||||
|
if (key && key === name) {
|
||||||
|
result = decodeAndParse(cookie);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!key) {
|
||||||
|
result[name] = decodeAndParse(cookie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
config.defaults = {};
|
||||||
|
|
||||||
|
$.removeCookie = function (key, options) {
|
||||||
|
if ($.cookie(key) !== undefined) {
|
||||||
|
// Must not alter options, thus extending a fresh object...
|
||||||
|
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
}));
|
||||||
Loading…
Reference in New Issue
Block a user