Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
	<meta charset="utf-8">
	<meta http-equiv="x-ua-compatible" content="ie=edge">
	<title></title>
	<meta name="description" content="">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css">
	<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
	<link href="https://fonts.googleapis.com/css?family=Josefin+Sans|Lobster+Two" rel="stylesheet">
	<link rel="stylesheet" href="dist/css/style.css">

	<script type="text/javascript" src="https://cdn.emailjs.com/dist/email.min.js"></script>
</head>

<body>
	<!--[if lt IE 8]>
  	<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
  <![endif]-->

  <div id="snow"></div>

  <div class="snowflakes" aria-hidden="true">
  <div class="snowflake">
  	<img src="http://secretsanta.kcfeatures.com/img/snowflake.png">
  </div>
  <div class="snowflake">
  	<img src="http://secretsanta.kcfeatures.com/img/snowflake.png">
  </div>
  <div class="snowflake">
  	<img src="http://secretsanta.kcfeatures.com/img/snowflake.png">
  </div>
  <div class="snowflake">
  	<img src="http://secretsanta.kcfeatures.com/img/snowflake.png">
  </div>
  <div class="snowflake">
  	<img src="http://secretsanta.kcfeatures.com/img/snowflake.png">
  </div>
  <div class="snowflake">
  	<img src="http://secretsanta.kcfeatures.com/img/snowflake.png">
  </div>
  <div class="snowflake">
  	<img src="http://secretsanta.kcfeatures.com/img/snowflake.png">
  </div>
  <div class="snowflake">
  	<img src="http://secretsanta.kcfeatures.com/img/snowflake.png">
  </div>
  <div class="snowflake">
  	<img src="http://secretsanta.kcfeatures.com/img/snowflake.png">
  </div>
  <div class="snowflake">
  	<img src="http://secretsanta.kcfeatures.com/img/snowflake.png">
  </div>
</div>

	<div class="container">

		<img src="http://secretsanta.kcfeatures.com/img/santahat.svg" class="santahat">
		
		<div class="instructions">
			<h1>Secret Santa Sign Up!</h1>
			<p>Enter in the names and contact information for the people participating in your Secret Santa. When you click submit each person will receive an email with the name of who they are a Secret Santa for!</p>
		</div>

	  <form class="secretSantaForm">

		  <div id="sections">
		    <div class="section">
		      <fieldset>
		        <h3>Participant</h3>

            <input class="nameInput" name="name0" id="name0" type="text" placeholder="Name"  />
            <input class="emailInput" name="email0" id="email0" type="email" placeholder="Email"  />
						
						<div class="buttonContainer">
		        	<a href="#" class="remove button">Remove Participant</a>
		        </div>

		      </fieldset>
		    </div>
		  </div>

		  <div class="buttonContainer">
			  <button class="addsection button">Add Participant</button>
			  <button class="button submitBtn" type="submit">Pair up!</button>
		  </div>

		  <div class="results">
			  <h3>Results</h3>
			  <p>Participants that emails were successfully sent to will be displayed here in a few moments.</p>
			  <div class="results-display"></div>
			  <div class="buttonContainer">
        	<a href="#" class="button" onClick="window.location.reload()">Reset Form</a>
        </div>
			</div>

	  </form>
  </div>


  <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
  <script src="dist/js/scripts.js"></script>

  </body>

  </html>
              
            
!

CSS

              
                /* ====================================================
	 General Styles
	 ==================================================== */
body {
  font-family: "Josefin Sans", sans-serif;
  background-color: #6B92B9;
  color: #f9f9f9;
  padding: 20px;
}

h1, h2, h3, h4, h5, h6 {
  font-family: "Lobster Two", cursive;
}

.container {
  max-width: 500px;
  margin: 80px auto 0;
  padding: 30px;
  border-radius: 15px;
  background-color: #D62822;
  -webkit-box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.7);
  -moz-box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.7);
  box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.7);
  z-index: 10;
  position: relative;
}

/* customizable snowflake styling */
.snowflake {
  color: #fff;
  font-size: 1em;
  font-family: Arial;
  text-shadow: 0 0 1px #000;
}

@-webkit-keyframes snowflakes-fall {
  0% {
    top: -10%;
  }
  100% {
    top: 100%;
  }
}

@-webkit-keyframes snowflakes-shake {
  0% {
    -webkit-transform: translateX(0px);
    transform: translateX(0px);
  }
  50% {
    -webkit-transform: translateX(80px);
    transform: translateX(80px);
  }
  100% {
    -webkit-transform: translateX(0px);
    transform: translateX(0px);
  }
}

@keyframes snowflakes-fall {
  0% {
    top: -10%;
  }
  100% {
    top: 100%;
  }
}

