Moved js files

This commit is contained in:
OptimusCrime
2014-10-16 18:45:46 +02:00
parent e73c5c011a
commit a9ebbeef32
6 changed files with 0 additions and 0 deletions

35
static/js/admin.js Executable file
View File

@@ -0,0 +1,35 @@
var adminTogg;
function admin()
{
adminTogg = !adminTogg;
if(adminTogg){
$.ajax({
url:"../static/panel.html",
context: document.body,
success: function(response){
//$(response).hide().appendTo("#adminPanel").fadeIn(1000);
$("#adminPanel").append(response).hide().fadeIn(300);
}
});
}else
{
setTimeout(function(){document.getElementById("adminPanel").innerHTML = "";}, 300);
$("#adminPanel").fadeOut(300);
}
$("#playlist").toggleClass("lowOpacity");
}
function submitAdmin(form)
{
vote = form.vote.checked,
addSongs = form.addSongs.checked,
longSongs = form.longSongs.checked,
onlyMusic = form.onlyMusic.checked;
console.log("Vote: "+vote);
console.log("Add Songs: "+addSongs);
console.log("Long Songs: "+longSongs);
console.log("Only music: "+onlyMusic);
}

2006
static/js/iscroll.js Executable file

File diff suppressed because it is too large Load Diff

114
static/js/list.js Executable file
View File

