Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes made JL 02102016 #2

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
$(function(){
// cache the ul that holds the list
$list = $("ul");

//Hide all items and fade them in one at a time
$("li").hide().each( function(i) {
$(this).delay(450 * i).fadeIn(1600);

});

//Update the item counter
function updateItemCount() {
var itemCount = $("li").length;
$("#counter").text(itemCount);

}

// Call the funcgtion defined above to update the initial item count
updateItemCount();

//Add ability to add a new item to the list
$("#newItemButton").show();
$("#newItemForm").hide();

$("#showForm").on("click", function() {
$("#newItemButton").hide();
$("#newItemForm").show();
});

// Build the new list item and add it when we click add
$("#add").on("click", function(e) {
// prevent the form submit from refreshing the page
e.preventDefault();

//get the text for the item to add, then build/add new li
var text = $("#itemDescription").val();
var $newItem = $("<li>" + text + "</li>");
$newItem.on("click", function() {
var $li = $(this);
completeItem($li);

})
$list.append($newItem);
$("#itemDescription").val("");

// update the counter and reset the form display
updateItemCount();
$("#newItemForm").hide();
$("#newItemButton").show();
});
// Add click handler so that we can grey out the list items as they are done
$("li").on("click", function() {
var $li = $(this);
completeItem($li);
});

// Name our click handler function so we can add it to new items
function completeItem ( $li ) {
//Need to see first if it was already complete
if ($li.hasClass("complete")) {
$li.animate({
opacity: 0.0,
paddingLeft: '+= 180'
}, 500, 'swing', function (){
$li.remove();
updateItemCount();
});
} else {
$li.addClass("complete");
$list.append($li).hide().fadeIn(300);
}
}

});