@keyframes snowflakes-shake {
  0% {
    transform: translateX(0px);
  }
  50% {
    transform: translateX(80px);
  }
  100% {
    transform: translateX(0px);
  }
}

.snowflake {
  position: fixed;
  top: -10%;
  z-index: -1;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  cursor: default;
  -webkit-animation-name: snowflakes-fall,snowflakes-shake;
  -webkit-animation-duration: 10s,3s;
  -webkit-animation-timing-function: linear,ease-in-out;
  -webkit-animation-iteration-count: infinite,infinite;
  -webkit-animation-play-state: running,running;
  animation-name: snowflakes-fall,snowflakes-shake;
  animation-duration: 10s,3s;
  animation-timing-function: linear,ease-in-out;
  animation-iteration-count: infinite,infinite;
  animation-play-state: running,running;
}

.snowflake:nth-of-type(0) {
  left: 1%;
  -webkit-animation-delay: 0s,0s;
  animation-delay: 0s,0s;
}

.snowflake:nth-of-type(1) {
  left: 10%;
  -webkit-animation-delay: 1s,1s;
  animation-delay: 1s,1s;
}

.snowflake:nth-of-type(2) {
  left: 20%;
  -webkit-animation-delay: 6s,.5s;
  animation-delay: 6s,.5s;
}

.snowflake:nth-of-type(3) {
  left: 30%;
  -webkit-animation-delay: 4s,2s;
  animation-delay: 4s,2s;
}

.snowflake:nth-of-type(4) {
  left: 40%;
  -webkit-animation-delay: 2s,2s;
  animation-delay: 2s,2s;
}

.snowflake:nth-of-type(5) {
  left: 50%;
  -webkit-animation-delay: 8s,3s;
  animation-delay: 8s,3s;
}

.snowflake:nth-of-type(6) {
  left: 60%;
  -webkit-animation-delay: 6s,2s;
  animation-delay: 6s,2s;
}

.snowflake:nth-of-type(7) {
  left: 70%;
  -webkit-animation-delay: 2.5s,1s;
  animation-delay: 2.5s,1s;
}

.snowflake:nth-of-type(8) {
  left: 80%;
  -webkit-animation-delay: 1s,0s;
  animation-delay: 1s,0s;
}

.snowflake:nth-of-type(9) {
  left: 90%;
  -webkit-animation-delay: 3s,1.5s;
  animation-delay: 3s,1.5s;
}

.santahat {
  width: 150px;
  top: -85px;
  right: -25px;
  transform: rotate(25deg);
  position: absolute;
}

@media (min-width: 780px) {
  .santahat {
    width: 220px;
    top: -75px;
    left: -105px;
    transform: rotate(-20deg);
  }
}

/* ====================================================
	 Instructions Styles
	 ==================================================== */
.instructions {
  text-align: center;
}

.instructions h1 {
  margin-top: 0;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.4);
}

/* ====================================================
	 Form Styles
	 ==================================================== */
.secretSantaForm input[type="text"],
.secretSantaForm input[type="date"],
.secretSantaForm input[type="datetime"],
.secretSantaForm input[type="email"],
.secretSantaForm input[type="number"],
.secretSantaForm input[type="search"],
.secretSantaForm input[type="time"],
.secretSantaForm input[type="url"],
.secretSantaForm input[type="password"],
.secretSantaForm textarea,
.secretSantaForm select {
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  outline: none;
  display: block;
  width: 100%;
  padding: 3px;
  border: none;
  border-radius: 0;
  border-bottom: 1px solid #f9f9f9;
  background: transparent;
  margin-bottom: 10px;
  height: 40px;
  color: #f9f9f9;
}

.secretSantaForm textarea {
  resize: none;
  overflow: hidden;
}

.secretSantaForm fieldset {
  border: 0;
  border-radius: 5px;
  border-left: solid 5px #f9f9f9;
  background-color: rgba(255, 255, 255, 0.1);
  margin-bottom: 20px;
}

.secretSantaForm fieldset h3 {
  margin: 10px 0;
}

.secretSantaForm fieldset .button {
  padding: 11px 29px 10px;
  font-size: 1em;
  margin-top: 5px;
  width: 100%;
  display: block;
  box-sizing: border-box;
  margin: 20px 0 5px;
}

.buttonContainer {
  text-align: center;
}

.button {
  border-style: solid;
  border-width: 0px 0px 3px;
  box-shadow: 0 -1px 0 rgba(255, 255, 255, 0.1) inset;
  color: #f9f9f9;
  border-radius: 6px;
  cursor: pointer;
  display: inline-block;
  overflow: hidden;
  text-align: center;
  text-decoration: none;
  text-overflow: ellipsis;
  transition: all 200ms ease-in-out 0s;
  white-space: nowrap;
  padding: 11px 29px 10px;
  background-color: #97D6A6;
  border-color: #468263;
  margin: 10px;
  font-size: 1.2em;
  font-family: "Lobster Two", cursive;
}

