client side programming
A2/A2.docx
IT 3046 Assignment 2 Fall 2015
Total: 40 points Extra Credit: 10 points
All assignments should be individual work. Discussion with class mates is allowed but the final code has to be written individually. If you take code from any Web site, provide the links in your submission files.
All the files you need for this exercise are available on Blackboard->Course Schedule->A2.zip
Start early.
DO NOT USE jQuery or CSS to implement the programs. You can use CSS only for styling purposes. Solutions should be general enough so that if the size or content of arrays/images changes, your code will still work.
1. (10 points) In this exercise, you’ll develop an application that uses an array to manage a “To Do” list. To keep this simple, assume that you do the tasks on a FIFO basis. That is, the first task added to the list is the first one that you do, so the next task is always the first one in the list.
· Begin with the files todo_list.js and todo_list.html. Then, run the application to see the user interface shown above, although that interface won’t do anything until you develop the JavaScript for it.
· In the JavaScript include a global variable declaration for an empty array named taskList. Then, write the code for adding a task to this array when the user enters a task in the first text box and clicks the Add Task button. This code should also blank out the text box. At this point, don’t worry about displaying the tasks in the text area for the task list. Instead, use alert statements to print the array to make sure this works when you add one or more items.
· Add the JavaScript code for the click event handler (function) of the Show Next Task button. This handler should display the first task in the array in the Next task text box and remove its item from the array. To remove the first item in an array, you can use the shift method.
· In the event handler (function) for the Show Next Task button, test to make sure the array has items in it. If it doesn’t, use the alert method to display “No tasks remaining” and clear the task from the Next task text box.
· Add a JavaScript function that displays the elements in the array in the Task list text area. Then, call this function from both of the click event handlers (functions) so the updated task list is displayed each time a task is added to the list or removed from it.
· Give this application a final test to make sure it works correctly.
2. (15 points) In this exercise, you will develop an Image Rollover application. When the user moves the mouse over one of the three images, the current image is replaced by a new one.
-Begin with the files rollover.js and rollover.html. Review the HTML code, and note that the id attribute of each img tag points to the image that should replace the current image when the mouse hovers over it.
-Use JavaScript to write the onmouseenter event handler for the mouse enter event of the img tags (similar to the onclick event handler of the img tags in the ImageSwap/SlideShow applications). This handler should change the src attribute of the img tag so it points to the URL for the rollover image.
-Use Javascript to write the onmouseout event handler for the mouse out event. This handler should change the src attribute of the img tag to the original image.
3. (15 points) In this exercise, you will add some of the code you wrote for #2, analyze the program and apply your HTML/CSS knowledge from previous courses.
-Then answer the three questions in the a2.js file. You can write your answers on the file as comments.
-Improve the appearance of the Web site by using CSS/HTML.
(10 points) Extra Credit:
The pictures for #3 have been taken from this page http://www.landsend.com/shop/-/N-jri?cm_re=nav-_-outerwear-_-catagories-_-Hats-Gloves-Scarves. Find the specific page for each scarf. Your Web site should show a link to the selected scarf. For example, when the user selects the Plum Scarf, the link to the Plum Scarf page should be displayed. You can implement this in multiple ways such as using a text link, using an image link or directly clicking on the images.
Submission Upload the three folders as a single .zip file to Blackboard under Submit Assignments ->Assignment 2. Name your file as YourUsername_A2.zip e.g. If I were to upload it, it would be mutsuday_A2.zip
Test your code on a wide range of inputs. Some exercises show some sample inputs and the expected results. Use these examples as a starting point. Your file must successfully execute in order to be considered for a grade- absolutely no syntax errors. Comment out any code that does not work for partial credit.
Page 1 of 2
image1.emf
A2/image_rollover/images/h1.jpg
A2/image_rollover/images/h2.jpg
A2/image_rollover/images/h3.jpg
A2/image_rollover/images/h4.jpg
A2/image_rollover/images/h5.jpg
A2/image_rollover/images/h6.jpg
A2/image_rollover/main.css
/* the default styles for the document */ body { font-family: Arial, Helvetica, sans-serif; margin: 0 auto; padding: 20px; width: 760px; border: 3px solid blue; } h1, ul { margin: 0; padding: 0; } h1 { padding-bottom: .5em; } img { height: 175px; } /* the styles for the center content */ section { } li { padding-right: 10px; display: inline; }
A2/image_rollover/rollover.html
Image Rollovers
A2/image_rollover/rollover.js
//FUNCTION var $ = function (id) { return document.getElementById(id); } //ONLOAD EVENT HANDLER window.onload = function () { //GET IMAGE TAGS //PROCESS EACH IMAGE //1. GET IMG TAG //2. PRELOAD IMAGE FROM IMG TAG //3. ATTACH EVENT HANDLERS (onmouseover & onmouseout) TO IMG TAG }
A2/imageSwap_rollover/a2.css
/* type selectors */ article, aside, figure, figcaption, footer, header, nav, section { display: block; } body { font-family: Arial, Helvetica, sans-serif; margin: 0 auto; padding: 20px; width: 550px; border: 3px solid blue; } h1, h2, ul, p { margin: 0; padding: 0; } h1 { padding-bottom: .25em; } h2 { font-size: 120%; padding: .5em 0 .25em; } li { padding-right: 10px; display: inline; }
A2/imageSwap_rollover/a2.html
Scarf Selector
Superior cashmere-like softness Infinitely soft and warm in a substantial jacquard knit that shows its pretty pattern on both sides, so it always looks great when wrapped. The lush brushed acrylic fabric feels just like cashmere, at a fraction of the cost. A perfect scarf for snowy winter days. Available in four colors.
Ashwood
A2/imageSwap_rollover/a2.js
//FUNCTION var $ = function (id) { return document.getElementById(id); } //ONLOAD EVENT HANDLER window.onload = function () { //GET LINKS var listNode = $("image_list"); var imageLinks = listNode.getElementsByTagName("a"); //GET CAPTION var captionNode = $("caption"); //GET ENLARGED IMAGE var imageNode = $("images/ashwood2.jpg"); /**** 1.Explain why we had to add the following two event handlers here ****/ imageNode.onmouseover = function(evt) { /****Add mouseover code from rollover.js here****/ } imageNode.onmouseout = function(evt) { /****Add mouseout code from rollover.js here****/ } var i, imgLink, image; //PROCESS EACH IMAGE for ( i = 0; i < imageLinks.length; i++ ) { //1. GET LINK imgLink = imageLinks[i]; //2. PRELOAD IMAGE image = new Image(); image.src = imgLink.getAttribute("href"); //3. ATTACH EVENT HANDLER TO LINK imgLink.onclick = function (evt) { //a.GET CLICKED LINK var link = this; //b.CHANGE ENLARGED IMAGE'S SRC/ID TO CLICKED LINK imageNode.src = link.getAttribute("href"); /******The following line has been commented out. Run the program and see what happens. Then uncomment the line and see what happens. 2. What does the following line do? 3. Why is it important to include this line here? *******/ //imageNode.id = "images/" + link.getAttribute("id"); //c.CHANGE THE CAPTION TO CLICKED LINK'S TITLE captionNode.firstChild.nodeValue = link.getAttribute("title"); //d.CANCEL DEFAULT ACTION OF EVENT if (!evt) { evt1 = window.event; evt1.returnValue = false; } if (evt) { evt.preventDefault(); } }//end onclick }//end for loop }//end onload
A2/imageSwap_rollover/images/ashwood1.jpg
A2/imageSwap_rollover/images/ashwood2.jpg
A2/imageSwap_rollover/images/black1.jpg
A2/imageSwap_rollover/images/black2.jpg
A2/imageSwap_rollover/images/deep_pine1.jpg
A2/imageSwap_rollover/images/deep_pine2.jpg
A2/imageSwap_rollover/images/plum1.jpg
A2/imageSwap_rollover/images/plum2.jpg
A2/imageSwap_rollover/thumbnails/ashwood.jpg
A2/imageSwap_rollover/thumbnails/black.jpg
A2/imageSwap_rollover/thumbnails/deep_pine.jpg
A2/imageSwap_rollover/thumbnails/plum.jpg
A2/to_do_list/todo_list.css
body { font-family: Arial, Helvetica, sans-serif; background-color: white; margin: 0 auto; width: 600px; border: 3px solid blue; } h1 { color: blue; } section { padding: 0 2em 1em; } label { float: left; width: 5em; text-align: right; padding-bottom: .5em; } input[type="text"] { width: 20em; margin-left: 1em; margin-bottom: .5em; } textarea { height: 10em; width: 20em; margin-left: 1em; margin-bottom: .5em; }
A2/to_do_list/todo_list.html
To Do List
Add task: Task list: Next task:A2/to_do_list/todo_list.js
//FUNCTION var $ = function (id) { return document.getElementById(id); } //ONLOAD EVENT HANDLER window.onload = function () { }