@@ -0,0 +1,114 @@
var list;
var toSend = "";
var sendURL;
var myScroll;
var scroller = false;
var showToggle =true;
var chan = $("#chan").html();
function updateList()
{
console.log("updating list");
list = $.ajax({ type: "GET",
url: "php/change.php",
async: false
}).responseText;
list = $.parseJSON(list);
/*list[0].shift();
list[3].shift();
list[2].shift();*/
setTimeout(function()
{
$("#wrapper").empty();
$.each(list["songs"], function(j, listeID){
var video_title=listeID["title"].replace(/\\\'/g, "'").replace(/\\\"/g,"'");;
var video_id = listeID["id"];
var video_thumb = "http://i.ytimg.com/vi/"+video_id+"/default.jpg";
var odd = ""; if(j%2==0)odd=" oddlist";
var finalhtml="<div id='result' class='result lresult"+odd+"'>"+
"<img src='"+video_thumb+"' class='thumb lthumb'>"+
"<div class='ltitle'>"+video_title+"</div>"+
"<div class='votes'>"+listeID["votes"]+"<a onclick=\"vote('"+video_id+"','pos');\" id='plus'>+</a><a onclick=\"vote('"+video_id+"','neg');\" id='minus'>-</a></div>"+
"</div>";
$("#wrapper").append(finalhtml);
});
if($("#playlist").height() > $("#player").height())
{
if(!window.mobilecheck())
{
$("#playlist").css({height: $("#player").height() - $("#buttons").height()-4});
$("#playlist").css({overflow: "hidden"});
if(scroller == false)
{
myScroll = new IScroll('#playlist', {
mouseWheel: true,
scrollbars: false,
scrollY: true,
interactiveScrollbars: false
});
scroller = true;
}else
{
myScroll.refresh();
}
}
}
if(window.mobilecheck())
{
document.getElementById("player").style.display="none";
ytplayer.pauseVideo();
}
}, 2500);
}
function vote(id, vote){
console.log($.ajax({
type: "GET",
url: "php/change.php",
async: false,
data: "vote="+vote+"&id="+id,
success: function() {
console.log("voted "+vote+" on "+id);
if(vote=="pos"){ $("#playlist").addClass("success");}
else{ $("#playlist").addClass("error");}
},
}).responseText);
setTimeout(function(){
$("#playlist").removeClass("success");
$("#playlist").removeClass("error");
},1500);
}
function skip(){
console.log($.ajax({
type: "GET",
url: "php/change.php",
async: false,
data: "skip",
success: function() {
console.log("voted to skip song");
$("#buttons").addClass("success");
},
}).responseText);
setTimeout(function(){
$("#playlist").removeClass("success");
},1500);
}
function show(){
if(showToggle){
showToggle=false;
$("#toptitle").empty();
$("#chan").addClass("bigChan");
$("#chan").html("zoff.no/"+chan);
}else{
showToggle=true;
$("#toptitle").html("Zöff");
$("#chan").removeClass("bigChan");
$("#chan").html(chan);
}
}

100
static/js/search.js Executable file
View File

@@ -0,0 +1,100 @@
$(document).ready(function()
{
$("#search").focus();
$('#base').bind("keyup keypress", function(e) {
var code = e.keyCode || e.which;
if (code == 13) {
e.preventDefault();
return false;
}
});
var old_input="";
$(".search_input").focus();
setTimeout(function(){
$(".search_input").keyup(function()
{
var search_input = $(this).val();
if(search_input.length < 3){
$("#results").html("");
}
if(search_input != old_input){
old_input=search_input;
$("#results").html('');
if(search_input != ""){
var keyword= encodeURIComponent(search_input);
var yt_url='http://gdata.youtube.com/feeds/api/videos?q='+keyword+'&format=5&max-results=25&v=2&alt=jsonc';
$.ajax({
type: "GET",
url: yt_url,
dataType:"jsonp",
success: function(response)
{
if(response.data.items)
{
$.each(response.data.items, function(i,data)
{
if(data.duration > 720){return;}
if(data["category"] == "Music"){
var video_title=encodeURIComponent(data.title).replace(/'/g, "\\\'");
var views=data.viewCount;
var video_thumb = "http://i.ytimg.com/vi/"+data.id+"/default.jpg";
var length = Math.floor(data.duration/60)+":"+(data.duration-Math.floor(data.duration / 60)*60);
var finalhtml="<div id='result' class='result' onclick=\"submit('"+data.id+"','"+video_title+"');\">"+
"<img src='"+video_thumb+"' class='thumb'>"+
"<div id='title'>"+data.title+""+
"<span class='result_info'>"+data.uploader+" • "+views+" views • "+length+"</span></div></div>";
$("#results").append(finalhtml);
}
});
}
else
{
$("#video").html("<div id='no'>No Video</div>");
}
}
});
}
}
});
}, 300);
});
function submit(id,title){
console.log($.ajax({
type: "GET",
url: "php/change.php",
async: false,
data: "v="+id+"&n="+title,
success: function() {
console.log("added "+id);
document.getElementById("search").value = "";
$("#search").addClass("success");
$("#results").html('');
},
error: function(){
console.log("error in adding");
document.getElementById("search").value = "";
$("#search").addClass("error");
$("#results").html('');
}
}).responseText);
$("#search").focus();
setTimeout(function(){
$("#search").removeClass("success");
$("#search").removeClass("error");
},1500);
}
// if(reply=="added"){$("#search").removeClass('success'); $("#search").addClass('success');}

5
static/js/visualize.js Executable file
View File

@@ -0,0 +1,5 @@
/*$(document).ready(function()
{
context = new AudioContext();
src = context.createMediaElementSource($('#player video'));
}*/

301
static/js/youtube.js Executable file
View File

@@ -0,0 +1,301 @@
/*
This is the youtube player sync and control file.
Fetcher sangen som spilles fra JSON filen
*/
var timeDifference;
var wasPaused;
var beginning;
var diffVideo;
var serverTime;
var url;
var response;
var url
var tag
var firstScriptTag;
var ytplayer;
var syncInterval;
var title;
var interval;
var viewers;
var changed = false;
$(document).ready(function()
{
window.mobilecheck = function() {
var check = false;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))check = true})(navigator.userAgent||navigator.vendor||window.opera);
return check; }
updateList();
timeDifference;
wasPaused = false;
beginning = true;
diffVideo = false;
interval = false;
response = $.ajax({ type: "GET",
url: "php/change.php",
async: false
}).responseText;
//console.log(response);
response = $.parseJSON(response);
console.log(response["nowPlaying"].length);
try{
for(first in response["nowPlaying"]) break;
console.log(first);
response = first;
}catch(err){
response = "1";
}
$.ajax({
type: 'get',
url: 'php/timedifference.php',
data: "abcde",
async: false,
success: function(data) {
timeDifference = $.parseJSON(data);
}
});
console.log("timediff:"+timeDifference[0]);
tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
if(window.mobilecheck()){
syncInterval = setInterval(getTime, 50000);
listInterval = setInterval(updateList, 50000);
document.getElementById("search").blur();
}else{
syncInterval = setInterval(getTime, 5000);
listInterval = setInterval(updateList, 10000);
}
});
function onYouTubeIframeAPIReady() {
ytplayer = new YT.Player('player', {
height: window.height*0.75,
width: window.width*0.6,
videoId: response,
playerVars: { controls: "1" , iv_load_policy: "3", theme:"light", rel:"0", color:"white" },
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange,
'onError': errorHandler
}
});
}
/**
Legger sangen inn i <div>en, via swfobject
var params = { allowScriptAccess: "always"};
var atts = { id: "myytplayer" };
swfobject.embedSWF("http://www.youtube.com/v/"+response+"?enablejsapi=1&playerapiid=ytplayer&version=3&controls=1&iv_load_policy=3",
"ytapiplayer", "825", "462", "8", null, null, params, atts);
eventlistener for når playeren endres
*/
function onPlayerStateChange(newState) {
console.log("new state: "+newState.data);
console.log("beginning: "+beginning);
//ytplayer.seekTo(15);
if((newState.data == 0 && checkEnd()) || (newState.data == 1 && checkEnd()))
{
console.log("nummer 1");
startNextSong();
ytplayer.pauseVideo();
wasPaused = false;
}else if(newState.data == 1 && (wasPaused && !beginning))
{
console.log("unpaused");
beginning = false;
wasPaused = false;
syncInterval = setInterval(getTime, 5000);
getTime();
}else if(newState.data == 2)
{
clearInterval(syncInterval);
interval = true;
wasPaused = true;
beginning = false;
}
}
function checkEnd()
{
console.log("sjekker om brukeren spolte");
$.ajax({
type: 'get',
url: 'php/timedifference.php',
data: "abcde",
async: false,
success: function(data) {
timeDifference = $.parseJSON(data);
}
});
if(parseInt(timeDifference[0]) > ytplayer.getDuration())
{
return true;
}
return false;
}
function startNextSong()
{
//console.log(getTime());
if(checkEnd() && !changed)
{
setTimeout(function(){
response = $.ajax({
type: "POST",
url: "php/change.php",
async: false,
data: "thisUrl="+response+"&act=save",
success: function() {
console.log("saved song-switch - "+response);
}
}).responseText;
console.log("next video: "+response);
getTitle(response);
ytplayer.loadVideoById(response);
beginning = true;
},2500);
updateList();
changed = true
setTimeout(function() {
changed = false;
syncInterval = setInterval(getTime, 5000);
interval = true;
console.log("starter intervallen. Interval: " + interval);
}, 2500);
}
}
function getTime()
{
console.log("utenfor if test" + wasPaused);
if(!wasPaused)
{
console.log("sjekker om brukeren spolte");
$.ajax({
type: 'get',
url: 'php/timedifference.php',
data: "abcde",
async: false,
success: function(data) {
timeDifference = $.parseJSON(data);
}
});
console.log("current song: "+response);
console.log("song in database: "+timeDifference[1]);
if(parseInt(timeDifference[2]) + 1> ytplayer.getCurrentTime() + parseInt(timeDifference[3]) && ytplayer.getPlayerState() == 0)
{
return true;
}else if(ytplayer.getCurrentTime() + parseInt(timeDifference[3]) > parseInt(timeDifference[2]) + 5 || (ytplayer.getCurrentTime() + parseInt(timeDifference[3]) < parseInt(timeDifference[2]) - 5 && ytplayer.getPlayerState() != 0 && ytplayer.getPlayerState() != 3))
{
if(parseInt(timeDifference[0]) > ytplayer.getDuration())
{
console.log("burde ikke søke, men hoppe til neste sang");
}
ytplayer.seekTo(timeDifference[0]);
ytplayer.pauseVideo();
ytplayer.playVideo();
getTitle();
return false;
}
//if(interval){syncInterval = setInterval(getTime, 5000);interval = false;}
if(response != timeDifference[1])
{
clearInterval(syncInterval);
console.log("forskjellige videoer!!");
ytplayer.pauseVideo();
ytplayer.loadVideoById(timeDifference[1]);
setTimeout(function(){
//console.log(response);
diffVideo = true;
beginning = true;
$.ajax({
type: "POST",
url: "php/change.php",
async: false,
data: "thisUrl=123abcprompeprompe&act=save",
success: function(data)
{
response = timeDifference[1];
getTitle();
}
});
syncInterval = setInterval(getTime, 5000);
},2500);
}
}
}
function getTitle()
{
$.ajax({ type: "GET",
url: "php/timedifference.php",
async: false,
success: function(data) {
viewers = $.parseJSON(data);
var outPutWord = viewers[5] > 1 ? "viewers" : "viewer";
var title= viewers[4].replace(/\\\'/g, "'").replace(/\\\&quot;/g,"'");
document.title = title + " • Zöff";
document.getElementsByName('v')[0].placeholder = title + " • " + viewers[5] + " " + outPutWord;
}
});
}
function errorHandler(newState)
{
setTimeout(function(){
response = $.ajax({
type: "POST",
url: "php/change.php",
async: false,
data: "thisUrl="+response+"&act=empty",
success: function() {
console.log("error! deleted video");
}
}).responseText;
ytplayer.loadVideoById(response);
},2500);
/*
setTimeout(function(){
response = $.ajax({ type: "GET",
url: "change.php",
async: false
}).responseText;
var url = $.parseJSON(response);
response = url[0][0];
ytplayer.loadVideoById(response);
},2500);*/
}
function onPlayerReady(event) {
//ytplayer = document.getElementById("myytplayer");
// ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
//ytplayer.addEventListener("onError", "errorHandler");
getTime();
ytplayer.playVideo();
getTitle();
}