From ccda8f88064f3e930a1b0e91d9ddda4dd3189a4a Mon Sep 17 00:00:00 2001 From: coreyshuman Date: Tue, 16 Feb 2016 20:42:18 -0800 Subject: [PATCH 1/4] Made some cool changes to final project --- Final Project/Corey's Todo App/css/styles.css | 4 ++ Final Project/Corey's Todo App/js/scripts.js | 56 ++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/Final Project/Corey's Todo App/css/styles.css b/Final Project/Corey's Todo App/css/styles.css index 71c6edb..88a1cb0 100644 --- a/Final Project/Corey's Todo App/css/styles.css +++ b/Final Project/Corey's Todo App/css/styles.css @@ -87,4 +87,8 @@ ol ol { a:hover .ListControls { opacity: 1; +} + +.selectLite { + border: solid .15em aqua; } \ No newline at end of file diff --git a/Final Project/Corey's Todo App/js/scripts.js b/Final Project/Corey's Todo App/js/scripts.js index f5c606d..007de9c 100644 --- a/Final Project/Corey's Todo App/js/scripts.js +++ b/Final Project/Corey's Todo App/js/scripts.js @@ -8,6 +8,8 @@ var listArray = []; var itemId = 1; + var editing = false; + var curItem = null; $(function() { var newItemButton = document.getElementById("NewItemButton"); @@ -115,9 +117,26 @@ printList(); break; } + } else if(target.hasAttribute("rel")) { + selectItem(target); + } } + function selectItem(ref) { + clearSelect(); + ref.setAttribute("class", "selectLite"); + curItem = ref; + } + + function clearSelect() { + var items = document.querySelectorAll("ol li a"); + for(var i = 0; i < items.length; i++) { + items[i].removeAttribute("class"); + } + curItem = null; + } + function printList() { listNode.innerHTML = ""; listArray.forEach(function(item) { @@ -129,9 +148,11 @@ function showEditWindow(show) { var wnd = document.getElementById("EditWindowDiv"); if(show) { + editing = true; wnd.style.display = "block"; itemInput.focus(); } else { + editing = false; wnd.style.display = "none"; } } @@ -169,13 +190,46 @@ // handle enter and escape keys document.onkeydown = function keyCheck(e) { var KeyID = (window.event) ? event.keyCode : e.keyCode; - + console.log(KeyID) switch(KeyID) { case 13: // [enter] handleEditClick(); break; case 27: // [esc] showEditWindow(false); + clearSelect(); + break; + case 78: // new (n) + if(!editing) { + showEditWindow(true); + e.preventDefault() + } + break; + case 69: // edit (e) + if(!editing && curItem !== null) { + var itemId = curItem.getAttribute("rel"); + itemId = parseInt(itemId); + setupEditAction(itemId); + e.preventDefault(); + } + break; + case 68: // delete (d) + if(!editing && curItem !== null) { + var itemId = curItem.getAttribute("rel"); + itemId = parseInt(itemId); + if(confirm("Are you sure you want to delete?")) { + deleteItem(itemId); + printList(); + } + } + break; + case 70: // mark (f) + if(!editing && curItem !== null) { + var itemId = curItem.getAttribute("rel"); + itemId = parseInt(itemId); + markItem(itemId); + printList(); + } break; } From 2c737a4cb88f8b1d91ce1faabfa53dbb92d0804b Mon Sep 17 00:00:00 2001 From: coreyshuman Date: Mon, 14 Mar 2016 20:03:34 -0700 Subject: [PATCH 2/4] improved rps script comments --- Day 7/RPS/js/scripts.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Day 7/RPS/js/scripts.js b/Day 7/RPS/js/scripts.js index e996c2d..9b585a8 100644 --- a/Day 7/RPS/js/scripts.js +++ b/Day 7/RPS/js/scripts.js @@ -1,22 +1,20 @@ -/* JavaScript Test Code Template +/* JavaScript Rock Paper Scissors Game Corey Shuman - 11/4/15 + 3/14/16 - This files contains some shortcut functions - to manipulate the values for two input textboxes. - It also sets up an event handler to handle - button clicks on the page. */ -// USER CODE - Put your code here! +// create global variables to store game and win count var gameCount = 0; var winCount = 0; // This function is called every time the button is clicked function handleGoButtonClick(event) { + // get user value that they typed into input 1 var user = domInput1().toLowerCase(); var computer; var result; + // use a random number to pick what the computer plays switch(Math.ceil(Math.random()*3)) { case 1: computer = 'rock'; @@ -29,13 +27,17 @@ function handleGoButtonClick(event) { break; } + // clear the input box domInput1(""); + // validate the user input if(user !== 'rock' && user !== 'paper' && user !== 'scissors') { result = "Invalid Input"; domTextOutput(result); return; } + // game logic + // string stored in 'result' will be sent to page result = "You choose " + user; result += "
Computer chooses " + computer + "
"; gameCount++; @@ -60,6 +62,7 @@ function handleGoButtonClick(event) { result += "
You have played " + gameCount + " games."; result += "
You have won " + winCount + " games."; + // output text to the page domTextOutput(result); } From 46665c1708e34a4429471c747b2f09f890c8f464 Mon Sep 17 00:00:00 2001 From: coreyshuman Date: Wed, 23 Mar 2016 20:42:56 -0700 Subject: [PATCH 3/4] Added complete movie list app --- Day 10/MovieListApp/app.js | 72 +++++++++++++++++++++++++++++++ Day 10/MovieListApp/movieapp.html | 30 +++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 Day 10/MovieListApp/app.js create mode 100644 Day 10/MovieListApp/movieapp.html diff --git a/Day 10/MovieListApp/app.js b/Day 10/MovieListApp/app.js new file mode 100644 index 0000000..1d7916f --- /dev/null +++ b/Day 10/MovieListApp/app.js @@ -0,0 +1,72 @@ +// Movie List App +// Corey Shuman +// 3/23/16 +"use strict"; + + +var div = document.getElementById("movieListDiv"); + +var movieObjs = [ + {title: "Star Wars", release: 1977, genre: "sci-fi"}, + {title: "Inception", release: 2010, genre: "sci-fi"}, + {title: "The Matrix", release: 1999, genre: "sci-fi"} +]; + +function printMovieList() { + div.innerHTML = ""; + for (var i = 0; i < movieObjs.length; i++) { + var movie = movieObjs[i]; + var a = document.createElement("p"); + a.textContent = movie.title + " - " + movie.genre; + a.setAttribute("rel", movie.release); + a.setAttribute("style", "color:#009933;"); + a.addEventListener("click", function () { + alert(this.getAttribute("rel")); + }); + + div.appendChild(a); + } +} + +var form = document.getElementById("newMovieForm"); + + + +form.addEventListener("submit", function (evt) { + var movie = document.getElementById("movieTitle").value; + var release = document.getElementById("movieRelease").value; + var genre = getGenre(); + //alert(movie); + evt.preventDefault(); + //console.log(evt); + var newMovieObj = {title: movie, release: release, genre: genre}; + movieObjs.push(newMovieObj); + printMovieList(); +}); + +var genreInputs = document.getElementsByName("genre"); +console.log(genreInputs); + +function getGenre() { + var genre; + + for (var i = 0; i < genreInputs.length; i++) { + var genreInput = genreInputs[i]; + if (genreInput.checked) { + genre = genreInput.value; + } + } + + return genre; +} + + +printMovieList(); + + + + + + + + diff --git a/Day 10/MovieListApp/movieapp.html b/Day 10/MovieListApp/movieapp.html new file mode 100644 index 0000000..fc248e2 --- /dev/null +++ b/Day 10/MovieListApp/movieapp.html @@ -0,0 +1,30 @@ + + + JS1 Movie List App + + + +

Movie List App

+ +
+ + + + +
+ comedy
+ drama
+ horror
+ sci-fi
+ action
+
+ +
+ +

Movie List

+
+ + + + + \ No newline at end of file From 5338f5c2bb6255456e7de707592ecab93dcc719e Mon Sep 17 00:00:00 2001 From: coreyshuman Date: Mon, 28 Mar 2016 19:29:03 -0700 Subject: [PATCH 4/4] Added two ways to solve delete task. --- Day 11/Event Review Task/js/scripts.js | 2 +- Day 11/Event Review Task/js/scripts_array.js | 43 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Day 11/Event Review Task/js/scripts_array.js diff --git a/Day 11/Event Review Task/js/scripts.js b/Day 11/Event Review Task/js/scripts.js index e36bbd9..2fa1ea8 100644 --- a/Day 11/Event Review Task/js/scripts.js +++ b/Day 11/Event Review Task/js/scripts.js @@ -24,4 +24,4 @@ function deleteOnClick(event) { var myList = document.getElementById("myList"); myList.removeChild(event.target); } -} \ No newline at end of file +} diff --git a/Day 11/Event Review Task/js/scripts_array.js b/Day 11/Event Review Task/js/scripts_array.js new file mode 100644 index 0000000..ea11802 --- /dev/null +++ b/Day 11/Event Review Task/js/scripts_array.js @@ -0,0 +1,43 @@ +/* Day 11 Lecture Note Scripts + * Geekwise - JavaScript I + * Corey Shuman + * 11/14/15 + */ + + var myCounter = 0; // global counter + var myArray = []; // + +document.getElementById("myButton").addEventListener("click", function (evt) { + myCounter ++; + myArray.push(myCounter); + printList(); +}); + +function printList() { + var myList = document.getElementById("myList"); + myList.innerHTML = ""; + for(var i = 0; i < myArray.length; i++) + { + var item = myArray[i]; + var newItem = document.createElement("li"); + newItem.textContent = item; + myList.appendChild(newItem); + } +} + +document.getElementById("myList").addEventListener("click", deleteOnClick); + +function deleteOnClick(event) { + console.log(event); + if(event.target.nodeName.toUpperCase() === "LI") { + for(var i = 0; i < myArray.length; i++) { + var item = myArray[i]; + if(item == event.target.innerHTML) { + myArray.splice(i,1); + break; + } + } + var myList = document.getElementById("myList"); + myList.removeChild(event.target); + } +} \ No newline at end of file