Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bkrieger committed Sep 12, 2012
0 parents commit 3272fce
Show file tree
Hide file tree
Showing 11 changed files with 1,711 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
chrome-ex-pennapps
==================

[PennApps Tech Talk] Chrome Extension
24 changes: 24 additions & 0 deletions contacts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<script src='js/jquery.js'></script>
<script src='js/handlebars.js'></script>
<script src='js/templates.js'></script>
<script src='js/contacts.js'></script>
<script src='js/text.js'></script>
<link rel='stylesheet' href='css/style.css' />
</head>
<body>
<div id='container'>
<form class='contact-form'>
<input type='text' id='name' placeholder='Name' />
<input type='text' id='number' placeholder='Number' />
<input type='submit' id='save' />
</form>

<div id='contacts'>

</div>
</div>
</body>
</html>
13 changes: 13 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#container {
width: 330px;
}
#name {
width: 80px;
}
#number {
width: 130px;
}
#contacts {
max-height: 500px;
overflow: scroll;
}
Binary file added img/contacts.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions js/contacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
$(document).ready(function() {

//Save a contact to localStorage
function save(name,number) {
var data = localStorage["contacts"];
var contacts = JSON.parse(data);
contacts[name] = number;
localStorage["contacts"] = JSON.stringify(contacts);
}

//shows a single contact
function addOne(name,number) {
//To do this we had to install handlebars from npm
//Need handlebars.js
//Make file contact.handlebars
//Then fill in contact.handlebars file with the template we want
//Run "handlebars templates/contact.handlebars -f js/templates.js" whenever we change contact.handlebars

var template = Handlebars.templates.contact;
var contact_html = template({name: name, number: number});
$("#contacts").prepend(contact_html);
$(".text-form").hide();
}

//shows all contacts
function render() {
var data = localStorage["contacts"];
var contacts = JSON.parse(data);
for (var name in contacts) {
addOne(name, contacts[name]);
}
}

//Define what happens when we click submit
$(".contact-form").on("submit", function(e) {
//e.preventDefault(); //prevents form from resetting on submit
var name = $("#name").val();
var number = $("#number").val();
save(name,number);
addOne(name,number);
console.log(name+ " " + number);
});

//if localStorage of "contacts" is empty
if(!localStorage["contacts"]) {
localStorage["contacts"] = "{}";
}
render();
});
Loading

0 comments on commit 3272fce

Please sign in to comment.