///////////////////////////////////////////////////////////////////////
//Update Song History
function updateHistory(url) {
$(".history ul li", thisObj).remove();
if(settings.version == 1){
//Do nothing
}
else if(settings.version == 2){
$(".row-serv", thisObj).remove();
$.ajax ({
dataType: 'jsonp',
url: url,
success:
function(data) {
data.length = 6;
for (var i = 1; i < data.length; i++) {
var rowNum = i;
var listVal = rowNum;
var songtitle = data[i].title;
var songtitleSplit = songtitle.split('-');
var artist = songtitleSplit[0];
var title = songtitleSplit[1];
$(".history-serv", thisObj).append(
"
" + title + "
"+ artist + "
"+ listVal + "
"
);
getImageList(artist, title, rowNum);
}
}
})
}
}
//Get image list for song history
function getImageList(artist, title, i) {
artist = formatArtist(artist);
title = formatTitle(title);
artist = encodeURI(artist);
title = encodeURI(title);
var url = "https://itunes.apple.com/search?term==" + artist + "-" + title + "&media=music&limit=1";
$.ajax ({
dataType: 'jsonp',
url: url,
success:
function(data) {
if (data.results.length == 1){
cover = data.results[0].artworkUrl100;
cover = cover.replace('100x100', '400x400');
}
else {
var cover = settings.logo;
}
$('#row'+ i , thisObj).css({"background-image": "url(" + cover + ")", "background-size": "100% 100%"});
},
error:
function() { console.log("#getImageList(), Error in loading history image list for " + decodeURI(artist)) }
})
}
//Icecast
function getIC(url) {
if(settings.version == "icecast") {
function foo() {
$.ajax ({
dataType: 'json',
url: url,
success:
function(data) {
var result = findMPData(data);
if (result.title != getTag()) {
updateTag(result.title);
var songtitle = result.title;
var songtitleSplit = songtitle.split('-');
var artist = songtitleSplit[0];
var title = songtitleSplit[1];
updateArtist(artist);
updateTitle(title);
getCover(artist, title);
updateServerInfoIC(result);
updateHistoryIC(artist, title);
FBShare(result);
TWShare3(result);
}
}
})
}
foo();
setInterval(foo, 12000);
}
}
var icHis = new Array();
function findMPData(data) {
if (data.icestats.source.length === undefined){
return data.icestats.source;
}
else{
for (var i = 0; i < data.icestats.source.length; i++) {
var str = data.icestats.source[i].listenurl;
if (str.indexOf(settings.mount_point) >= 0) {
return data.icestats.source[i];
}
}
}
}
function updateServerInfoIC(data) {
$(".servertitle", thisObj).text(data.server_name);
$(".listeners", thisObj).text(data.listeners);
}
function updateHistoryIC(artist, title) {
addToArray(artist, title);
createHisList();
}
function addToArray(artist, title) {
icHis.unshift({ar: artist, tt: title});
icHis.length = icHis.length < 6 ? icHis.length : 6;
}
function createHisList(){
$(".row-serv", thisObj).remove();
for(var i = 1; i < icHis.length; i++){
var rowNum = i;
var listVal = rowNum;
var artist = icHis[i].ar;
var title = icHis[i].tt;
$(".history-serv", thisObj).append(
"
" + title + "
"+ artist + "
"+ listVal + "
"
);
getImageList(artist, title, rowNum);
}
}
//Song history panel handling
$(".icons-history", thisObj).on("click tap", function () {
$(".icons-history", thisObj).toggleClass("icons-close");
if (!$(".player-ctr", thisObj).hasClass("open")) {
$(".player-ctr", thisObj).fadeOut(400);
$(".history-serv", thisObj).delay(600).fadeIn(400);
$(".player-ctr", thisObj).addClass("open");
}
else if($(".player-ctr", thisObj).hasClass("open")) {
$(".player-ctr", thisObj).removeClass("open");
$(".history-serv", thisObj).fadeOut(400);
$(".player-ctr", thisObj).delay(600).fadeIn(400);
}
});
// Share
$(".album-cover-serv", thisObj).hover(function () {
$(".social-share-serv", thisObj).toggleClass("display");
$(".social-link-twitter", thisObj).toggleClass("bounceIn");
$(".social-link-facebook", thisObj).toggleClass("bounceIn");
$(".listener", thisObj).toggleClass("bounceIn");
})
function FBShare(result) {
var siteURL = window.location.href;
var url = "https://www.facebook.com/sharer/sharer.php?u=" + encodeURIComponent(siteURL);
$("#aface", thisObj).attr("href", url);
}
function TWShare(result) {
var siteURL = window.location.href;
var url = "https://twitter.com/home?status=I'm listening to " + result.songtitle + " @ " + siteURL;
$("#atwitter", thisObj).attr("href", url);
}
function TWShare2(result) {
var siteURL = window.location.href;
var url = "https://twitter.com/home?status=I'm listening to " + result.split(",")[6] + " @ " + siteURL;
$("#atwitter", thisObj).attr("href", url);
}
function TWShare3(result) {
var siteURL = window.location.href;
var url = "https://twitter.com/home?status=I'm listening to " + result.title + " @ " + siteURL;
$("#atwitter", thisObj).attr("href", url);
}
//Mobile Volume Classes
if( /Android|webOS|iPhone|iPad|iPod|Opera Mini/i.test(navigator.userAgent) ) {
$(cVolumeIcon).addClass("nodisplay");
$(cVolumeIconM).addClass("display");
}
};
})(jQuery)