<commit_before>var screen = $(window).width();
var inviteList = $('#invite-list button');
var saveButton = $('#save');

if (screen > 420) {
	$('.blackout').css('display', 'block');
	$('.text-left .padding-box').css('display', 'none');
}

saveButton.click(function () {
    $('.confirm').css('display', 'none');
    $('.question').text('¿Querés saber quienes vienen?');
    inviteList.css('display', 'block');
})

// LISTA DE CONFIRMADOS!
var invitedPep = {
	"invitados": [
		{ "name":"Mike", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Mariana", "subsecretary":"SECPECG", "direction":"-"  },
		{ "name":"Alejo", "subsecretary":"DE", "direction":"Inversiones"  },
		{ "name":"Manu", "subsecretary":"SSCI", "direction":"DGCYT"  },
		{ "name":"Tomas", "subsecretary":"DE", "direction":"Inversiones"  },
		{ "name":"Guido S.", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Francisco", "subsecretary":"DE", "direction":"Inversiones"  },
		{ "name":"Julieta", "subsecretary":"Comunicacion", "direction":"Comunicacion"  },
		{ "name":"Dolores", "subsecretary":"SSCI", "direction":"SSICI"  },
		{ "name":"Romina", "subsecretary":"SSCI", "direction":"SSICI"  },
		{ "name":"Lucrecia", "subsecretary":"SSCI", "direction":"SSICI"  },
		{ "name":"Mili Tachella", "subsecretary":"SSCI", "direction":"Comunicación"  },
		{ "name":"Guillermina", "subsecretary":"SSCI", "direction":"Comunicación"  },
		{ "name":"Clara", "subsecretary":"SSCI", "direction":"DGCyT"  },
		{ "name":"Angie Giavarini", "subsecretary":"DE", "direction":"Inversiones"  },
		{ "name":"Juan Puig", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Nico", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Ifi", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Guido", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Melina", "subsecretary":"SSCI", "direction":"Comunicacion"  },
		{ "name":"Diego Guillen", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Nacho Pueta", "subsecretary":"SSCI", "direction":"DGCyT"  },
		{ "name":"Lore", "subsecretary":"SSCI", "direction":"DGCyT"  },
		{ "name":"Pablo Icardi", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Tomi Casagrande", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Pitu", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Yorland", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Sol", "subsecretary":"Economica", "direction":"PAPP"  },
		{ "name":"Puchu", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Florchi", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Ernesto", "subsecretary":"Ciudad Inteligente", "direction":"GEDI"  },
		{ "name":"Ponja", "subsecretary":"Ciudad Inteligente", "direction":"GEDI"  }
	]
}

var listInvited = ( function () {

	var name;
	var subse;
	var direction;
	var listElement = $('.invited-list');

	for (var i = 0; i < invitedPep.invitados.length; i++) {
		name = invitedPep.invitados[i].name;
		subse = invitedPep.invitados[i].subsecretary;
		direction = invitedPep.invitados[i].direction;

		listElement.append('
 ' + name + ' ' + '' + subse + ', ' + direction + '
');
	}
})()

<commit_msg>Update script.js<commit_after>var screen = $(window).width();
var inviteList = $('#invite-list button');
var saveButton = $('#save');

if (screen > 420) {
	$('.blackout').css('display', 'block');
	$('.text-left .padding-box').css('display', 'none');
}

saveButton.click(function () {
    $('.confirm').css('display', 'none');
    $('.question').text('¿Querés saber quienes vienen?');
    inviteList.css('display', 'block');
})

// LISTA DE CONFIRMADOS!
var invitedPep = {
	"invitados": [
		{ "name":"Mariana", "subsecretary":"-", "direction":"-"  },
		{ "name":"Mike", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Mariana", "subsecretary":"SECPECG", "direction":"-"  },
		{ "name":"Alejo", "subsecretary":"DE", "direction":"Inversiones"  },
		{ "name":"Manu", "subsecretary":"SSCI", "direction":"DGCYT"  },
		{ "name":"Tomas", "subsecretary":"DE", "direction":"Inversiones"  },
		{ "name":"Guido S.", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Francisco", "subsecretary":"DE", "direction":"Inversiones"  },
		{ "name":"Julieta", "subsecretary":"Comunicacion", "direction":"Comunicacion"  },
		{ "name":"Dolores", "subsecretary":"SSCI", "direction":"SSICI"  },
		{ "name":"Romina", "subsecretary":"SSCI", "direction":"SSICI"  },
		{ "name":"Lucrecia", "subsecretary":"SSCI", "direction":"SSICI"  },
		{ "name":"Mili Tachella", "subsecretary":"SSCI", "direction":"Comunicación"  },
		{ "name":"Guillermina", "subsecretary":"SSCI", "direction":"Comunicación"  },
		{ "name":"Clara", "subsecretary":"SSCI", "direction":"DGCyT"  },
		{ "name":"Angie Giavarini", "subsecretary":"DE", "direction":"Inversiones"  },
		{ "name":"Juan Puig", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Nico", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Ifi", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Guido", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Melina", "subsecretary":"SSCI", "direction":"Comunicacion"  },
		{ "name":"Diego Guillen", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Nacho Pueta", "subsecretary":"SSCI", "direction":"DGCyT"  },
		{ "name":"Lore", "subsecretary":"SSCI", "direction":"DGCyT"  },
		{ "name":"Pablo Icardi", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Tomi Casagrande", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Pitu", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Yorland", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Sol", "subsecretary":"Economica", "direction":"PAPP"  },
		{ "name":"Puchu", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Florchi", "subsecretary":"SSCI", "direction":"GEDI"  },
		{ "name":"Ernesto", "subsecretary":"Ciudad Inteligente", "direction":"GEDI"  },
		{ "name":"Ponja", "subsecretary":"Ciudad Inteligente", "direction":"GEDI"  }
	]
}

var listInvited = ( function () {

	var name;
	var subse;
	var direction;
	var listElement = $('.invited-list');

	for (var i = 0; i < invitedPep.invitados.length; i++) {
		name = invitedPep.invitados[i].name;
		subse = invitedPep.invitados[i].subsecretary;
		direction = invitedPep.invitados[i].direction;

		listElement.append('
 ' + name + ' ' + '' + subse + ', ' + direction + '
');
	}
})()

<|endoftext|>


<commit_before>/* ----------------------------------------------------------------------------
                GitHup Ctrl
---------------------------------------------------------------------------- */

//Initialisation
var app = angular.module("AdobeOpenSource", ["ngResource"])

//Get Adobe Github repos
app.factory("GitAdobe", function($resource) {
    return $resource("https://api.github.com/users/adobe/:type?sort=updated", {type: "@type"})
});

//Get Adobe Github repos
app.factory("GitRepo", function($resource) {
    return $resource("https://api.github.com/repos/adobe/:repo/:info", {owner: "@owner", languages: "@languages"})
});

//TODO : Manage offline project list when errors

this.ProjectCtrl = function($scope, GitAdobe, GitRepo) {
    //Init display range
    $scope.projFirst = 0;
    $scope.projLast = 10;

    //Get all projects
    $scope.projects = GitAdobe.query({ type: "repos" }, function() {
        $($scope.projects).each(function(i) {
            var actProj = $scope.projects[i];
            $scope.projects.languages = {
                $scope.projects.language: 0
            };

            var request = $.ajax({
                url: "https://api.github.com/repos/adobe/"+this.name+"/languages"
            });

            request.done( function( repLang ) {
                $scope.$apply( function () {
                    var tempProj =
                    $scope.projects.languages = repLang;
                    console.info( $scope.projects.languages );
                });
            });

            //If it fails, we use the main language only
            request.fail( function ( jqXHR, textStatus ) {
                $scope.$apply( function () {
                    $scope.projects.languages = $scope.projects.language;
                });
                console.log("Language query failed for "+actProj.name+", error: "+textStatus, jqXHR);
            });
        });
    });
};

/* ----------------------------------------------------------------------------
                Parrallax Scrolling
---------------------------------------------------------------------------- */

var scrollTop, topLogo_footer, topLogo_org, topLogo_header;
$(function(){
    $(document).foundation();

    $(window).scroll(function () {
        scrollTop = $(window).scrollTop();

        //Logo animation
        var baseH = 100;
        var adobeLogoLimit = $(".header").height() - 150;
        if ( scrollTop > adobeLogoLimit ) {
            if ( (scrollTop - adobeLogoLimit) <= 50 ) {
                newHeight = baseH - (scrollTop - adobeLogoLimit)
                $(".wrapLogoTop").css({height: newHeight });
            } else {
                $(".wrapLogoTop").css({height: baseH-50 });
            };
        }
        else if (scrollTop < adobeLogoLimit) {
            $(".wrapLogoTop").css({height: baseH });
        }

        //First parallax: header
        if (scrollTop < ($(".header").height() + 20) ) {
            topLogo_header = ( $(window).scrollTop()/3 ) - 70;
            $("#logo1").css({ top: topLogo_header });
            $("#text-header").css({ top: - scrollTop });
        }

        //2nd parrallax: organisations
        topLogo_org = ( ( $(window).scrollTop() - $("#header_org").position().top + 350 ) / 2 ) - 10 ;
        if ( topLogo_org > 90 )
            topLogo_org = 90;
        $("#logo2").css({ top: topLogo_org });

        //3rd parrallax: footer
        topLogo_footer = ( scrollTop + $(window).height() - $("#footer").position().top - $("#footer").height()*2 ) - 65;
        $("#logo3").css({ bottom: topLogo_footer });
    });
});

$(document).foundation();<commit_msg>ERROR: Last commit with false name, correction: Auto pull all languages<commit_after>/* ----------------------------------------------------------------------------
                GitHup Ctrl
---------------------------------------------------------------------------- */

//Initialisation
var app = angular.module("AdobeOpenSource", ["ngResource"])

//Get Adobe Github repos
app.factory("GitAdobe", function($resource) {
    return $resource("https://api.github.com/users/adobe/:type?sort=updated", {type: "@type"})
});

//Get Adobe Github repos
app.factory("GitRepo", function($resource) {
    return $resource("https://api.github.com/repos/adobe/:repo/:info", {owner: "@owner", languages: "@languages"})
});

//TODO : Manage offline project list when errors

this.ProjectCtrl = function($scope, GitAdobe, GitRepo) {
    //Init display range
    $scope.projFirst = 0;
    $scope.projLast = 10;

    //Get all projects
    $scope.projects = GitAdobe.query({ type: "repos" }, function() {
        $($scope.projects).each(function(i) {
            var actProj = $scope.projects[i];
            $scope.projects.languages = {
                $scope.projects.language: 0
            };

            var request = $.ajax({
                url: "https://api.github.com/repos/adobe/"+this.name+"/languages"
            });

            request.done( function( repLang ) {
                $scope.$apply( function () {
                    var tempProj =
                    $scope.projects.languages = repLang;
                    console.info( $scope.projects.languages );
                });
            });

            //If it fails, we use the main language only
            request.fail( function ( jqXHR, textStatus ) {
                $scope.$apply( function () {
                    $scope.projects.languages = $scope.projects.language;
                });
                console.log("Language query failed for "+actProj.name+", error: "+textStatus, jqXHR);
            });
        });
    });
};

/* ----------------------------------------------------------------------------
                Parrallax Scrolling
---------------------------------------------------------------------------- */

var scrollTop, topLogo_footer, topLogo_org, topLogo_header;
$(function(){
    $(document).foundation();

    $(window).scroll(function () {
        scrollTop = $(window).scrollTop();

        //Logo animation
        var baseH = 100;
        var adobeLogoLimit = $(".header").height() - 150;
        if ( scrollTop > adobeLogoLimit ) {
            if ( (scrollTop - adobeLogoLimit) <= 50 ) {
                newHeight = baseH - (scrollTop - adobeLogoLimit)
                $(".wrapLogoTop").css({height: newHeight });
            } else {
                $(".wrapLogoTop").css({height: baseH-50 });
            };
        }
        else if (scrollTop < adobeLogoLimit) {
            $(".wrapLogoTop").css({height: baseH });
        }

        //First parallax: header
        if (scrollTop < ($(".header").height() + 20) ) {
            topLogo_header = ( $(window).scrollTop()/3 ) - 70;
            $("#logo1").css({ top: topLogo_header });
            $("#text-header").css({ top: - scrollTop });
        }

        //2nd parrallax: organisations
        topLogo_org = ( ( $(window).scrollTop() - $("#header_org").position().top + 350 ) / 2 ) - 10 ;
        if ( topLogo_org > 90 )
            topLogo_org = 90;
        $("#logo2").css({ top: topLogo_org });

        //3rd parrallax: footer
        topLogo_footer = ( scrollTop + $(window).height() - $("#footer").position().top - $("#footer").height()*2 ) - 65;
        $("#logo3").css({ bottom: topLogo_footer });
    });
});

$(document).foundation();<|endoftext|>


<commit_before>//Global variables
var base = 'https://api.github.com/users/';
var rData = {},
	uData = {};
var langChart;

// Run on load
$(document).ready(function() {
	$('#username').focus();
	$('#data').hide();
	$('.spinner').hide();
});

//Detect 'Enter' key being pressed
$('#username').keyup(function (e) {
	if (e.keyCode === 13) {
		$('#content').empty();
		$('#orgz').empty();
		$('#top-bar').empty();
		$('#data').hide();
		$('#messages').empty();
        $('#repos').empty();
		$('#API').hide();
		var enteredText = $('#username').val();
		if (enteredText.length === 0) unrecognized(enteredText);
		else {
			if (enteredText == 'git help') showHelp();
			else if (enteredText == 'git info') showInfo();
			else if (enteredText == 'username') showOops();
			else {
				$('.spinner').show();
				getUser(enteredText);
			}
			$('#username').val('');
		}
	}
});

//Get user data using GitHub API
function getUser(userName) {
	$.get(base + userName, function (userData) {
		uData = userData;
		$('#search').fadeOut(750, function () {
			$('#data').fadeIn(500);
			$('#footer').fadeOut();
		});
		//Check that the user has a defined full name or use their username if they don't
		var uName = userName,
			uBlog = uData.blog, uCompany = uData.company, uLocation = uData.location;

		//Check for any required information that is null
		if (uData.name !== null && uData.name !== undefined && uData.name.length) {
            uName = uData.name;
        }

		if (uBlog === null || uBlog === undefined || !uBlog.length) {
			$('#home').hide();
		}

		if (uCompany === null || uCompany === undefined || !uCompany.length) {
			uCompany = 'a secret location';
		}

		if (uLocation === null || uLocation === undefined || !uLocation.length) {
			uLocation = 'a hidden safe house';
		}

		document.title = uName + '\'s résumés';

		$('#top-bar').append(''+uName+'');
		$('#top-bar').append(' has been committing since '+(uData.created_at).substring(0,10)+'');
		$("#home").wrap('');
		$("#code").wrap('');
		$('#content').append('Since then, they have amassed ');
		$('#content').append(''+uData.public_repos+' public repositories,');
		$('#content').append(''+uData.followers+' followers and');
		$('#content').append(''+uData.public_gists+' gists.
');
		$('#content').append(''+((uName).split(" "))[0]+' currently works at '+uCompany+'');
        $('#content').append(' and lives in '+uLocation+'.');

		//Get users' organization info
		var orgCount = 0;
		var oData = {};
		var orgs = [];
		$.get(base + userName+'/orgs', function (orgData) {
			oData = orgData;
			$.each(oData, function(i, orgInf) {
				orgCount++;
				orgs.push({info:orgInf});
			});
			if (orgCount === 0) {
				$('#orgz').hide();
			} else {
				$('#orgz').show();
				$('#orgz').append(''+((uName).split(" "))[0]+' is a member of '+orgs[0].info.login+' and ');
				if ((orgCount - 1) === 1) {
					$('#orgz').append(' '+orgs[1].info.login+'.');
				} else {
					$('#orgz').append(' '+(orgCount - 1)+' other organizations.');
				}
			}
		});
	});
	getRepos(userName);
}

//Get users' repo data using GitHub API
function getRepos(user) {
	var repos = [],
		uLang = [],
		langList = [], //To prevent duplicates
		page = 1,
		repoInf;

	var ctx = document.getElementById("lang-chart").getContext("2d");
	var data = [];
	langChart = new Chart(ctx).Doughnut(data, {animateScale: true,animationEasing : "easeOutExpo",segmentStrokeWidth : 2});

	while (page !== 3) {
		$.get(base+user+'/repos?&page='+page, function (repoData) {
			rData = repoData;
			alert(repoData.length);
			if (repoData.length === 0) {
				alert('here');
			}
			else {
				$.each(rData, function(i, repoInf) {
					repos.push({info:repoInf});
				});

				repos.sort(sortByStars);

				$('#repos').append('

Repo Name	Stars	Forks

'+repos[0].info.name+'	'+repos[0].info.stargazers_count+'	'+repos[0].info.forks_count+'

'+repos[1].info.name+'	'+repos[1].info.stargazers_count+'	'+repos[1].info.forks_count+'

'+repos[2].info.name+'	'+repos[2].info.stargazers_count+'	'+repos[2].info.forks_count+'

'+repos[3].info.name+'	'+repos[3].info.stargazers_count+'	'+repos[3].info.forks_count+'

'+repos[4].info.name+'	'+repos[4].info.stargazers_count+'	'+repos[4].info.forks_count+'

');

				for (var i = 0; i < repos.length; i++) {
					if (repos[i].info.language) {
						if (langList.indexOf(repos[i].info.language) === -1) {
							uLang.push({val:1, label:repos[i].info.language});
							langList[langList.length] = repos[i].info.language;
						} else {
							uLang[langList.indexOf(repos[i].info.language)].val++;
						}
					}
				}
				for (var i = 0; i < langList.length; i++) {
					langChart.addData({
						value: uLang[i].val,
						color: Please.make_color(),
						label: uLang[i].label
					});
				}
			}
		});
	page++;
	}
}

//Sort repos by stars
function sortByStars(a, b) {
		return b.info.stargazers_count - a.info.stargazers_count;
}

//Help message
function showHelp() {
	var help = 'Enter the username of the GitHub member you are looking for.';
	$('#messages').append('
'+help+'
');
	$('#messages').show();
	setTimeout(function() {
        $("#messages").fadeOut("slow", function() {
            $("#messages").hide();
        });
    }, 5000);
}

//Information about Committed
function showInfo() {
	var info = 'Committed is not affiliated with GitHub, it simply uses the GitHub API.
Committed was made with ♥ by Nischaal Cooray and is licensed under the MIT license.
Check out Committed on GitHub!
Committed is NOT optimized for mobile devices YET!'
	$('#messages').append('
'+info+'
');
	$('#messages').show();
	setTimeout(function() {
        $("#messages").fadeOut("slow", function() {
            $("#messages").hide();
        });
    }, 9000);
}

//Oops
function showOops() {
	var oops = 'Ah! Hello! I see that I didn\'t make myself understandable enough - sorry about that.
What I meant was to enter the username of the user that you are trying to find information about.
Now go get \'em!';
	$('#messages').append('
'+oops+'
');
	$('#messages').show();
	setTimeout(function() {
        $("#messages").fadeOut("slow", function() {
            $("#messages").hide();
        });
    }, 9000);
}
//Error message - not implemented fully yet
function unrecognized(text) {
	var error = '';
	if (text.length == 0) error = 'I ain\'t silly, I know you didn\'t type anything!
Try again!';
	else error = 'Ah shucks... I couldn\'t find that user... Would you give me another chance?';
	$('#messages').append('
'+error+'
');
	$('#messages').show();
	setTimeout(function() {
        $("#messages").fadeOut("slow", function() {
            $("#messages").hide();
        });
    }, 5000);
}

// Take user back to search screen
$( '#go-back' ).click(function() {
		$('#data').fadeOut(500, function () {
			$('#search').fadeIn(500);
			$('#API').fadeIn(500);
			$('.spinner').hide();
			$('#username').focus();
			langChart.destroy();
		});
	$('#home').show();
	document.title = 'Committed';
});
<commit_msg>I don't like rate limiting.<commit_after>//Global variables
var base = 'https://api.github.com/users/';
var rData = {},
	uData = {};
var langChart;

// Run on load
$(document).ready(function() {
	$('#username').focus();
	$('#data').hide();
	$('.spinner').hide();
});

//Detect 'Enter' key being pressed
$('#username').keyup(function (e) {
	if (e.keyCode === 13) {
		$('#content').empty();
		$('#orgz').empty();
		$('#top-bar').empty();
		$('#data').hide();
		$('#messages').empty();
        $('#repos').empty();
		$('#API').hide();
		var enteredText = $('#username').val();
		if (enteredText.length === 0) unrecognized(enteredText);
		else {
			if (enteredText == 'git help') showHelp();
			else if (enteredText == 'git info') showInfo();
			else if (enteredText == 'username') showOops();
			else {
				$('.spinner').show();
				getUser(enteredText);
			}
			$('#username').val('');
		}
	}
});

//Get user data using GitHub API
function getUser(userName) {
	$.get(base + userName, function (userData) {
		uData = userData;
		$('#search').fadeOut(750, function () {
			$('#data').fadeIn(500);
			$('#footer').fadeOut();
		});
		//Check that the user has a defined full name or use their username if they don't
		var uName = userName,
			uBlog = uData.blog, uCompany = uData.company, uLocation = uData.location;

		//Check for any required information that is null
		if (uData.name !== null && uData.name !== undefined && uData.name.length) {
            uName = uData.name;
        }

		if (uBlog === null || uBlog === undefined || !uBlog.length) {
			$('#home').hide();
		}

		if (uCompany === null || uCompany === undefined || !uCompany.length) {
			uCompany = 'a secret location';
		}

		if (uLocation === null || uLocation === undefined || !uLocation.length) {
			uLocation = 'a hidden safe house';
		}

		document.title = uName + '\'s résumés';

		$('#top-bar').append(''+uName+'');
		$('#top-bar').append(' has been committing since '+(uData.created_at).substring(0,10)+'');
		$("#home").wrap('');
		$("#code").wrap('');
		$('#content').append('Since then, they have amassed ');
		$('#content').append(''+uData.public_repos+' public repositories,');
		$('#content').append(''+uData.followers+' followers and');
		$('#content').append(''+uData.public_gists+' gists.
');
		$('#content').append(''+((uName).split(" "))[0]+' currently works at '+uCompany+'');
        $('#content').append(' and lives in '+uLocation+'.');

		//Get users' organization info
		var orgCount = 0;
		var oData = {};
		var orgs = [];
		$.get(base + userName+'/orgs', function (orgData) {
			oData = orgData;
			$.each(oData, function(i, orgInf) {
				orgCount++;
				orgs.push({info:orgInf});
			});
			if (orgCount === 0) {
				$('#orgz').hide();
			} else {
				$('#orgz').show();
				$('#orgz').append(''+((uName).split(" "))[0]+' is a member of '+orgs[0].info.login+' and ');
				if ((orgCount - 1) === 1) {
					$('#orgz').append(' '+orgs[1].info.login+'.');
				} else {
					$('#orgz').append(' '+(orgCount - 1)+' other organizations.');
				}
			}
		});
	});
	getRepos(userName);
}

//Get users' repo data using GitHub API
function getRepos(user) {
	var repos = [],
		uLang = [],
		langList = [], //To prevent duplicates
		page = 1,
		repoInf;

	var ctx = document.getElementById("lang-chart").getContext("2d");
	var data = [];
	langChart = new Chart(ctx).Doughnut(data, {animateScale: true,animationEasing : "easeOutExpo",segmentStrokeWidth : 2});

	while (page !== 3) {
		$.get(base+user+'/repos?&page='+page, function (repoData) {
			rData = repoData;
			alert(repoData.length);
			if (repoData.length === 0) {
				alert('here');
			}
			else {
				$.each(rData, function(i, repoInf) {
					repos.push({info:repoInf});
				});

				repos.sort(sortByStars);

				$('#repos').append('

Repo Name	Stars	Forks

'+repos[0].info.name+'	'+repos[0].info.stargazers_count+'	'+repos[0].info.forks_count+'

'+repos[1].info.name+'	'+repos[1].info.stargazers_count+'	'+repos[1].info.forks_count+'

'+repos[2].info.name+'	'+repos[2].info.stargazers_count+'	'+repos[2].info.forks_count+'

'+repos[3].info.name+'	'+repos[3].info.stargazers_count+'	'+repos[3].info.forks_count+'

'+repos[4].info.name+'	'+repos[4].info.stargazers_count+'	'+repos[4].info.forks_count+'

');

				for (var i = 0; i < repos.length; i++) {
					if (repos[i].info.language) {
						if (langList.indexOf(repos[i].info.language) === -1) {
							uLang.push({val:1, label:repos[i].info.language});
							langList[langList.length] = repos[i].info.language;
						} else {
							uLang[langList.indexOf(repos[i].info.language)].val++;
						}
					}
				}
				for (var i = 0; i < langList.length; i++) {
					langChart.addData({
						value: uLang[i].val,
						color: Please.make_color(),
						label: uLang[i].label
					});
				}
			}
		});
	page++;
	}
}

//Sort repos by stars
function sortByStars(a, b) {
		return b.info.stargazers_count - a.info.stargazers_count;
}

//Help message
function showHelp() {
	var help = 'Enter the username of the GitHub member you are looking for.';
	$('#messages').append('
'+help+'
');
	$('#messages').show();
	setTimeout(function() {
        $("#messages").fadeOut("slow", function() {
            $("#messages").hide();
        });
    }, 5000);
}

//Information about Committed
function showInfo() {
	var info = 'Committed is not affiliated with GitHub, it simply uses the GitHub API.
Committed was made with ♥ by Nischaal Cooray and is licensed under the MIT license.
Check out Committed on GitHub!
Committed is NOT optimized for mobile devices YET!'
	$('#messages').append('
'+info+'
');
	$('#messages').show();
	setTimeout(function() {
        $("#messages").fadeOut("slow", function() {
            $("#messages").hide();
        });
    }, 9000);
}

//Oops
function showOops() {
	var oops = 'Ah! Hello! I see that I didn\'t make myself understandable enough - sorry about that.
What I meant was to enter the username of the user that you are trying to find information about.
Now go get \'em!';
	$('#messages').append('
'+oops+'
');
	$('#messages').show();
	setTimeout(function() {
        $("#messages").fadeOut("slow", function() {
            $("#messages").hide();
        });
    }, 9000);
}
//Error message - not implemented fully yet
function unrecognized(text) {
	var error = '';
	if (text.length == 0) error = 'I ain\'t silly, I know you didn\'t type anything!
Try again!';
	else error = 'Ah shucks... I couldn\'t find that user... Would you give me another chance?';
	$('#messages').append('
'+error+'
');
	$('#messages').show();
	setTimeout(function() {
        $("#messages").fadeOut("slow", function() {
            $("#messages").hide();
        });
    }, 5000);
}

// Take user back to search screen
$( '#go-back' ).click(function() {
		$('#data').fadeOut(500, function () {
			$('#search').fadeIn(500);
			$('#API').fadeIn(500);
			$('.spinner').hide();
			$('#username').focus();
			langChart.destroy();
		});
	$('#home').show();
	document.title = 'Committed';
});
<|endoftext|>


<commit_before>/**
 * Author: Olaolu Olawuyi

 * Date Created: 20/08/2015

 * Last Modified: 01/07/2016

 * Twitter: @whizkydee, @webtwic

 * Github: https://github.com/webtwic/webtwic-site

*/

var Webtwic = Webtwic || {};

var browser_name = bowser.name.toLowerCase();

var test_canvas = document.createElement( 'canvas' );
var canvascheck = ( test_canvas.getContext ) ? true : false;

Webtwic = {
	// Basic Information about Webtwic
	name: 'Webtwic',
	description: 'A community focused on code tweaks, articles and tutorials for newbie and professional developers.',
	repo: 'https://github.com/webtwic/webtwic-site',
	author: 'Olaolu Olawuyi',
	version: '1.0.0',

	// Start main functions for the object

	// Function to add browser name and version to body class
	showBrowser: function( b ) {
		b = (typeof b == 'undefined') ? browser_name : b.toLowerCase();
		if ( ! ( bowser.webkit ) )
			$( 'body' ).addClass( b + ' ' + b + parseInt( bowser.version ) );
		else
			$( 'body' ).addClass( 'webkit' + ' ' + b + ' ' + b + parseInt( bowser.version ) );
	},

	// Function to set attributes and values to elements
	setAttr: function( elem, name, val ) {
		$( elem, this ).attr( name, val );
	},

	// Function to push down .site-content
	adjustSiteContent: function() {
		if ( $( 'body' ).hasClass( 'default-body' ) ) {
			$( '.top-stripe' ).addClass( 'adjustedMargin' );
			$( '#header .logo' ).addClass( 'adjustedTop' );
			$( '.main-menu' ).addClass( 'adjustedMargin' );
			$( '#header' ).addClass( 'adjustSiteContent' );
		} else if ( $( 'body' ).hasClass( 'secondary-body' ) ) {
			$( '.site-content' ).addClass( 'adjustSiteContent' );
			$( '.secondary-header' ).addClass( 'adjustedMargin' );
		}
	},

	// Function to push up .site-content to default state
	undoSiteAdjust: function() {
		if ( $( 'body' ).hasClass( 'default-body' ) ) {
			$( '.top-stripe' ).removeClass( 'adjustedMargin' );
			$( '#header .logo' ).removeClass( 'adjustedTop' );
			$( '.main-menu' ).removeClass( 'adjustedMargin' );
			$( '#header' ).removeClass( 'adjustSiteContent' );
		} else if ( $( 'body' ).hasClass( 'secondary-body' ) ) {
			$( '.secondary-header' ).removeClass( 'adjustedMargin' );
		}
	},

	// Function to show Notifications before header
	showNotif: function( text ) {
		text = ( typeof text == 'undefined' ) ? notif_text : text;
		Webtwic.adjustSiteContent();
		$( 'body' ).prepend(
			'
'+text+''+close_button+'
'
		);

		$( '.close-button' ).on( 'click', function( e ) {
			e.preventDefault();
			Webtwic.undoReset();
		});
	},

	// Function to hide Notifications
	hideNotif: function() {
		$( '#notifBanner' ).removeClass( 'notif_vis' );
	},

	resetSite: function() {
		Webtwic.showNotif();
		Webtwic.adjustSiteContent();
	},

	undoReset: function() {
		Webtwic.hideNotif();
		Webtwic.undoSiteAdjust();
	},
};

var WBT = Webtwic,
	 $$ = Webtwic,
	 close_button = '',
	 browser_link = ' ' + 'browser.' + ' ',
	 notif_text = 'Whoa. Your browser currently dosen\'t support some important features. Please try refreshing this page or get a better' +browser_link;

// Detect when the DOM is ready

jQuery( document ).ready( function() {
	// Test for HTML5 support
	if ( window.Modernizr )
		if ( !Modernizr.canvas )
			Webtwic.showNotif ( "Oops. Looks like your browser doesn't support HTML5. Please get a better" +browser_link+ "for an awesome experience." );
		 else /* do nothing */ ;
	 else
		if ( canvascheck === false )
			Webtwic.showNotif ( "Oops. Looks like your browser doesn't support HTML5. Please get a better" +browser_link+ "for an awesome experience." );
		 else /* do nothing */ ;

	// Define Variables
	var $scroll_top = $( 'a.scroll_top' ),
	is_toggle_active = $( '.hamburger' ).hasClass( 'is_active' ),
	height = 200;

	// Performance Fixes

	// Start browser detection
	switch ( browser_name ) {
	   case 'microsoft edge':
	      Webtwic.showBrowser( 'msedge' );
	      break;
		default:
			Webtwic.showBrowser();
	}

	/*
		TODO: Rebuild Performance fixes for attributes
		See history of Performance fixes.
		Also, check StackOverflow.
		See Issue #12
	*/

	var required_features = [
		Modernizr.flexbox,
		Modernizr.inlinesvg,
		Modernizr.svg,
		Modernizr.svgclippaths,
		Modernizr.fontface,
		Modernizr.boxshadow,
		Modernizr.borderradius,
		Modernizr.csstransforms
	];

	if ( window.Modernizr )
		if ( !( required_features ) )
			Webtwic.showNotif();
		else /* do nothing */ ;
	else /* do nothing */ ;

	// Start Main Page

	$( 'nav li ul.drop-nav' )
	.hide()
	.removeClass( 'dropNavFallback' );

	if ( $( window ).width() > 768 ) {
		$( 'nav li.dropdown' ).hover(function() {
			$( 'ul.drop-nav', this )
			.stop()
			.slideDown( 'fast' );
		}, function() {
			$( 'ul.drop-nav', this )
			.stop()
			.slideUp( 'fast' );
		});
	}

	$( '.active-item' ).append(
		'<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M 16.682,19.674c 0.010-0.012, 0.014-0.028, 0.024-0.040l 6.982-7.714c 0.39-0.434, 0.39-1.138,0-1.572 c-0.004-0.004-0.008-0.006-0.012-0.008C 23.496,10.13, 23.244,10, 22.964,10L 8.998,10 c-0.286,0-0.54,0.138-0.722,0.352L 8.272,10.348 c-0.39,0.434-0.39,1.138,0,1.572l 6.998,7.754C 15.66,20.108, 16.292,20.108, 16.682,19.674z"></path></svg>'
	);

	$( 'a.hamburger' ).on('click', function( e ) {
		$( this ).toggleClass( 'is_active' );

		e.preventDefault();
	});
	$( '.mobile-header .mobile-nav' ).hide();

	$( window ).on('scroll', function() {
		( $( this ).scrollTop() > height ) ? $scroll_top.addClass( 'topVisible' ): $scroll_top.removeClass( 'topVisible' );
	});

	// Styles for homepage article-social

	$( '.article .article-social a' ).hover(function() {
		$( 'span', this )
		.eq(1)
		.fadeIn(400);
	}, function() {
		$( 'span', this )
		.eq(1)
		.fadeOut(250);
	});

	// Functions for search-icon and ui-overlay-search

	$( '.header-follow-search .search-wrap' ).on( 'click', function() {
		openUiOverlay();
	});

	$( '.header-follow-search .close-icon' ).on( 'click', function( e ) {
		e.preventDefault();
		closeUiOverlay();
	});

	$( '.header-follow-search .close-icon' ).hover(
		function() {
			$( this ).addClass( 'spin' );
		}, function() {
			$( this ).removeClass( 'spin' );
	});

	function openUiOverlay() {
		$( '.ui-overlay-search' )
		.fadeIn(400)
		.addClass( 'is_open' );
	}

	function closeUiOverlay() {
		$( '.ui-overlay-search' )
		.fadeOut(400)
		.removeClass( 'is_open' );
	}

	$( '.ui-overlay-search .search-input input' ).on('focus', function() {
		$( '.search-input' ).attr( 'data-focused', 'true' );
		$( '.search-input input' ).addClass( '_is-focused' );
		$( '#__expand' ).addClass( 'visible' );
	});

	$( '.ui-overlay-search .search-input input' ).on('blur', function() {
		$( '.search-input' ).attr( 'data-focused', 'false' );
		$( '.search-input input' ).removeClass( '_is-focused' );
		$( '#__expand' ).removeClass( 'visible' );
	});

	$( '.post-meta .post-meta-inner .cta-btns a.is_inactive' ).on( 'click', function( e ) {
		e.preventDefault();
	});

	$( document ).on('keydown', function( e ) {
		if ( e.keyCode == 27 )
			closeUiOverlay();
		else /* do nothing */ ;
 	});

	$( '.mobile-nav' ).hide();

	// Functions for more-posts button click

	var loadMoreBtn = '.secondary-category-section .category-posts-column [data-clicked="false"]';

	function addLoader() {
		$( loadMoreBtn )
		.attr( 'data-clicked', 'true' )
		.append( '' );
	}

	$( loadMoreBtn ).on( 'click', function( e ) {
		$( this ).css({
			'background': '#50ABF1',
			'color': '#fff'
		});
		addLoader();
		e.preventDefault();
	});

	$scroll_top.on( 'click', function( e ) {
		$( 'body, html' ).animate({
			scrollTop: 0
		}, 1000);

		e.preventDefault();
	});

});
<commit_msg>Remove jQuery.fadeIn() from openUiOverlay()<commit_after>/**
 * Author: Olaolu Olawuyi

 * Date Created: 20/08/2015

 * Last Modified: 01/07/2016

 * Twitter: @whizkydee, @webtwic

 * Github: https://github.com/webtwic/webtwic-site

*/

var Webtwic = Webtwic || {};

var browser_name = bowser.name.toLowerCase();

var test_canvas = document.createElement( 'canvas' );
var canvascheck = ( test_canvas.getContext ) ? true : false;

Webtwic = {
	// Basic Information about Webtwic
	name: 'Webtwic',
	description: 'A community focused on code tweaks, articles and tutorials for newbie and professional developers.',
	repo: 'https://github.com/webtwic/webtwic-site',
	author: 'Olaolu Olawuyi',
	version: '1.0.0',

	// Start main functions for the object

	// Function to add browser name and version to body class
	showBrowser: function( b ) {
		b = (typeof b == 'undefined') ? browser_name : b.toLowerCase();
		if ( ! ( bowser.webkit ) )
			$( 'body' ).addClass( b + ' ' + b + parseInt( bowser.version ) );
		else
			$( 'body' ).addClass( 'webkit' + ' ' + b + ' ' + b + parseInt( bowser.version ) );
	},

	// Function to set attributes and values to elements
	setAttr: function( elem, name, val ) {
		$( elem, this ).attr( name, val );
	},

	// Function to push down .site-content
	adjustSiteContent: function() {
		if ( $( 'body' ).hasClass( 'default-body' ) ) {
			$( '.top-stripe' ).addClass( 'adjustedMargin' );
			$( '#header .logo' ).addClass( 'adjustedTop' );
			$( '.main-menu' ).addClass( 'adjustedMargin' );
			$( '#header' ).addClass( 'adjustSiteContent' );
		} else if ( $( 'body' ).hasClass( 'secondary-body' ) ) {
			$( '.site-content' ).addClass( 'adjustSiteContent' );
			$( '.secondary-header' ).addClass( 'adjustedMargin' );
		}
	},

	// Function to push up .site-content to default state
	undoSiteAdjust: function() {
		if ( $( 'body' ).hasClass( 'default-body' ) ) {
			$( '.top-stripe' ).removeClass( 'adjustedMargin' );
			$( '#header .logo' ).removeClass( 'adjustedTop' );
			$( '.main-menu' ).removeClass( 'adjustedMargin' );
			$( '#header' ).removeClass( 'adjustSiteContent' );
		} else if ( $( 'body' ).hasClass( 'secondary-body' ) ) {
			$( '.secondary-header' ).removeClass( 'adjustedMargin' );
		}
	},

	// Function to show Notifications before header
	showNotif: function( text ) {
		text = ( typeof text == 'undefined' ) ? notif_text : text;
		Webtwic.adjustSiteContent();
		$( 'body' ).prepend(
			'
'+text+''+close_button+'
'
		);

		$( '.close-button' ).on( 'click', function( e ) {
			e.preventDefault();
			Webtwic.undoReset();
		});
	},

	// Function to hide Notifications
	hideNotif: function() {
		$( '#notifBanner' ).removeClass( 'notif_vis' );
	},

	resetSite: function() {
		Webtwic.showNotif();
		Webtwic.adjustSiteContent();
	},

	undoReset: function() {
		Webtwic.hideNotif();
		Webtwic.undoSiteAdjust();
	},
};

var WBT = Webtwic,
	 $$ = Webtwic,
	 close_button = '',
	 browser_link = ' ' + 'browser.' + ' ',
	 notif_text = 'Whoa. Your browser currently dosen\'t support some important features. Please try refreshing this page or get a better' +browser_link;

// Detect when the DOM is ready

jQuery( document ).ready( function() {
	// Test for HTML5 support
	if ( window.Modernizr )
		if ( !Modernizr.canvas )
			Webtwic.showNotif ( "Oops. Looks like your browser doesn't support HTML5. Please get a better" +browser_link+ "for an awesome experience." );
		 else /* do nothing */ ;
	 else
		if ( canvascheck === false )
			Webtwic.showNotif ( "Oops. Looks like your browser doesn't support HTML5. Please get a better" +browser_link+ "for an awesome experience." );
		 else /* do nothing */ ;

	// Define Variables
	var $scroll_top = $( 'a.scroll_top' ),
	is_toggle_active = $( '.hamburger' ).hasClass( 'is_active' ),
	height = 200;

	// Performance Fixes

	// Start browser detection
	switch ( browser_name ) {
	   case 'microsoft edge':
	      Webtwic.showBrowser( 'msedge' );
	      break;
		default:
			Webtwic.showBrowser();
	}

	/*
		TODO: Rebuild Performance fixes for attributes
		See history of Performance fixes.
		Also, check StackOverflow.
		See Issue #12
	*/

	var required_features = [
		Modernizr.flexbox,
		Modernizr.inlinesvg,
		Modernizr.svg,
		Modernizr.svgclippaths,
		Modernizr.fontface,
		Modernizr.boxshadow,
		Modernizr.borderradius,
		Modernizr.csstransforms
	];

	if ( window.Modernizr )
		if ( !( required_features ) )
			Webtwic.showNotif();
		else /* do nothing */ ;
	else /* do nothing */ ;

	// Start Main Page

	$( 'nav li ul.drop-nav' )
	.hide()
	.removeClass( 'dropNavFallback' );

	if ( $( window ).width() > 768 ) {
		$( 'nav li.dropdown' ).hover(function() {
			$( 'ul.drop-nav', this )
			.stop()
			.slideDown( 'fast' );
		}, function() {
			$( 'ul.drop-nav', this )
			.stop()
			.slideUp( 'fast' );
		});
	}

	$( '.active-item' ).append(
		'<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M 16.682,19.674c 0.010-0.012, 0.014-0.028, 0.024-0.040l 6.982-7.714c 0.39-0.434, 0.39-1.138,0-1.572 c-0.004-0.004-0.008-0.006-0.012-0.008C 23.496,10.13, 23.244,10, 22.964,10L 8.998,10 c-0.286,0-0.54,0.138-0.722,0.352L 8.272,10.348 c-0.39,0.434-0.39,1.138,0,1.572l 6.998,7.754C 15.66,20.108, 16.292,20.108, 16.682,19.674z"></path></svg>'
	);

	$( 'a.hamburger' ).on('click', function( e ) {
		$( this ).toggleClass( 'is_active' );

		e.preventDefault();
	});
	$( '.mobile-header .mobile-nav' ).hide();

	$( window ).on('scroll', function() {
		( $( this ).scrollTop() > height ) ? $scroll_top.addClass( 'topVisible' ): $scroll_top.removeClass( 'topVisible' );
	});

	// Styles for homepage article-social

	$( '.article .article-social a' ).hover(function() {
		$( 'span', this )
		.eq(1)
		.fadeIn(400);
	}, function() {
		$( 'span', this )
		.eq(1)
		.fadeOut(250);
	});

	// Functions for search-icon and ui-overlay-search

	$( '.header-follow-search .search-wrap' ).on( 'click', function() {
		openUiOverlay();
	});

	$( '.header-follow-search .close-icon' ).on( 'click', function( e ) {
		e.preventDefault();
		closeUiOverlay();
	});

	$( '.header-follow-search .close-icon' ).hover(
		function() {
			$( this ).addClass( 'spin' );
		}, function() {
			$( this ).removeClass( 'spin' );
	});

	function openUiOverlay() {
		$( '.ui-overlay-search' ).addClass( 'is_open' );
	}

	function closeUiOverlay() {
		$( '.ui-overlay-search' )
		.fadeOut(400)
		.removeClass( 'is_open' );
	}

	$( '.ui-overlay-search .search-input input' ).on('focus', function() {
		$( '.search-input' ).attr( 'data-focused', 'true' );
		$( '.search-input input' ).addClass( '_is-focused' );
		$( '#__expand' ).addClass( 'visible' );
	});

	$( '.ui-overlay-search .search-input input' ).on('blur', function() {
		$( '.search-input' ).attr( 'data-focused', 'false' );
		$( '.search-input input' ).removeClass( '_is-focused' );
		$( '#__expand' ).removeClass( 'visible' );
	});

	$( '.post-meta .post-meta-inner .cta-btns a.is_inactive' ).on( 'click', function( e ) {
		e.preventDefault();
	});

	$( document ).on('keydown', function( e ) {
		if ( e.keyCode == 27 )
			closeUiOverlay();
		else /* do nothing */ ;
 	});

	$( '.mobile-nav' ).hide();

	// Functions for more-posts button click

	var loadMoreBtn = '.secondary-category-section .category-posts-column [data-clicked="false"]';

	function addLoader() {
		$( loadMoreBtn )
		.attr( 'data-clicked', 'true' )
		.append( '' );
	}

	$( loadMoreBtn ).on( 'click', function( e ) {
		$( this ).css({
			'background': '#50ABF1',
			'color': '#fff'
		});
		addLoader();
		e.preventDefault();
	});

	$scroll_top.on( 'click', function( e ) {
		$( 'body, html' ).animate({
			scrollTop: 0
		}, 1000);

		e.preventDefault();
	});

});
<|endoftext|>


<commit_before>/**
 * Springle Chat
 *
 * @author Saurabh aka JSX <saurabh@rebugged.com>
 * @copyright
 * @license GNU AFFERO GENERAL PUBLIC LICENSE v3
 */

var WebSocketServer = require('websocket').server;

// Check if SSL support is enabled
if (process.argv.indexOf('--enable-ssl') !== -1) {
    var https = require('https');
    var fs = require('fs');

    var options = {
        key: fs.readFileSync('/home/conf/ssl.key'),
        cert: fs.readFileSync('/home/conf/ssl.crt')
    };

    var server = https.createServer(options, function(request, response) {
        response.writeHead(404);
        response.end();
    });

    var port = 8805;
    var server_start_message = (new Date()) + ' Springle server with SSL is listening on port ' + port;
} else {
    var http = require('http');

    var server = http.createServer(function(request, response) {
        response.writeHead(404);
        response.end();
    });

    var port = 8804;
    var server_start_message = (new Date()) + ' Springle server is listening on port ' + port;
}

var clients = [];
var chat_rooms = {};

var allowed_origins = [
    'localhost',
    'springle.rebugged.com'
];

var allowed_protocol = 'chat';

var connection_id = 0;

server.listen(port, function() {
    console.log(server_start_message);
});

wsServer = new WebSocketServer({
    httpServer: server,
    autoAcceptConnections: false
});

function originIsAllowed(origin) {
    var origin_trimmed = origin.replace('http://', '')
                               .replace('https://', '');

    if (allowed_origins.indexOf(origin_trimmed) > -1) {
        return true;
    }

    return false;
}

wsServer.on('request', function(request) {
    if (!originIsAllowed(request.origin)) {
      // Make sure we only accept requests from an allowed origin
      request.reject();
      return;
    }

    if (request.requestedProtocols.indexOf(allowed_protocol) === -1) {
        request.reject();
        return false;
    }

    var connection = request.accept('chat', request.origin);
    connection.id = connection_id++;

    connection.on('message', function(message) {
        if (message.type === 'utf8') {
            var msgObj = JSON.parse(message.utf8Data);

            if (msgObj.type === 'intro') {
                connection.nickname = msgObj.nickname;
                connection.chatroom = msgObj.chatroom;

                if (chat_rooms[msgObj.chatroom] !== undefined) {
                    chat_rooms[msgObj.chatroom].push(connection);
                } else {
                    chat_rooms[msgObj.chatroom] = [connection];
                }

                connection.sendUTF(JSON.stringify({
                    type: 'welcome',
                    userId:connection.id
                }));

                broadcast_chatters_list(msgObj.chatroom);
            } else if (msgObj.type === 'message') {

                message_to_send = JSON.parse(message.utf8Data);
                message_to_send['sender'] = connection.id.toString();
                message_to_send = JSON.stringify(message_to_send);

                console.log(message_to_send)
                broadcast_message(message_to_send, msgObj.chatroom);
            } else if (msgObj.type.match(/^activity_/)) {
                // echo back any message type that start with activity_
                message_to_send = JSON.parse(message.utf8Data);
                message_to_send['sender'] = connection.id.toString();
                message_to_send = JSON.stringify(message_to_send);

                broadcast_message(message_to_send, msgObj.chatroom);
            }
        } else if (message.type === 'binary') {
            // At the moment, we are handling only text messages - no binary
            connection.sendUTF('Invalid message');
        }
    });

    connection.on('close', function(reasonCode, description) {
        var chatroom = connection.chatroom;
        var users = chat_rooms[chatroom];

        for (var i in users) {
            if (connection.id === users[i].id) {
                chat_rooms[chatroom].splice(i, 1);
                broadcast_chatters_list(connection.chatroom);
            }
        }
        console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');
    });

    function broadcast_message(message, chatroom) {
        var users = chat_rooms[chatroom];

        for (var i in users) {
            users[i].sendUTF(message);
        }
    }

    function broadcast_chatters_list(chatroom) {
        var nicklist = [];
        var msg_to_send;
        var users = chat_rooms[chatroom];

        for (var i in users) {
            nicklist.push(users[i].nickname);
        }

        msg_to_send = JSON.stringify({
            type: 'nicklist',
            nicklist: nicklist
        });

        broadcast_message(msg_to_send, chatroom);
    }

    function send_poke() {
        var msg = JSON.stringify({
            type: 'message',
            nickname: 'Bot',
            message: 'This is an automated message from the server.'
        });

        broadcast_message(msg);
    }

});
<commit_msg>Added sky.rebugged.com and mozilla.net to allowed domains.<commit_after>/**
 * Springle Chat
 *
 * @author Saurabh aka JSX <saurabh@rebugged.com>
 * @copyright
 * @license GNU AFFERO GENERAL PUBLIC LICENSE v3
 */

var WebSocketServer = require('websocket').server;

// Check if SSL support is enabled
if (process.argv.indexOf('--enable-ssl') !== -1) {
    var https = require('https');
    var fs = require('fs');

    var options = {
        key: fs.readFileSync('/home/conf/ssl.key'),
        cert: fs.readFileSync('/home/conf/ssl.crt')
    };

    var server = https.createServer(options, function(request, response) {
        response.writeHead(404);
        response.end();
    });

    var port = 8805;
    var server_start_message = (new Date()) + ' Springle server with SSL is listening on port ' + port;
} else {
    var http = require('http');

    var server = http.createServer(function(request, response) {
        response.writeHead(404);
        response.end();
    });

    var port = 8804;
    var server_start_message = (new Date()) + ' Springle server is listening on port ' + port;
}

var clients = [];
var chat_rooms = {};

var allowed_origins = [
    'localhost',
    'springle.rebugged.com',
    'sky.rebugged.com',
    'mozilla.net'
];

var allowed_protocol = 'chat';

var connection_id = 0;

server.listen(port, function() {
    console.log(server_start_message);
});

wsServer = new WebSocketServer({
    httpServer: server,
    autoAcceptConnections: false
});

function originIsAllowed(origin) {
    var origin_trimmed = origin.replace('http://', '')
                               .replace('https://', '');

    if (allowed_origins.indexOf(origin_trimmed) > -1) {
        return true;
    }

    return false;
}

wsServer.on('request', function(request) {
    if (!originIsAllowed(request.origin)) {
      // Make sure we only accept requests from an allowed origin
      request.reject();
      return;
    }

    if (request.requestedProtocols.indexOf(allowed_protocol) === -1) {
        request.reject();
        return false;
    }

    var connection = request.accept('chat', request.origin);
    connection.id = connection_id++;

    connection.on('message', function(message) {
        if (message.type === 'utf8') {
            var msgObj = JSON.parse(message.utf8Data);

            if (msgObj.type === 'intro') {
                connection.nickname = msgObj.nickname;
                connection.chatroom = msgObj.chatroom;

                if (chat_rooms[msgObj.chatroom] !== undefined) {
                    chat_rooms[msgObj.chatroom].push(connection);
                } else {
                    chat_rooms[msgObj.chatroom] = [connection];
                }

                connection.sendUTF(JSON.stringify({
                    type: 'welcome',
                    userId:connection.id
                }));

                broadcast_chatters_list(msgObj.chatroom);
            } else if (msgObj.type === 'message') {

                message_to_send = JSON.parse(message.utf8Data);
                message_to_send['sender'] = connection.id.toString();
                message_to_send = JSON.stringify(message_to_send);

                console.log(message_to_send)
                broadcast_message(message_to_send, msgObj.chatroom);
            } else if (msgObj.type.match(/^activity_/)) {
                // echo back any message type that start with activity_
                message_to_send = JSON.parse(message.utf8Data);
                message_to_send['sender'] = connection.id.toString();
                message_to_send = JSON.stringify(message_to_send);

                broadcast_message(message_to_send, msgObj.chatroom);
            }
        } else if (message.type === 'binary') {
            // At the moment, we are handling only text messages - no binary
            connection.sendUTF('Invalid message');
        }
    });

    connection.on('close', function(reasonCode, description) {
        var chatroom = connection.chatroom;
        var users = chat_rooms[chatroom];

        for (var i in users) {
            if (connection.id === users[i].id) {
                chat_rooms[chatroom].splice(i, 1);
                broadcast_chatters_list(connection.chatroom);
            }
        }
        console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');
    });

    function broadcast_message(message, chatroom) {
        var users = chat_rooms[chatroom];

        for (var i in users) {
            users[i].sendUTF(message);
        }
    }

    function broadcast_chatters_list(chatroom) {
        var nicklist = [];
        var msg_to_send;
        var users = chat_rooms[chatroom];

        for (var i in users) {
            nicklist.push(users[i].nickname);
        }

        msg_to_send = JSON.stringify({
            type: 'nicklist',
            nicklist: nicklist
        });

        broadcast_message(msg_to_send, chatroom);
    }

    function send_poke() {
        var msg = JSON.stringify({
            type: 'message',
            nickname: 'Bot',
            message: 'This is an automated message from the server.'
        });

        broadcast_message(msg);
    }

});
<|endoftext|>


<commit_before>var w = window.innerWidth;
var h = window.innerHeight;
var shapes = [];
var points = [];
var colors = [];
var viewerMode = false;
var i = 0;
var j = 0;
var bgColor = 0;
var weight = 5;
var increase = true;
var strokeColors;
var strokeN = 0;
var effectN = 0;
var view = false;

var ref = new Firebase("redraw.firebaseIO.com");
var shapesRef = ref.child("drawings");

function setup() {
  var redColor = color(255, 0, 0);
  var greenColor = color(0, 255, 0);
  var blueColor = color(0, 0, 255);
  var darkGray = color(50, 50, 50);
  var lightGray = color(200, 200, 200);
  strokeColors = new Array(lightGray, darkGray, redColor, greenColor, blueColor);
  createCanvas(w, h);
  // smooth();
  noSmooth();
}

function draw() {
  blockScroll();
  noFill();
  background(bgColor);

  strokeWeight(weight);
  for (var k = 0; k < shapes.length; k++) {
    beginShape();
    stroke(strokeColors[colors[k]]);
    for (var l = 0; l < shapes[k].length; l++) {
      if (l==0 || l==shapes[k].length-1) {
        curveVertex(shapes[k][l].x*w, shapes[k][l].y*h);
      }
      curveVertex(shapes[k][l].x*w, shapes[k][l].y*h);
    }
    endShape();
  }
  stroke(strokeColors[strokeN]);
  beginShape();
  for (var key in points) {
    if (key==0 || key==points.length-1) {
      curveVertex(points[key].x*w, points[key].y*h);
    }
    curveVertex(points[key].x*w, points[key].y*h);
  }
  endShape();

  if (mouseIsPressed && !viewerMode) {
    if (points.length == 0) {
      if (mouseY > 55) {
        points.push({x: mouseX/w, y:mouseY/h});
      }
    } else {
      points.push({x: mouseX/w, y:mouseY/h});
    }
  } else if (touchIsDown && !viewerMode) {
    if (points.length == 0) {
      if (touchY > 55) {
        points.push({x: touchX/w, y:touchY/h});
      }
    } else {
      points.push({x: touchX/w, y:touchY/h});
    }
  } else {
    points = [];
  }

  if (viewerMode || view) {
    // smooth();
    background(bgColor);
    if (i < shapes.length && !view) {
      for (var k = 0; k <= i; k++) {
        // smooth();
        beginShape();
        stroke(strokeColors[colors[k]]);
        if (k == i) {
          for (var l = 0; l <= j; l++) {
            if (l==0 || l==j) {
              curveVertex(shapes[k][l].x*w, shapes[k][l].y*h);
            }
            curveVertex(shapes[k][l].x*w, shapes[k][l].y*h);
            if (0 == j) {
              curveVertex(shapes[k][l].x*w+0.5, shapes[k][l].y*h+0.5);
              curveVertex(shapes[k][l].x*w+0.5, shapes[k][l].y*h+0.5);
            }
          }
        } else {
          for (var l = 0; l < shapes[k].length; l++) {
            curveVertex(shapes[k][l].x*w, shapes[k][l].y*h);
          }
        }
        endShape();
      }
      if (j < shapes[i].length - 1) {
        j++;
      } else {
        i++;
        j = 0;
      }
    } else {
      if (effectN === 0) {
        if (weight > 9) {
          increase = false;
        } else if (weight < 4) {
          increase = true;
        }
        if (increase) {
          weight += 0.3;
        } else {
          weight -= 0.1;
        }
      } else {
        weight = 5;
      }
      for (var k = 0; k < shapes.length; k++) {
        stroke(strokeColors[colors[k]]);
        // smooth();
        beginShape();
        for (var l = 0; l < shapes[k].length; l++) {
          var x = shapes[k][l].x*w;
          var y = shapes[k][l].y*h;
          if (l==0 || l==shapes[k].length-1) {
            curveVertex(x, y);
          }
          curveVertex(x, y);
          if (effectN === 1) {
            ellipse(x+random(4)-random(4), y+random(4)-random(4), 2+random(2), 2+random(2));
          }
        }
        endShape();
      }
    }
  }
}

function mouseReleased() {
  if (points.length != 0) {
    shapes.push(points);
    colors.push(strokeN);
  }
}

function touchEnded() {
  touchIsDown = false;
  if (points.length != 0) {
    shapes.push(points);
    colors.push(strokeN);
  }
}

function share() {
  var newShapesRef = shapesRef.push();
  newShapesRef.set({shapes: shapes, bgColor: bgColor, colors: colors, effectN: effectN});
  window.open("http://jackbdu.me/redrawer/drawings/?"+newShapesRef.path.o[1]);
}

function clearAll() {
  shapes = [];
  colors = [];
}

function toggleBackground() {
  if (bgColor == 0) {
    bgColor = 255;
  } else {
    bgColor = 0;
  }
}

function changeColor() {
  if (strokeN < strokeColors.length - 1) {
    strokeN++;
  } else {
    strokeN = 0;
  }
  var theRGBA = strokeColors[strokeN].rgba;
  $('#color').css('background-color', 'rgb('+theRGBA[0]+','+theRGBA[1]+','+theRGBA[2]+')');
}

function windowResized() {
  resizeCanvas(windowWidth, windowHeight);
  w = window.innerWidth;
  h = window.innerHeight;
}

function viewEdit() {
  view = !view;
}

function changeEffect() {
  if (effectN < 1) {
    effectN++;
  } else {
    effectN = 0;
  }
}

// block scrolling in iphone
function blockScroll() {
  $("body").swipe({
    swipe:function(event, direction, distance, duration, fingerCount) {
      var swipeDirection = direction;
    }
  });
}<commit_msg>drawing bug fixed<commit_after>var w = window.innerWidth;
var h = window.innerHeight;
var shapes = [];
var points = [];
var colors = [];
var viewerMode = false;
var i = 0;
var j = 0;
var bgColor = 0;
var weight = 5;
var increase = true;
var strokeColors;
var strokeN = 0;
var effectN = 0;
var view = false;

var ref = new Firebase("redraw.firebaseIO.com");
var shapesRef = ref.child("drawings");

function setup() {
  var redColor = color(255, 0, 0);
  var greenColor = color(0, 255, 0);
  var blueColor = color(0, 0, 255);
  var darkGray = color(50, 50, 50);
  var lightGray = color(200, 200, 200);
  strokeColors = new Array(lightGray, darkGray, redColor, greenColor, blueColor);
  createCanvas(w, h);
  // smooth();
  noSmooth();
}

function draw() {
  blockScroll();
  noFill();
  background(bgColor);

  strokeWeight(weight);
  for (var k = 0; k < shapes.length; k++) {
    beginShape();
    stroke(strokeColors[colors[k]]);
    for (var l = 0; l < shapes[k].length; l++) {
      if (l==0 || l==shapes[k].length-1) {
        curveVertex(shapes[k][l].x*w, shapes[k][l].y*h);
      }
      curveVertex(shapes[k][l].x*w, shapes[k][l].y*h);
    }
    endShape();
  }
  stroke(strokeColors[strokeN]);
  beginShape();
  for (var key in points) {
    if (key==0 || key==points.length-1) {
      curveVertex(points[key].x*w, points[key].y*h);
    }
    curveVertex(points[key].x*w, points[key].y*h);
  }
  endShape();

  if (mouseIsPressed && !viewerMode) {
    if (points.length == 0) {
      if (mouseY > 55) {
        points.push({x: mouseX/w, y:mouseY/h});
      }
    } else {
      points.push({x: mouseX/w, y:mouseY/h});
    }
  } else if (touchIsDown && !viewerMode) {
    if (points.length == 0) {
      if (touchY > 55) {
        points.push({x: touchX/w, y:touchY/h});
      }
    } else {
      points.push({x: touchX/w, y:touchY/h});
    }
  } else {
    points = [];
  }

  if (viewerMode || view) {
    // smooth();
    background(bgColor);
    if (i < shapes.length && !view) {
      for (var k = 0; k <= i; k++) {
        // smooth();
        beginShape();
        stroke(strokeColors[colors[k]]);
        if (k == i) {
          for (var l = 0; l <= j; l++) {
            if (l==0 || l==j) {
              curveVertex(shapes[k][l].x*w, shapes[k][l].y*h);
            }
            curveVertex(shapes[k][l].x*w, shapes[k][l].y*h);
            if (0 == j) {
              curveVertex(shapes[k][l].x*w+0.5, shapes[k][l].y*h+0.5);
              curveVertex(shapes[k][l].x*w+0.5, shapes[k][l].y*h+0.5);
            }
          }
        } else {
          for (var l = 0; l < shapes[k].length; l++) {
            curveVertex(shapes[k][l].x*w, shapes[k][l].y*h);
            if (l==0 || l==shapes[k].length) {
              curveVertex(shapes[k][l].x*w, shapes[k][l].y*h);
            }
            curveVertex(shapes[k][l].x*w, shapes[k][l].y*h);
          }
        }
        endShape();
      }
      if (j < shapes[i].length - 1) {
        j++;
      } else {
        i++;
        j = 0;
      }
    } else {
      if (effectN === 0) {
        if (weight > 9) {
          increase = false;
        } else if (weight < 4) {
          increase = true;
        }
        if (increase) {
          weight += 0.3;
        } else {
          weight -= 0.1;
        }
      } else {
        weight = 5;
      }
      for (var k = 0; k < shapes.length; k++) {
        stroke(strokeColors[colors[k]]);
        // smooth();
        beginShape();
        for (var l = 0; l < shapes[k].length; l++) {
          var x = shapes[k][l].x*w;
          var y = shapes[k][l].y*h;
          if (l==0 || l==shapes[k].length-1) {
            curveVertex(x, y);
          }
          curveVertex(x, y);
          if (effectN === 1) {
            ellipse(x+random(4)-random(4), y+random(4)-random(4), 2+random(2), 2+random(2));
          }
        }
        endShape();
      }
    }
  }
}

function mouseReleased() {
  if (points.length != 0) {
    shapes.push(points);
    colors.push(strokeN);
  }
}

function touchEnded() {
  touchIsDown = false;
  if (points.length != 0) {
    shapes.push(points);
    colors.push(strokeN);
  }
}

function share() {
  var newShapesRef = shapesRef.push();
  newShapesRef.set({shapes: shapes, bgColor: bgColor, colors: colors, effectN: effectN});
  window.open("http://jackbdu.me/redrawer/drawings/?"+newShapesRef.path.o[1]);
}

function clearAll() {
  shapes = [];
  colors = [];
}

function toggleBackground() {
  if (bgColor == 0) {
    bgColor = 255;
  } else {
    bgColor = 0;
  }
}

function changeColor() {
  if (strokeN < strokeColors.length - 1) {
    strokeN++;
  } else {
    strokeN = 0;
  }
  var theRGBA = strokeColors[strokeN].rgba;
  $('#color').css('background-color', 'rgb('+theRGBA[0]+','+theRGBA[1]+','+theRGBA[2]+')');
}

function windowResized() {
  resizeCanvas(windowWidth, windowHeight);
  w = window.innerWidth;
  h = window.innerHeight;
}

function viewEdit() {
  view = !view;
}

function changeEffect() {
  if (effectN < 1) {
    effectN++;
  } else {
    effectN = 0;
  }
}

// block scrolling in iphone
function blockScroll() {
  $("body").swipe({
    swipe:function(event, direction, distance, duration, fingerCount) {
      var swipeDirection = direction;
    }
  });
}<|endoftext|>


<commit_before>var firstnames = [], lastnames = [], states = [], messages = [];
var slideAuthor, slideText, slideContent;
var backwardsSlide, forwardSlide;
var nextMessageTimeout = null;
var current = -1;
var blocked = false;
var hovering = false;
var loaded = false;
var xmlResource = "https://www.staatsschutz.at/appsrv/messages";
var timeout = 15000;

$(function () {
    findElements();
})

function htmlColToArray(xml, tagName) {
    var i, x, xmlDoc, nodeArray = [];
    xmlDoc = xml.responseXML;
    x = xmlDoc.getElementsByTagName(tagName);
    for (i = 0; i < x.length; i++) {
        nodeArray = nodeArray.concat([$("<div/>").text(x[i].childNodes[0].nodeValue).html()]);
    }
    return nodeArray;
}

function findElements() {
    slideAuthor = document.getElementById("slideauthor");
    slideText = document.getElementById("slidetext");
    slideContent = document.getElementById("slideContent");
    backwardsSlide = document.getElementById("slideleft");
    forwardSlide = document.getElementById("slideright");
    quoteFadeout = document.getElementById("quoteFadeout");
}

function setSlideScreen(index) {
    slideAuthor.innerHTML = firstnames[index] + " " + lastnames[index] + ", " + states[index];
    slideText.innerHTML = messages[index];
}

function getElements(xml) {
    firstnames = firstnames.concat(htmlColToArray(xml, "firstname"));
    lastnames = lastnames.concat(htmlColToArray(xml, "lastname"));
    states = states.concat(htmlColToArray(xml, "state"));
    messages = messages.concat(htmlColToArray(xml, "message"));
}

function openXML() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState === 4 && xhttp.status === 200) {
            getElements(xhttp);
            findElements();
            loaded = true;
            backwardsSlide.classList.remove("slideUnselectable");
            forwardSlide.classList.remove("slideUnselectable");
            autoSlide();
        }
    };
    xhttp.open("GET", xmlResource, true);
    xhttp.send();
}

function loadNext() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState === 4 && xhttp.status === 200) {
            getElements(xhttp);
        }
    };
    xhttp.open("GET", xmlResource, true);
    xhttp.send();
}

function slideForwards() {

    if (blocked || ! loaded)
        return;

    blocked = true;

    if (current == -1) {
        backwardsSlide.classList.add("slideUnselectable");
    } else if (current == 0) {
        backwardsSlide.classList.remove("slideUnselectable");
    } else if (current + 3 >= firstnames.length) {
        loadNext();
    }

    nextMessageTimeout && clearTimeout(nextMessageTimeout);
    nextMessageTimeout = setTimeout(autoSlide, timeout);

    current++;

    slideContent.classList.remove("slideBackwards");
    slideContent.classList.remove("slideForwards");
    slideContent.offsetWidth = slideContent.offsetWidth;
    slideContent.classList.add("slideForwards");

    setTimeout(function () {
        setSlideScreen(current);
        blocked = false;
    }, 300);
}

function slideBackwards() {
    if (blocked == true)
        return;

    blocked = true;

    if (current == 0) {
        blocked = false;
        return;
    } else if (current <= 1) {
        backwardsSlide.classList.add("slideUnselectable");
    }

    nextMessageTimeout && clearTimeout(nextMessageTimeout);
    nextMessageTimeout = setTimeout(autoSlide, timeout);

    current--;

    slideContent.classList.remove("slideBackwards");
    slideContent.classList.remove("slideForwards");
    slideContent.offsetWidth = slideContent.offsetWidth;
    slideContent.classList.add("slideBackwards");

    setTimeout(function () {
        setSlideScreen(current);
        blocked = false;
    }, 300);
}

function autoSlide() {
    if (!hovering) {
        slideForwards();
    }
}

$(document).ready(function(){
    $("#slider").hover(function () {
        hovering = true;
        slideText.classList.remove("sliderShrink");
        slideText.classList.add("sliderExpand");
        quoteFadeout.classList.add("sliderExpand");
    }, function () {
        hovering = false;
        slideText.classList.remove("sliderExpand");
        slideText.classList.add("sliderShrink");
        quoteFadeout.classList.remove("sliderExpand");
    });
});

window.onload = function () {
    openXML();
};
<commit_msg>Prevent backwards slide from initial (preloaded) message<commit_after>var firstnames = [], lastnames = [], states = [], messages = [];
var slideAuthor, slideText, slideContent;
var backwardsSlide, forwardSlide;
var nextMessageTimeout = null;
var current = -1;
var blocked = false;
var hovering = false;
var loaded = false;
var xmlResource = "https://www.staatsschutz.at/appsrv/messages";
var timeout = 15000;

$(function () {
    findElements();
})

function htmlColToArray(xml, tagName) {
    var i, x, xmlDoc, nodeArray = [];
    xmlDoc = xml.responseXML;
    x = xmlDoc.getElementsByTagName(tagName);
    for (i = 0; i < x.length; i++) {
        nodeArray = nodeArray.concat([$("<div/>").text(x[i].childNodes[0].nodeValue).html()]);
    }
    return nodeArray;
}

function findElements() {
    slideAuthor = document.getElementById("slideauthor");
    slideText = document.getElementById("slidetext");
    slideContent = document.getElementById("slideContent");
    backwardsSlide = document.getElementById("slideleft");
    forwardSlide = document.getElementById("slideright");
    quoteFadeout = document.getElementById("quoteFadeout");
}

function setSlideScreen(index) {
    slideAuthor.innerHTML = firstnames[index] + " " + lastnames[index] + ", " + states[index];
    slideText.innerHTML = messages[index];
}

function getElements(xml) {
    firstnames = firstnames.concat(htmlColToArray(xml, "firstname"));
    lastnames = lastnames.concat(htmlColToArray(xml, "lastname"));
    states = states.concat(htmlColToArray(xml, "state"));
    messages = messages.concat(htmlColToArray(xml, "message"));
}

function openXML() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState === 4 && xhttp.status === 200) {
            getElements(xhttp);
            findElements();
            loaded = true;
            forwardSlide.classList.remove("slideUnselectable");
            autoSlide();
        }
    };
    xhttp.open("GET", xmlResource, true);
    xhttp.send();
}

function loadNext() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState === 4 && xhttp.status === 200) {
            getElements(xhttp);
        }
    };
    xhttp.open("GET", xmlResource, true);
    xhttp.send();
}

function slideForwards() {

    if (blocked || ! loaded)
        return;

    blocked = true;

    if (current == -1) {
        backwardsSlide.classList.add("slideUnselectable");
    } else if (current == 0) {
        backwardsSlide.classList.remove("slideUnselectable");
    } else if (current + 3 >= firstnames.length) {
        loadNext();
    }

    nextMessageTimeout && clearTimeout(nextMessageTimeout);
    nextMessageTimeout = setTimeout(autoSlide, timeout);

    current++;

    slideContent.classList.remove("slideBackwards");
    slideContent.classList.remove("slideForwards");
    slideContent.offsetWidth = slideContent.offsetWidth;
    slideContent.classList.add("slideForwards");

    setTimeout(function () {
        setSlideScreen(current);
        blocked = false;
    }, 300);
}

function slideBackwards() {
    if (blocked || ! loaded)
        return;

    blocked = true;

    if (current == 0) {
        blocked = false;
        return;
    } else if (current <= 1) {
        backwardsSlide.classList.add("slideUnselectable");
    }

    nextMessageTimeout && clearTimeout(nextMessageTimeout);
    nextMessageTimeout = setTimeout(autoSlide, timeout);

    current--;

    slideContent.classList.remove("slideBackwards");
    slideContent.classList.remove("slideForwards");
    slideContent.offsetWidth = slideContent.offsetWidth;
    slideContent.classList.add("slideBackwards");

    setTimeout(function () {
        setSlideScreen(current);
        blocked = false;
    }, 300);
}

function autoSlide() {
    if (!hovering) {
        slideForwards();
    }
}

$(document).ready(function(){
    $("#slider").hover(function () {
        hovering = true;
        slideText.classList.remove("sliderShrink");
        slideText.classList.add("sliderExpand");
        quoteFadeout.classList.add("sliderExpand");
    }, function () {
        hovering = false;
        slideText.classList.remove("sliderExpand");
        slideText.classList.add("sliderShrink");
        quoteFadeout.classList.remove("sliderExpand");
    });
});

window.onload = function () {
    openXML();
};
<|endoftext|>


<commit_before>/**
 * carousel
 * @authors Ping YF (koakumaping@163.com)
 * @date    2016-04-14 10:48:35
 * @version $Id$
 */

(function(factory) {
    "use strict";
    if(typeof exports === "object" && typeof module === "object") {
        module.exports = factory();
    } else if(typeof define === "function" && (define.amd || define.cmd)) {
        define(factory);
    } else {
        window.slider = factory();
    }
})(function(){
    'use strict';
    function slider (selector) {
        this.config = {
            speed: 35,
            x: 0,
            xCurrent: 0,
            xEnd: 0,
            y: 0,
            yCurrent: 0,
            zIndex: 2,
            direction: 'stay'
        };

        this.selector = document.querySelectorAll(selector)[0];
        this.length = this.selector.querySelectorAll('li').length;
        this.clientWidth = this.selector.clientWidth;
        this.isRunning = false;

        this.calPosition;
        this.prevCalPosition;
        this.nextCalPosition;

        // 记忆位置
        this.index = 0;
        this.indexPrev;
        this.indexNext;
        this.indexFlag = true;
        this.canMoveX = true;
        this.canMoveY = true;

        // 初始化元素
        this.li = this.selector.querySelectorAll('li');

        this.elment,
        this.elmentPrev,
        this.elmentNext;
        this.init();
    };

    slider.prototype = {
        init: function () {
            var self = this;
            self.addFocus();
            self.setActiveFocus();
            self.requestAnimationFrame();

            self.selector.querySelectorAll('ul')[0].addEventListener('touchstart', function (event) {
                event.preventDefault();
                if (self.isRunning) {
                    return true;
                }

                self.config.x = event.changedTouches[0].pageX;
                self.config.y = event.changedTouches[0].pageY;
            });

            self.selector.querySelectorAll('ul')[0].addEventListener('touchmove', function (event) {
                event.preventDefault();
                if (self.isRunning) {
                    return true;
                }

                self.config.xCurrent = event.changedTouches[0].pageX;
                self.config.yCurrent = event.changedTouches[0].pageY;

                // 上下滑动
                if ( self.canMoveY ) {
                    window.scrollBy(0, self.config.y - self.config.yCurrent);
                    if (Math.abs(self.config.y - self.config.yCurrent) > 12) {
                        self.canMoveX = false;
                    }
                }

                // 左右滑动
                if (self.canMoveX) {
                    if (self.index === 0) {
                        self.indexPrev = self.length - 1;
                        self.indexFlag = false;
                    } else {
                        self.indexPrev = self.index - 1;
                    }

                    if (self.index >= self.length - 1) {
                        self.indexNext = 0;
                        self.indexFlag = false;
                    } else {
                        self.indexNext = self.index + 1;
                    }

                    self.calPosition = self.config.xCurrent - self.config.x;

                    // 防止超出
                    if ( self.length > 1 ){
                        if (self.calPosition >= self.clientWidth) {
                            self.calPosition = self.clientWidth;
                        }

                        if (self.calPosition <= - self.clientWidth) {
                            self.calPosition = - self.clientWidth;
                        }
                    } else {
                        return false
                    }

                    self.elment = self.li[self.index].querySelectorAll('img')[0];

                    var elmentPrev,
                        elmentNext;

                    if (self.calPosition >= 0) {
                        // 向右滑动
                        elmentPrev = self.li[self.indexPrev].querySelectorAll('img')[0];
                    } else {
                        // 向左滑动
                        elmentNext = self.li[self.indexNext].querySelectorAll('img')[0];
                    }

                    var elmentLi = self.li[self.index],
                        elmentLiPrev = self.li[self.indexPrev],
                        elmentLiNext = self.li[self.indexNext];

                    elmentLi.style.visibility = 'visible';

                    self.prevCalPosition = self.calPosition - self.clientWidth;
                    self.nextCalPosition = self.clientWidth + self.calPosition;

                    if ( Math.abs(self.calPosition) > 20 ) {
                        self.canMoveY = false;
                        if (elmentPrev) {
                            elmentLiPrev.style.visibility = 'visible';
                            elmentPrev.style.transform = 'translate3d(' + self.prevCalPosition +'px,0,0)';
                        }

                        if (elmentNext) {
                            elmentLiNext.style.visibility = 'visible';
                            elmentNext.style.transform = 'translate3d(' + self.nextCalPosition +'px,0,0)';
                        }

                        self.elment.style.transform = 'translate3d(' + self.calPosition +'px,0,0)';

                        // 向左滑动
                        if (self.calPosition > 0) {
                            self.config.direction = 'left';
                            if ( self.length > 2 ){
                                elmentLiNext.style.visibility = 'hidden';
                            }
                        } else if (self.calPosition < 0) {
                            self.config.direction = 'right';
                            if ( self.length > 2 ){
                                elmentLiPrev.style.visibility = 'hidden';
                            }
                        } else {
                            self.config.direction = 'stay';
                        }
                    }
                }
            });

            self.selector.querySelectorAll('ul')[0].addEventListener('touchend', function (event) {
                self.canMoveX = true;
                self.canMoveY = true;

                if (self.isRunning) {
                    return true;
                }

                switch (self.config.direction) {
                    case 'left':
                        self.prev();
                        self.config.direction = 'stay';
                        break;
                    case 'right':
                        self.next();
                        self.config.direction = 'stay';
                        break;
                    case 'stay':
                        self.stay();
                        break;
                }
            });
        },

        prev: function (index) {

            var self = this;

            var index = self.index;
            var indexPrev,
                indexFlag = true;

            if (self.index === 0) {
                indexPrev = self.length - 1;
                indexFlag = false;
            } else {
                indexPrev = index - 1;
            }

            console.log(self.index, self.length)

            var elment = self.li[self.index].querySelectorAll('img')[0],
                elmentPrev = self.li[self.indexPrev].querySelectorAll('img')[0];

            var elmentLi = self.li[self.index],
                elmentLiPrev = self.li[self.indexPrev];

            elmentLi.style.visibility = 'visible';
            elmentLiPrev.style.visibility = 'visible';

            var _run = function () {
                self.isRunning = true;
                self.prevCalPosition = self.prevCalPosition + self.config.speed;
                self.calPosition = self.calPosition + self.config.speed;

                elmentPrev.style.transform = 'translate3d(' + self.prevCalPosition +'px,0,0)';
                elment.style.transform = 'translate3d(' + self.calPosition +'px,0,0)';

                if (self.calPosition < self.clientWidth) {
                    requestAnimationFrame(_run);
                } else {
                    self.prevCalPosition = 0;
                    self.calPosition = 0;

                    elmentPrev.style.transform = 'translate3d(' + self.prevCalPosition +'px,0,0)';
                    elment.style.transform = 'translate3d(' + self.calPosition +'px,0,0)';

                    elmentLi.style.visibility = 'hidden';

                    self.isRunning = false;

                    if (!indexFlag) {
                        self.index = self.length - 1;
                    } else {
                        self.index --;
                    }
                    self.setActiveFocus();
                }
            }

            _run();
        },

        next: function (index) {
            var self = this;

            var index = self.index;
            var indexNext,
                indexFlag = true;

            if (self.index >= self.length - 1) {
                indexNext = 0;
                indexFlag = false;
            } else {
                indexNext = index + 1;
            }

            console.log(self.index, self.length)

            var li = document.querySelectorAll('li');
            var elment = li[index].querySelectorAll('img')[0];
            var elmentNext = li[indexNext].querySelectorAll('img')[0];

            var elmentLi = li[index];
            var elmentLiNext = li[indexNext];

            self.x = self.calPosition + self.clientWidth;  //prev

            var _run = function () {
                self.isRunning = true;
                self.x = self.x - self.config.speed;
                self.calPosition = self.calPosition - self.config.speed;

                elmentNext.style.transform = 'translate3d(' + self.x +'px,0,0)';
                elment.style.transform = 'translate3d(' + self.calPosition +'px,0,0)';

                if (self.calPosition > - self.clientWidth) {
                    requestAnimationFrame(_run);
                } else {
                    self.x = 0;
                    self.calPosition = 0;

                    elmentNext.style.transform = 'translate3d(' + self.x +'px,0,0)';
                    elment.style.transform = 'translate3d(' + self.calPosition +'px,0,0)';

                    elmentLi.style.visibility = 'hidden';

                    self.isRunning = false;

                    if (indexFlag) {
                        self.index ++;
                    } else {
                        self.index = 0;
                    }
                    self.setActiveFocus();
                }
            }

            _run();

        },

        stay: function () {
            var self = this;
            self.isRunning = false;
        },

        // 添加指示器
        addFocus: function () {
            var self = this;
            var innerHtml = ''
            var baseHtml = ''
            var $focus = this.selector.querySelector('.focus-horizontal')

            for (var i = 0; i < self.length; ++i) {
                innerHtml += baseHtml
            }

            $focus.innerHTML = innerHtml
        },

        setActiveFocus: function () {

            var $bullets = this.selector.querySelectorAll('.focus-horizontal-bullet')

            for (var i = 0, l = $bullets.length; i < l; ++i) {
                if (i !== this.index) {
                    $bullets[i].className = 'focus-horizontal-bullet'
                } else {
                    $bullets[i].className = 'focus-horizontal-bullet active'
                }
            }
        },

        requestAnimationFrame: function () {
            var lastTime = 0;
            var vendors = ['webkit', 'moz'];
            for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
                window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
                window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] ||    // name has changed in Webkit
                                              window[vendors[x] + 'CancelRequestAnimationFrame'];
            }

            if (!window.requestAnimationFrame) {
                window.requestAnimationFrame = function(callback, element) {
                    var currTime = new Date().getTime();
                    var timeToCall = Math.max(0, 16.7 - (currTime - lastTime));
                    var id = window.setTimeout(function() {
                        callback(currTime + timeToCall);
                    }, timeToCall);
                    lastTime = currTime + timeToCall;
                    return id;
                };
            }
            if (!window.cancelAnimationFrame) {
                window.cancelAnimationFrame = function(id) {
                    clearTimeout(id);
                };
            }
        }
    }

    return slider;
});<commit_msg>增加滑动动画<commit_after>/**
 * carousel
 * @authors Ping YF (koakumaping@163.com)
 * @date    2016-04-14 10:48:35
 * @version $Id$
 */

(function(factory) {
    "use strict";
    if(typeof exports === "object" && typeof module === "object") {
        module.exports = factory();
    } else if(typeof define === "function" && (define.amd || define.cmd)) {
        define(factory);
    } else {
        window.slider = factory();
    }
})(function(){
    'use strict';
    function slider (selector) {
        this.config = {
            speed: 600,
            x: 0,
            xCurrent: 0,
            xEnd: 0,
            y: 0,
            yCurrent: 0,
            zIndex: 2,
            direction: 'stay'
        };

        this.selector = document.querySelectorAll(selector)[0];
        this.length = this.selector.querySelectorAll('li').length;
        this.clientWidth = this.selector.clientWidth;
        this.isRunning = false;

        this.calPosition;
        this.prevCalPosition;
        this.nextCalPosition;

        // 记忆位置
        this.index = 0;
        this.indexPrev;
        this.indexNext;
        this.indexFlag = true;
        this.canMoveX = true;
        this.canMoveY = true;

        // 初始化元素
        this.li = this.selector.querySelectorAll('li');

        this.elment,
        this.elmentPrev,
        this.elmentNext;
        this.init();
    };

    slider.prototype = {
        init: function () {
            var self = this;
            self.addFocus();
            self.setActiveFocus();
            self.requestAnimationFrame();

            self.selector.querySelectorAll('ul')[0].addEventListener('touchstart', function (event) {
                event.preventDefault();
                if (self.isRunning) {
                    return true;
                }

                self.config.x = event.changedTouches[0].pageX;
                self.config.y = event.changedTouches[0].pageY;
            });

            self.selector.querySelectorAll('ul')[0].addEventListener('touchmove', function (event) {
                event.preventDefault();
                if (self.isRunning) {
                    return true;
                }

                self.config.xCurrent = event.changedTouches[0].pageX;
                self.config.yCurrent = event.changedTouches[0].pageY;

                // 上下滑动
                if ( self.canMoveY ) {
                    window.scrollBy(0, self.config.y - self.config.yCurrent);
                    if (Math.abs(self.config.y - self.config.yCurrent) > 12) {
                        self.canMoveX = false;
                    }
                }

                // 左右滑动
                if (self.canMoveX) {
                    if (self.index === 0) {
                        self.indexPrev = self.length - 1;
                        self.indexFlag = false;
                    } else {
                        self.indexPrev = self.index - 1;
                    }

                    if (self.index >= self.length - 1) {
                        self.indexNext = 0;
                        self.indexFlag = false;
                    } else {
                        self.indexNext = self.index + 1;
                    }

                    self.calPosition = self.config.xCurrent - self.config.x;

                    // 防止超出
                    if ( self.length > 1 ){
                        if (self.calPosition >= self.clientWidth) {
                            self.calPosition = self.clientWidth;
                        }

                        if (self.calPosition <= - self.clientWidth) {
                            self.calPosition = - self.clientWidth;
                        }
                    } else {
                        return false
                    }

                    self.elment = self.li[self.index].querySelectorAll('img')[0];

                    var elmentPrev,
                        elmentNext;

                    if (self.calPosition >= 0) {
                        // 向右滑动
                        elmentPrev = self.li[self.indexPrev].querySelectorAll('img')[0];
                    } else {
                        // 向左滑动
                        elmentNext = self.li[self.indexNext].querySelectorAll('img')[0];
                    }

                    var elmentLi = self.li[self.index],
                        elmentLiPrev = self.li[self.indexPrev],
                        elmentLiNext = self.li[self.indexNext];

                    elmentLi.style.visibility = 'visible';

                    self.prevCalPosition = self.calPosition - self.clientWidth;
                    self.nextCalPosition = self.clientWidth + self.calPosition;

                    if ( Math.abs(self.calPosition) > 20 ) {
                        self.canMoveY = false;
                        if (elmentPrev) {
                            elmentLiPrev.style.visibility = 'visible';
                            elmentPrev.style.transform = 'translate3d(' + self.prevCalPosition +'px,0,0)';
                        }

                        if (elmentNext) {
                            elmentLiNext.style.visibility = 'visible';
                            elmentNext.style.transform = 'translate3d(' + self.nextCalPosition +'px,0,0)';
                        }

                        self.elment.style.transform = 'translate3d(' + self.calPosition +'px,0,0)';

                        // 向左滑动
                        if (self.calPosition > 0) {
                            self.config.direction = 'left';
                            if ( self.length > 2 ){
                                elmentLiNext.style.visibility = 'hidden';
                            }
                        } else if (self.calPosition < 0) {
                            self.config.direction = 'right';
                            if ( self.length > 2 ){
                                elmentLiPrev.style.visibility = 'hidden';
                            }
                        } else {
                            self.config.direction = 'stay';
                        }
                    }
                }
            });

            self.selector.querySelectorAll('ul')[0].addEventListener('touchend', function (event) {
                self.canMoveX = true;
                self.canMoveY = true;

                if (self.isRunning) {
                    return true;
                }

                switch (self.config.direction) {
                    case 'left':
                        self.prev();
                        self.config.direction = 'stay';
                        break;
                    case 'right':
                        self.next();
                        self.config.direction = 'stay';
                        break;
                    case 'stay':
                        self.stay();
                        break;
                }
            });
        },

        prev: function (index) {

            var self = this;

            var index = self.index;
            var indexPrev,
                indexFlag = true;

            if (self.index === 0) {
                indexPrev = self.length - 1;
                indexFlag = false;
            } else {
                indexPrev = index - 1;
            }

            var elment = self.li[self.index].querySelectorAll('img')[0],
                elmentPrev = self.li[self.indexPrev].querySelectorAll('img')[0];

            var elmentLi = self.li[self.index],
                elmentLiPrev = self.li[self.indexPrev];

            elmentLi.style.visibility = 'visible';
            elmentLiPrev.style.visibility = 'visible';
            var start = 0
            var _run = function () {
                self.isRunning = true;

                start ++
                self.prevCalPosition = self.easeOutCubic(start, self.prevCalPosition, self.clientWidth, self.config.speed);
                self.calPosition = self.easeOutCubic(start, self.calPosition, self.clientWidth, self.config.speed);

                elmentPrev.style.transform = 'translate3d(' + self.prevCalPosition +'px,0,0)';
                elment.style.transform = 'translate3d(' + self.calPosition +'px,0,0)';

                if (self.calPosition < self.clientWidth) {
                    requestAnimationFrame(_run);
                } else {
                    self.prevCalPosition = 0;
                    self.calPosition = 0;

                    elmentPrev.style.transform = 'translate3d(' + self.prevCalPosition +'px,0,0)';
                    elment.style.transform = 'translate3d(' + self.calPosition +'px,0,0)';

                    elmentLi.style.visibility = 'hidden';

                    self.isRunning = false;

                    if (!indexFlag) {
                        self.index = self.length - 1;
                    } else {
                        self.index --;
                    }
                    self.setActiveFocus();
                }
            }

            _run();
        },

        next: function (index) {
            var self = this;

            var index = self.index;
            var indexNext,
                indexFlag = true;

            if (self.index >= self.length - 1) {
                indexNext = 0;
                indexFlag = false;
            } else {
                indexNext = index + 1;
            }

            var li = document.querySelectorAll('li');
            var elment = li[index].querySelectorAll('img')[0];
            var elmentNext = li[indexNext].querySelectorAll('img')[0];

            var elmentLi = li[index];
            var elmentLiNext = li[indexNext];

            self.x = self.calPosition + self.clientWidth;  //prev
            var start = 0
            var _run = function () {
                self.isRunning = true;

                start ++
                self.x = self.easeOutCubic(start, self.x, -self.clientWidth, self.config.speed);
                self.calPosition = self.easeOutCubic(start, self.calPosition, -self.clientWidth, self.config.speed);

                elmentNext.style.transform = 'translate3d(' + self.x +'px,0,0)';
                elment.style.transform = 'translate3d(' + self.calPosition +'px,0,0)';

                if (self.calPosition > - self.clientWidth) {
                    requestAnimationFrame(_run);
                } else {
                    self.x = 0;
                    self.calPosition = 0;

                    elmentNext.style.transform = 'translate3d(' + self.x +'px,0,0)';
                    elment.style.transform = 'translate3d(' + self.calPosition +'px,0,0)';

                    elmentLi.style.visibility = 'hidden';

                    self.isRunning = false;

                    if (indexFlag) {
                        self.index ++;
                    } else {
                        self.index = 0;
                    }
                    self.setActiveFocus();
                }
            }

            _run();

        },

        stay: function () {
            var self = this;
            self.isRunning = false;
        },

        // 添加指示器
        addFocus: function () {
            var self = this;
            var innerHtml = ''
            var baseHtml = ''
            var $focus = this.selector.querySelector('.focus-horizontal')

            for (var i = 0; i < self.length; ++i) {
                innerHtml += baseHtml
            }

            $focus.innerHTML = innerHtml
        },

        easeOutCubic: function(t, b, c, d) {
            return c * ((t = t/d - 1) * t * t + 1) + b;
        },

        setActiveFocus: function () {

            var $bullets = this.selector.querySelectorAll('.focus-horizontal-bullet')

            for (var i = 0, l = $bullets.length; i < l; ++i) {
                if (i !== this.index) {
                    $bullets[i].className = 'focus-horizontal-bullet'
                } else {
                    $bullets[i].className = 'focus-horizontal-bullet active'
                }
            }
        },

        requestAnimationFrame: function () {
            var lastTime = 0;
            var vendors = ['webkit', 'moz'];
            for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
                window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
                window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] ||    // name has changed in Webkit
                                              window[vendors[x] + 'CancelRequestAnimationFrame'];
            }

            if (!window.requestAnimationFrame) {
                window.requestAnimationFrame = function(callback, element) {
                    var currTime = new Date().getTime();
                    var timeToCall = Math.max(0, 16.7 - (currTime - lastTime));
                    var id = window.setTimeout(function() {
                        callback(currTime + timeToCall);
                    }, timeToCall);
                    lastTime = currTime + timeToCall;
                    return id;
                };
            }
            if (!window.cancelAnimationFrame) {
                window.cancelAnimationFrame = function(id) {
                    clearTimeout(id);
                };
            }
        }
    }

    return slider;
});<|endoftext|>