last used radio stations are saved now
This commit is contained in:
parent
006396cc2a
commit
11be63c110
@ -237,9 +237,10 @@
|
||||
<h4>Radio</h4>
|
||||
<div class="">
|
||||
<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();" >
|
||||
Play
|
||||
Play / Save
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
@ -271,7 +272,7 @@
|
||||
<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/jquery.mobile.iscrollview-closure-min.js"></script> -->
|
||||
|
||||
<script src="js/jquery.cookie.js"></script>
|
||||
<script src="js/jquery.truncate.min.js"></script>
|
||||
<!-- <script type="text/javascript" src="js/add2home.js" charset="utf-8"></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;
|
||||
}
|
||||
|
||||
function addRadioUri(value) {
|
||||
var value = value || $('#radioinput').val();
|
||||
if (validUrl(value)) {
|
||||
function addRadioUri(name, uri) {
|
||||
//value of name is based on the passing of an uri as a parameter or not
|
||||
var name = '';
|
||||
if (!uri) {
|
||||
name = $('#radionameinput').val();
|
||||
} else {
|
||||
$('#radionameinput').val('');
|
||||
}
|
||||
uri = uri || $('#radiouriinput').val();
|
||||
// console.log( name , uri);
|
||||
if (validUri(uri)) {
|
||||
showLoading(true);
|
||||
//stop directly, for user feedback
|
||||
mopidy.playback.stop(true);
|
||||
@ -307,15 +315,26 @@ function addRadioUri(value) {
|
||||
document.activeElement.blur();
|
||||
$("input").blur();
|
||||
clearQueue();
|
||||
mopidy.tracklist.add(null,null, value );
|
||||
//add station to list and check for doubles
|
||||
mopidy.tracklist.add(null,null, uri );
|
||||
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) {
|
||||
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];
|
||||
}
|
||||
};
|
||||
radioStations.unshift(['', value]);
|
||||
$('#radionameinput').val(tmpname);
|
||||
$('#radiouriinput').val(uri);
|
||||
radioStations.unshift([tmpname, uri]);
|
||||
saveRadioStations();
|
||||
mopidy.playback.play();
|
||||
updateRadioStations();
|
||||
showLoading(false);
|
||||
@ -333,7 +352,7 @@ function updateRadioStations() {
|
||||
var rs = radioStations[key];
|
||||
if(rs) {
|
||||
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>';
|
||||
tmp += child;
|
||||
}
|
||||
@ -342,9 +361,14 @@ function updateRadioStations() {
|
||||
}
|
||||
|
||||
function initRadio() {
|
||||
radioStations.push(['3FM', 'http://icecast.omroep.nl/3fm-bb-mp3']);
|
||||
radioStations.push(['', 'http://icecast-bnr.cdp.triple-it.nl/bnr_mp3_128_03']);
|
||||
radioStations.push(['Arrow', 'http://81.173.3.132:8082']);
|
||||
radioStations.push(['', 'http://icecast.omroep.nl/radio1-bb-mp3']);
|
||||
$.cookie.json = true;
|
||||
tmpRS = $.cookie('radioStations');
|
||||
radioStations = tmpRS || radioStations;
|
||||
updateRadioStations();
|
||||
}
|
||||
}
|
||||
|
||||
function saveRadioStations() {
|
||||
$.cookie.json = true;
|
||||
$.cookie('radioStations', radioStations);
|
||||
}
|
||||
|
||||
|
||||
@ -73,6 +73,12 @@ TRACK_TIMER = 1000;
|
||||
STATUS_TIMER = 10000;
|
||||
|
||||
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 */
|
||||
function validUrl(str) {
|
||||
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
|
||||
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
|
||||
'((\\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) );
|
||||
// from http://dzone.com/snippets/validate-url-regexp
|
||||
function validUri(str) {
|
||||
var regexp = /(mms|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
|
||||
return regexp.test(str);
|
||||
}
|
||||
@ -126,11 +126,22 @@ function setSongInfo(data) {
|
||||
artistshtml = '';
|
||||
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) {
|
||||
$("#modalalbum").html('Album: <a href="#" onclick="return showAlbum(\'' + data.album.uri + '\');">' + data.album.name + '</a>');
|
||||
getCover(artiststext, data.album.name, '#infocover, #controlspopupimage', 'extralarge');
|
||||
} else {
|
||||
$("#modalalbum").html('');
|
||||
}
|
||||
|
||||
$("#modalname").html(data.name);
|
||||
|
||||
if (!data.length || data.length == 0) {
|
||||
@ -144,6 +155,8 @@ function setSongInfo(data) {
|
||||
$('#trackslider').slider('enable');
|
||||
}
|
||||
|
||||
var arttmp = '';
|
||||
|
||||
if(data.artists) {
|
||||
for (var j = 0; j < data.artists.length; j++) {
|
||||
artistshtml += '<a href="#" onclick="return showArtist(\'' + data.artists[j].uri + '\');">' + data.artists[j].name + '</a>';
|
||||
@ -153,14 +166,14 @@ function setSongInfo(data) {
|
||||
artiststext += ', ';
|
||||
}
|
||||
}
|
||||
var arttmp = 'Artist';
|
||||
|
||||
arttmp = 'Artist';
|
||||
if (data.artists.length > 1) {
|
||||
arttmp += 's';
|
||||
arttmp += 's';
|
||||
}
|
||||
arttmp += ': ' + artistshtml;
|
||||
}
|
||||
|
||||
$("#modalartist").html(arttmp + ': ' + artistshtml);
|
||||
$("#modalartist").html(arttmp);
|
||||
|
||||
$("#trackslider").attr("min", 0);
|
||||
$("#trackslider").attr("max", data.length);
|
||||
@ -448,6 +461,9 @@ function locationHashChanged() {
|
||||
initSearch($('#searchinput').val());
|
||||
}
|
||||
break;
|
||||
case 'radio':
|
||||
$('#navradio a').addClass('ui-state-active ui-state-persist ui-btn-active');
|
||||
break;
|
||||
case 'artists':
|
||||
if (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