COURSE CALENDAR | WEEK 12 CLASS OUTLINE | Homework |
Topics covered in class:
- AD650 Learning Forum: New Technique presentation
- REVIEW Student Portfolio Client Sites: Today your site should be functional (all pages in the site are accessible through global and/or local navigation links) and structured (all pages in the site should have a template page applied with the developed stylesheet).
- Best Practices: Using
JavaScript for good, not evil
- Graceful Degradation: ensuring your sites work without Javascript. Functionality may be reduced, but it does not fail completely. Search engines do not understand JavaScript.
- Always ask: "How will this benefit the users?" and "What if a user doesn't have JavaScript?"
- BAD implementations of JavaScript are bad for usability. A page that needs JavaScript for accessing navigation and content in not accessible to all users.
- BAD Example #1: Pseudo-protocol
- BAD Example #2: Inline Event handlers using "#" symbol
- Better Example: Inline Event handler with real URL
- Progressive Enhancement, which means separating Presentation and Behavior from Structure, almost always degrades gracefully.
- Unobtrusive JavaScript: completely separating Behavior
from Structure
- In the same way we keep all presentation out of our HTML structure, we need to completely separate the JavaScript from the HTML by removing all inline event handlers and using a hook, like an ID or Class, to target an element and execute the function.
- To target multiple elements with a Class, use getElementsByTagName and getAttribute
- Since the document loads within the browser window, the Document Object is a property of the Window Object. Use the onload function to trigger the DOM and execute the script as the page loads. Without it the JavaScript file will load and execute before the document loads.
- To attach an event handler to an element with an ID:
getElementById(id).event = action- Example with ID and onload
- Backwards Compatibility: making sure older browsers
don't choke on your script
- Most browsers have some support JavaScript and most modern browsers understand the DOM, but not all older browsers understand DOM methods and properties.
- Test the browser using object detection to determine whether or not the browser understands a particular method. If the browser doesn't then the statement returns false.
- Use the if statement to wrap the method and the not operator to evaluate either true or false. If the browser understands the method the rest of the script will execute, if not, the value will return false.
- Updating the Image Gallery with BEST PRACTICES
- Review our showPic script.
- Does the Javascript degrade gracefully? YES
- Is the Javascript unobtrusive? NO
- Add a hook (ID or CLASS) to an element in the HTML (diagram)
- Remove the inline event handler (diagram)
- Write a function that adds the event handler to the Javascript and creates checkpoints for browsers that don't understand the DOM. (diagram)
- Use the addLoadEvent function to make sure the document has finished loading before the javascript executes. This function is like the onload function, but it allows for multiple functions to load when the page loads. (diagram)
- Does the showPic function have the necessary checks? NO
- This function never checks to see if "placeholder" and "description" exist.
- If the placeholder exists, but the description element doesn't we still want the image to swap.
- Add checks for "placeholder" and "description". (diagram)
- What if the placeholder image is missing? The script doesn't execute and we have cancelled our default action in the prepareGallery function. We no longer have graceful degradation.
- The problem is in the prepareGallery function. It cancels the default action. Modify the showPic function so that if the placeholder does NOT exist the showPic function should return true, instead of false (keeping the default link action). (diagram)
- We need to remove the return false (canceling the default link action) from the prepareGallery function and tell it to use the returned showPic value instead. (diagram)
- Extra Checks and onkeypress Accessibility
- Use showPic function to check for title attribute and set value of text to empty
- Also check to see if "placeholder" is an img using the nodeName property.
- Caution: the use of onkeypress is not always accessible. Some browsers trigger the onkeypress event way any key is pressed. The onlick event handler is also triggered when hitting the return key.
- The final script.
- Replacing text links with images
- Prepare for a JavaScript quiz.
- Client Site Work:
Make sure you are on track with your Milestone Schedule
- Phase 1: Site Definition
- Phase 2: Developing Site Structure
- Phase 3: Interface Design & Production
- The Design Process
- Protosite Development
- Art Optimization/Production
- Phase 4: Technical Engineering
- HTML Production/Layout
- Beta Launch/QA Testing -- WE ARE HERE!!!
- Phase 5: Publishing/Marketing/Launch
- Maintenance Schedule/Updating
- Domain and hosting setup
- Search Engine Submissions
- HTML Style Guide