mirror of
				https://github.com/KevinMidboe/zoff.git
				synced 2025-10-29 18:00:23 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			228 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			228 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
var List = {
 | 
						|
 | 
						|
    channel_listener: function()
 | 
						|
    {
 | 
						|
    	socket.on("channel", function(msg){
 | 
						|
    		List.channel_function(msg);
 | 
						|
    	});
 | 
						|
    },
 | 
						|
 | 
						|
    channel_function: function(msg)
 | 
						|
    {
 | 
						|
        switch(msg[0])
 | 
						|
        {
 | 
						|
            case "list":
 | 
						|
                List.populate_list(msg[1]);
 | 
						|
                break;
 | 
						|
            case "added":
 | 
						|
                List.added_song(msg[1]);
 | 
						|
                break;
 | 
						|
            case "deleted":
 | 
						|
                List.deleted_song(msg[1]);
 | 
						|
                break;
 | 
						|
            case "vote":
 | 
						|
                List.voted_song(msg[1], msg[2]);
 | 
						|
                break;
 | 
						|
            case "song_change":
 | 
						|
                List.song_change(msg[1]);
 | 
						|
                break;
 | 
						|
        }
 | 
						|
    },
 | 
						|
 | 
						|
    skipping_listener: function(){
 | 
						|
    	socket.on("skipping", function(obj)
 | 
						|
    	{
 | 
						|
    		document.getElementById("pBar").innerHTML = "Vote registrated! "+obj[0]+" of "+obj[1]+" has skipped. "+(Math.ceil(obj[1]/2))+" or more is needed!";
 | 
						|
    		$("#pBar").addClass("opacityFull");
 | 
						|
    		setTimeout(function(){
 | 
						|
    			$("#pBar").removeClass("opacityFull");
 | 
						|
    		},1500);
 | 
						|
    	});
 | 
						|
    },
 | 
						|
 | 
						|
    populate_list: function(msg)
 | 
						|
    {
 | 
						|
        full_playlist = msg;
 | 
						|
        
 | 
						|
        List.sortList();
 | 
						|
		$("#wrapper").empty();
 | 
						|
 | 
						|
		$.each(full_playlist, function(j, current_song){
 | 
						|
			if(!current_song.now_playing){ //check that the song isnt playing
 | 
						|
                $("#wrapper").append(List.generateSong(current_song, false));
 | 
						|
			}
 | 
						|
		});
 | 
						|
 | 
						|
        if(window.mobilecheck()) $(".list-image").lazyload({});
 | 
						|
        else $(".list-image").lazyload({container: $("#wrapper")}).removeClass("lazy");
 | 
						|
		$("#settings").css("visibility", "visible");
 | 
						|
		$("#settings").css("opacity", "1");
 | 
						|
		$("#wrapper").css("opacity", "1");
 | 
						|
 | 
						|
    },
 | 
						|
 | 
						|
    added_song: function(added){
 | 
						|
        full_playlist.push(added);
 | 
						|
        List.sortList();
 | 
						|
        List.insertAtIndex(added, true);
 | 
						|
    },
 | 
						|
 | 
						|
    deleted_song: function(deleted){
 | 
						|
        var index              = List.getIndexOfSong(deleted);
 | 
						|
        var to_delete          = $("#wrapper").children()[index];
 | 
						|
        to_delete.style.height = 0;
 | 
						|
 | 
						|
        setTimeout(function()
 | 
						|
        {
 | 
						|
            $("#"+deleted).remove();
 | 
						|
            full_playlist.splice(List.getIndexOfSong(deleted), 1);
 | 
						|
        }, 305);
 | 
						|
 | 
						|
        document.getElementById('wrapper').scrollTop += 1;
 | 
						|
        document.getElementById('wrapper').scrollTop += -1;
 | 
						|
    },
 | 
						|
 | 
						|
    voted_song: function(voted, time){
 | 
						|
        var index_of_song = List.getIndexOfSong(voted);
 | 
						|
        var song_voted_on = full_playlist[index_of_song];
 | 
						|
 | 
						|
        full_playlist[index_of_song].votes += 1;
 | 
						|
        full_playlist[index_of_song].added = time;
 | 
						|
 | 
						|
        List.sortList();
 | 
						|
        $("#"+voted).remove();
 | 
						|
        List.insertAtIndex(song_voted_on, false);
 | 
						|
    },
 | 
						|
 | 
						|
    song_change: function(time){
 | 
						|
        var length = full_playlist.length-1;
 | 
						|
 | 
						|
        full_playlist[0].now_playing        = true;
 | 
						|
        full_playlist[0].votes              = 0;
 | 
						|
        full_playlist[0].guids              = [];
 | 
						|
        full_playlist[0].added              = time;
 | 
						|
        full_playlist[length].now_playing   = false;
 | 
						|
 | 
						|
        full_playlist.push(full_playlist.shift());
 | 
						|
        $("#wrapper").children()[0].remove();
 | 
						|
 | 
						|
        List.insertAtIndex(full_playlist[length-1], false);
 | 
						|
        document.getElementById('wrapper').scrollTop += 1;
 | 
						|
        document.getElementById('wrapper').scrollTop += -1;
 | 
						|
    },
 | 
						|
 | 
						|
    vote: function(id, vote){
 | 
						|
    	socket.emit('vote', [chan, id, vote, adminpass]);
 | 
						|
    	return true;
 | 
						|
    },
 | 
						|
 | 
						|
    skip: function(){
 | 
						|
    	socket.emit('skip', [chan, localStorage[chan.toLowerCase()]]);
 | 
						|
    	return true;
 | 
						|
    },
 | 
						|
 | 
						|
    importOldList: function(chan){
 | 
						|
        var ids="";
 | 
						|
        var num=0;
 | 
						|
 | 
						|
    	playlist_url = "lists/"+chan+".json";
 | 
						|
 | 
						|
    	list = $.parseJSON($.ajax({
 | 
						|
    		      type: "GET",
 | 
						|
    		      url: playlist_url,
 | 
						|
    		      async: false
 | 
						|
    	       }).responseText);
 | 
						|
 | 
						|
    	$.each(list.songs, function(i,data)
 | 
						|
    	{
 | 
						|
    		ids+=data.id+",";
 | 
						|
 | 
						|
    		if(num>45){
 | 
						|
    			Search.addVideos(ids);
 | 
						|
 | 
						|
    			ids = "";
 | 
						|
    			num = 0;
 | 
						|
    		}
 | 
						|
    		num++;
 | 
						|
    	});
 | 
						|
 | 
						|
    	Search.addVideos(ids);
 | 
						|
    	document.getElementById("search").value = "";
 | 
						|
    },
 | 
						|
 | 
						|
    sortList: function()
 | 
						|
    {
 | 
						|
        full_playlist.sort(Helper.predicate({
 | 
						|
           name: 'votes',
 | 
						|
           reverse: true
 | 
						|
        }, 'added'));
 | 
						|
    },
 | 
						|
 | 
						|
    show: function(){
 | 
						|
    	if(!window.mobilecheck())
 | 
						|
    	{
 | 
						|
    		if(showToggle){
 | 
						|
    	    	showToggle=false;
 | 
						|
    	    	$("#toptitle").empty();
 | 
						|
    	        $("#chan").addClass("bigChan");
 | 
						|
    	        //$("#chan").html("zoff.no/"+encodeURI(chan));
 | 
						|
    	        $("#chan").html("zoff.no/"+chan.toLowerCase());
 | 
						|
    	    }else{
 | 
						|
    	    	showToggle=true;
 | 
						|
    	    	$("#toptitle").html("Zöff");
 | 
						|
    	    	$("#chan").removeClass("bigChan");
 | 
						|
    	    	$("#chan").html(chan);
 | 
						|
    	   }
 | 
						|
    	}
 | 
						|
    },
 | 
						|
 | 
						|
    insertAtIndex: function(song_info, transition) {
 | 
						|
        i = List.getIndexOfSong(song_info.id);
 | 
						|
 | 
						|
        if(i === 0) 
 | 
						|
         	$("#wrapper").prepend(List.generateSong(song_info, transition));
 | 
						|
        else
 | 
						|
            $("#wrapper > div:nth-child(" + (i) + ")").after(List.generateSong(song_info, transition));
 | 
						|
        
 | 
						|
        if(transition)
 | 
						|
        {
 | 
						|
            setTimeout(function(){
 | 
						|
                var added = $("#wrapper").children()[i];
 | 
						|
                $(added).css("height", 66);
 | 
						|
            },5);
 | 
						|
        }
 | 
						|
    },
 | 
						|
 | 
						|
    generateSong: function(song_info, transition)
 | 
						|
    {
 | 
						|
    	var video_id    = song_info.id;
 | 
						|
    	var video_title = song_info.title;
 | 
						|
    	var video_votes = song_info.votes;
 | 
						|
    	var video_thumb = "background-image:url('//img.youtube.com/vi/"+video_id+"/mqdefault.jpg');";
 | 
						|
        var song        = $("<div>"+list_html+"</div>");
 | 
						|
 | 
						|
        if(transition) song.find("#list-song").css("height", 0);
 | 
						|
        if(!w_p) song.find(".card-action").removeClass("hide");
 | 
						|
        if(video_votes == 1)song.find(".vote-text").text("vote");
 | 
						|
 | 
						|
    	song.find(".list-title").text(video_title);
 | 
						|
    	song.find(".list-title").attr("title", video_title);
 | 
						|
    	song.find(".list-votes").text(video_votes);
 | 
						|
    	song.find(".vote-container").attr("onclick", "vote('"+video_id+"','pos')");
 | 
						|
    	song.find(".list-image").attr("style",video_thumb);
 | 
						|
    	song.find("#list-song").attr("id", video_id);
 | 
						|
    	song.find("#del").attr("onclick", "vote('"+video_id+"', 'del')");
 | 
						|
 | 
						|
    	return song.html();
 | 
						|
    },
 | 
						|
 | 
						|
    getIndexOfSong: function(id)
 | 
						|
    {
 | 
						|
    	indexes = $.map(full_playlist, function(obj, index) {
 | 
						|
    	    if(obj.id == id) {
 | 
						|
    	        return index;
 | 
						|
    	    }
 | 
						|
    	});
 | 
						|
    	return indexes[0];
 | 
						|
    }
 | 
						|
} |