.button:hover {
  background-color: #468263;
  border-color: rgba(0, 0, 0, 0.5);
}

/* ====================================================
	 Results Styles
	 ==================================================== */
.results {
  display: none;
  margin-top: 20px;
  border-radius: 5px;
  border-left: solid 5px #f9f9f9;
  background-color: rgba(255, 255, 255, 0.1);
  padding: 20px 10px 10px;
}

.results h3 {
  margin: 0 0 10px;
}

.results p {
  margin: 10px 0 0;
}

.results .button {
  padding: 11px 29px 10px;
  font-size: 1em;
  margin-top: 5px;
  width: 100%;
  display: block;
  box-sizing: border-box;
  margin: 20px 0 5px;
}

              
            
!

JS

              
                // Define template variable. 
// This will contain the html required to create new participants
var template = $('#sections .section:first').clone();

var sectionsCount = 0;

// When user clicks .addsection button, adds new participant
$('body').on('click', '.addsection', function() {

  sectionsCount++;

  // Loop through each input
  var section = template.clone().find(':input').each(function(){
    var newId = this.id.slice(0, -1) + sectionsCount;
    this.id = newId;
    $(this).attr('name', newId);
	}).end()
  .appendTo('#sections');
  return false;
});

// When user clicks .remove button, removes that participant
$('#sections').on('click', '.remove', function() {
  $(this).parent().parent().fadeOut(300, function(){
    $(this).parent().empty();
    return false;
  });
  return false;
});

// Main function for Secret Santa web app
// Stores data from form in array and uses that data to pair participants
function secretSantaFormSubmit(event) {

	event.preventDefault();

	$(submitBtn).text("Pairing...");
	$(secretSantaForm).find(".results").css("display", "block");

	var participants = [];

	// Create an array for each participant within the participants array
	// Ends up with a 2 dimensional array
	$(secretSantaForm).find(".section").each(function() {
		var participant = [
			$(this).find(".nameInput").val(),
			$(this).find(".emailInput").val()
		];
		participants.push(participant);
	});

	participants = shuffle(participants);

	participants.forEach(matchParticipants);

	participants.forEach(emailParticipants);  
};


/**
 * Function that will randomly shuffle an array. 
 * Fisher-Yates (aka Knuth) Shuffle
 * http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
 */
function shuffle(array) {
	var currentIndex = array.length, temporaryValue, randomIndex;

	// While there remain elements to shuffle...
	while (0 !== currentIndex) {

		// Pick a remaining element...
		randomIndex = Math.floor(Math.random() * currentIndex);
		currentIndex -= 1;

		// And swap it with the current element.
		temporaryValue = array[currentIndex];
		array[currentIndex] = array[randomIndex];
		array[randomIndex] = temporaryValue;
	}
	return array;
};

// Function to match participants with recipients 
// Matches current participant in array with the next participant in array
// Unless they are the last, in which case matches them with the first participant in array
function matchParticipants (participant, index, array) {
	if (index === array.length - 1) {
		participant.push(array[0][0]);
	} else {
		participant.push(array[index + 1][0]);			
	}
};

// Function that uses emailjs API to send notification emails to secret santas
function emailParticipants (participant, index, array) {
	emailjs.send("default_service","secret_santa",{
		santa: array[index][0],
		email: array[index][1],
		giftie: array[index][2]
	})
		// After sending email perform this function if succeeds
		.then(function(response) {
			console.log(array[index][0] + ": SUCCESS", response);
			$(resultsDisplay).append("<p>Successfully sent to: " + array[index][0] + "</p>");

			if (index === array.length - 1) {
				$(submitBtn).text("Pair up!");
			}
		}, 
		// If there is an error, alert it to user
		function(err) {
			$(resultsDisplay).append("<p>Uh oh! Unable to send email to: " + array[index][0] + "<br>Error: " + JSON.stringify(err) + "</p>");
			console.log("FAILED", err);
			if (index === array.length - 1) {
				$(submitBtn).text("Pair up!");
			}
		});
};

// Store elements that are used multiple times in functions as variables
var secretSantaForm = document.getElementsByClassName('secretSantaForm')[0];
var resultsDisplay = document.getElementsByClassName('results-display')[0];
var submitBtn = document.getElementsByClassName('submitBtn')[0];

// Trigger secretSantaFormSubmit function when form is submitted
secretSantaForm.addEventListener('submit', secretSantaFormSubmit);



              
            
!
999px

Console