About Onno

Writing book For A future, almost finished

6 & 13 Peer Review

Peer review is an important life skill. Do it effectively and with tact.

Constructive Criticism

Be positive, let your partner know what you liked. Praise, comment, and correct in that order. Make positive comments about the design, its execution and overall effectiveness of the site before explaining what does not meet with expectations. Look at the code to see if it is properly annotated, well organized and correct. If you can help the person achieve their goals, do that.

Critical Review Examples

Detailed critical review feedback can be found on Web Standards Sherpa, a website dedicated to constructive criticism, to highlight standards compliant solution that solve real world problems. You can see articles that review the headlines of the New York Times and there are many others, including a critique of their own site.

The goal of WebStandardsSherpa.com is to provide web professionals the opportunity to receive feedback, glean advice and learn best practices from experts in the field to help improve the quality of their own work. It’s very instructive to see professional and pedagogically useful critique at work.

Reacting to Criticism

You do not have to incorporate your classmate’s suggestions. Trust your own judgement about your design, determine which issues are most important, though pay attention to comments if they are made by more than one peer, and get another opinion if you aren’t sure about something.

User Testing

One way to get feedback is to user test your site. You will use the SilverBack application to record the user test. Download the application, which is free for 30 days.

Doing a user test is straight forward. Create a project, and create a session which will record the your peer review partner’s “user interaction” as they go through your website. When you are finished, export the files at 50% size and low resolution, which is still acceptable, and reduces the file size to around 4mb/minute.

Take notes as your peer review partner “user tests” your site. If you are doing the user testing, try to verbalize your reaction and decision making as you go through the site to make it easier for the site’s owner to note how the site user experience works, or what does not work.

Watch the video of your partner going through your site. I do not see these taking more than a minute or two, which can easily be compressed and emailed to me, or posted on your site. If you go over two minutes, you can place it on your server with a link so I can download it.

The user testing experience will not be under ideal and pristine conditions. Ideally, a user test is done the first time a user uses the site. That may not be possible at school. Set up Silverback as the first thing and do a user test with as few preconceived expectations as possible before revealing anything about your site except who its target audience is and what you are selling.

Though this is not a pristine user experience test — the video isn’t representative of an industry standard user test — it will be a good lesson in highlighting the role of testing user interactivity nonetheless.

Tasks your peer review partner should perform.

  1. Find the product/service/idea that is being sold on the site.
  2. Find out additional information about the product/service/idea.
  3. Contact the seller with a question.
  4. Check the entire site to for completeness.

Here is an example. To see it at full resolution, right -click to open the video in its own window:

Peer Review Check Lists

Two lists of questions. The first is a core list every review has to cover. Be constructive, not just “yes” or “no”. Everyone should go through the second list before handing in your final web site or publishing it on the web. I will use the same lists to check to see if you’ve dotted your “i”s and crossed your “t”s, so to speak.

Don’t worry about browser compatibility. That is included because it is a criteria the real world uses, but note that it is no longer of much consequence, as IE 6-8 usage is below 10%.

You use of the HTML5 boilerplate should make your site work for even the most prehistoric browsers, though they will miss the CSS3 goodness.

These lists are resources for you to ask pertinent questions. Use them to help formulate your critique. They are meant to be helpful to you and your partner.

I will use these lists as my measure for evaluating how well you analyzed your partner’s web site, as well as in grading your final project.

Help Your Partner

Everyone has learned a lot, but in this little time, not everyone will have learned everything equally well. You will have the opportunity of helping your partner fix at least three issues in their website where they may not have figured out the best way to do something.

We are in this all together, and being able to

Core Peer Review Questions

  • Intuitive reaction

    1. Take the five-seconds test. What’s your immediate response? Your split second intuition is often canny in its ability to present an accurate picture that can get lost in more deliberated responses.
    2. How dos the site make you feel?
  • Clarity of Communication

    1. Does the site convey a clear sense of its intended audience?
    2. Does it use language in a way that is familiar to and comfortable for its readers?
    3. Is it conversational in its tone?
    4. Is the experience seamless?
    5. Do the pictures and the design facilitate the communication?
  • Accessibility

    1. Is load time appropriate to content?
    2. Is there an easily discoverable means of communicating with the author or administrator?
    3. Is the HTML semantic (can screen readers to navigate the site)?
  • Consistency

    1. Does the site have a consistent and clearly recognizable “look-&-feel”?
    2. Does it make effective use of repeating visual themes to unify the site?
    3. Is it consistent even without graphics or external style sheet? (it can happen)
  • Navigation

    1. Are the links obvious in their intent and destination?
    2. Is there a convenient, obvious way to maneuver among related pages, and between different sections?
  • Design & maintenance

    1. Does the site make effective use of hyperlinks to tie related items together?
    2. Are there dead links? Broken scripts? Pages that are not completed or look unfinished?
    3. Is page length appropriate to site content?
  • Visual Presentation

    1. Is the site worthy of a design student in its communication?
    2. Does it use distracting animations?
    3. Does it provide feedback? Using Javascript frameworks can enhance user experience, or detract from it.
  • Code

    1. Is the code clean and well documented?
    2. Is it optimized for Search Engines (SEO)?
    3. Does it have Google’s Analytics code?
    4. Does the HTML validate? Use the Unicorn Unified Validator Service and Check the HTML and CSS. You are to report your findings in your conclusion.
  • HTML5 and CSS3 goodness

    1. List the CSS3 features used. Were they used to good effect?
    2. Explain how well the document followed a semantically correct HTML5 document structure.
    3. Is the website future proof? Do they use media queries? Does it work on the iPhone/Android?
  • Overall Assessment?

    A list of fixes, suggestions and possible solutions to any issue that came up when assessing the website using the aforementioned considerations.

    Send this report to your partner later today, if you need more time to write it up than class provides, and send a copy to me.

Detail Checklist

  1. All text free from spelling errors?
  2. Content has been placed consistently?
  3. Page & Content formatting has been tested?
  4. Meta data has been included and is appropriate?
  5. Page titles are descriptive and SEO friendly?
  6. Images have appropriate alt text?
  7. Title attributes are appropriate and SEO friendly?
  8. Favicon has been created and displays correctly?
  9. Footer includes copyright and link to site creator?
  10. HTML has passed validation?
  11. CSS has passed validation?
  12. There are no broken links?
  13. JavaScript is error free?
  14. Displays & functions correctly in ie6? 5% of market share.
  15. Displays & functions correctly in ie7? 10% of market share.
  16. Displays & functions correctly in ie8? 40% of market share.
  17. Displays & functions correctly in Firefox 4 (Mac & PC)?
  18. Displays & functions correctly in Chrome 11 (Mac & PC)?
  19. Displays & functions correctly in Safari 5 (Mac & PC)?
  20. Displays & functions correctly in Opera 11 (Mac & PC)?
  21. Tested on the iPhone?
  22. Tested at 1024 x 768 resolution?
  23. Tested at larger resolutions?
  24. Web Statistics package installed and operational?
  25. 404 page exists and informative?

13 Forms

Forms are vital tools for collecting information from users, such as their name, email address, opinions, etc. A form will take input from the user and may store that data into a file, place an order, gather user statistics, register the person or subscribe them to a newsletter.

HTML

The form itself is created in HTML, and starts with the <form>element and ends when that element closes. All the form elements are within the form element, mostly consisting of various input elements.

The input element changes according to its attributes. If there are no attributes, it provides a one line text field:

HTML Code:

<form>
	<input>
</form>

Result:


Attributes

You add the type="text" or type="submit" attributes to the <input> tag to specify if it is text or a submit button. Add a name="name" attribute to reference the form element when it is sent. The size attribute sets the width, measured in blank spaces, and the number of characters can be limited using the maxlength="" attribute.

The submit button is created by using the input tag with a type attribute set to submit. The value="Send" attribute provides the text for the button, so the value send will label the submit button as “send”. Pressing the button engages the <form> action.

There has to be a mechanism for the form to send the information it collects. The <form> element contains a method attribute method="post" that is usually set to post. It can also be set to get, which appends the form information to the URL.

The <form> also has an action attribute action="url.php", which specifies the URL the data is sent to. In this example, it is set to use the email client with the “mailto:” command.

HTML Code:

<form method="post" action="mailto:name@address.com">
	Name: <input type="text" size="30" maxlength="60" name="name"> <br />
	<input type="submit" value="Send">
</form>

Result:

Name:

Filling out your name and sending it will open up your email client, and create an email addressed to name@address.com. and the body of the email contains whatever name you’ve entered. This paring up of the name of the form element with the information entered needs to happen for each form element that gets sent.

Radio Buttons

Of the different types of input, the type=radio allows for only one choice out of a number of options. This is accomplished by using the same name for each of the options, so that only one can be chosen. Each option has its own value however, which is sent when that option is selected.

HTML Code:

<input type="radio" name="color" value="red"> Red
<input type="radio" name="color" value="green"> Green
<input type="radio" name="color" value="blue"> Blue

Result:

Additive Colors:

Red

Green

Blue

Check Boxes

Check boxes are similar to radio buttons but its possible to click on more than one option.

HTML Code:

<input type="checkbox" name="color" value="cyan"> C
<input type="checkbox" name="color" value="magenta"> M
<input type="checkbox" name="color" value="yellow"> Y
<input type="checkbox" name="color" value="black"> K

Result:

Subtractive Colors:

C

M

Y

K

Drop Down Lists

Another way to present the choices is as a drop down menu, which are especially good when there are lots of options. The drop down list is created by the <select> with each choice enclosed by an option tag.

HTML Code:

<select name="shade">
<option>white</option>
<option>light grey</option>
<option>grey</option>
<option>dark grey</option>
<option>black</option>
</select>

Result:

Shade?

HTML Text Area

All of the input fields have been single lines up to this point. The textarea provides a larger area to enter text, specified in rows and columns. A row is one line of text high while column unit is a character wide. Another setting is the wrap, which can be either virtual, which wraps the words for the person entering the text, but the text is sent without returns, or, physical, where the text is sent wrapped, just as it appears in the text area. You can also turn text wrap off.

HTML Code:

<textarea rows="5" cols="80" wrap="physical" name="comments">
Enter Comments Here:
</textarea>

Result:

Enter Comments Here:


If you enter text and press the send button, you can see that the words are concatenated (meaning added together) with plus signs and because the wrap is physical, the return is represented by the code: %0D%0A.

PHP script

Thus far the actions for all of these examples has been the “mailto:” which sent the text to the email client. Sending an email with PHP is easy enough. All you need is the PHP mail() function:

mail("recipient@domain.com", "This is the message subject", "This is the message body");

It gets more complicated when you need to connect up and receive the information, to add security measures, verify the form entry, and so on. Most hosting services have an email script that you can use, and all you need to do is send the form to that script in the action="email-script.php" attribute.

Setting Up Your Form

There are a lot of PHP email scripts on the web, and Free Contact Form is one that is simple and easy to set up. It has all the parts you need. See the demo.

  1. These instructions are for the first version of this script: Download the package.
  2. installation.txt contains basic instructions:
  3. METHOD 1 (Automated)
    1. Upload all files to your website.
    2. In your browser, open the file freecontactforminstall.php and install.
  4. METHOD 2 (Manual)
    1. Create the file ‘freecontactformsettings.php’ using a code/plain text Editor.
    2. Insert the following code into this file :
      <?php
      
      $email_to = "youremailaddress@yourdomain.com"; // your email address
      $email_subject = "Contact Form Message"; // email subject line
      $thankyou = "thankyou.htm"; // thank you page
      
      // if you update the question on the form -
      // you need to update the questions answer below
      $antispam_answer = "25";
      ?>
      
    3. Enter your email address in place of youremailaddress@yourdomain.com
    4. Change the email subject (if you like)
    5. Change your thank you page reference (if you like)
    6. Save the file.
    7. Copy ALL files onto your website using an FTP program
  5. Test it out. The thank you page has been redirected with the return button bringing you back here.


Fields marked with * are required.

Alternatives

You need not develop your own php file if you use Form Spree. This allows you to go beyond the options provided for in the php script.

Setting it up is easy and free. Here’s how: You don’t even have to register.

  1. Setup the HTML form

    Change your form’s action attribute to the action input given below. Replace “your@email.com” with your own email.

    <input type=”text” value=”http://formspree.io/your@email.com” />

  2. Submit the form and confirm your email address.

    Go to your website and submit the form once. This will send you an email asking to confirm your email address, so that no one can start sending you spam from random websites.

  3. All set, receive emails

    From now on, when someone submits that form, we’ll forward you the data as email.

HTML5 Forms

Before HTML5, forms had to be carefully vetted with JavaScript to make sure that the information the user input was fundamentally correct, like an email address actually had the form of an email address, and a URL actually had the form of a URL. With HTML5 greatly enhanced forms support, this can be taken care of by the browser. Though there are still some browser compatibility problems, the time is coming when form checking is built right in.

12 HTML5 Multimedia

Week 12
11/19

Multimedia features of HTML5. HTML5 introduces a host of new features, the most visible are sound, video and the canvas element. Activity: We will incorporate these elements into a web page. 8
Activity: In-class final Workshop #2.

Homework

1) For the class: Use audio, video or canvas to sell your final Project. 2) For the final: Create home page for the final. Read chapter 17. Due: The following week. Third Quarter Assessment: Have your Final Worksheet including all 7 steps, photoshop comp and first page ready and uploaded by Wednesday Night. So I can grade them by next Friday.

Materials

Additional materials for this unit can be found by following these links:

Goal

The goal of this unit is to:

  • To incorporate Video, Audio and the Canvas element into your website.

Outcomes

At the end of this unit, students will have:

  • Coded a video for the web and embedded it in a page.
  • Exported audio into all necessary formats and embedded it into a page
  • Set up the canvas element and is able to create basic shapes.
  • Used the illustrator plugin to incorporate vector art into a page.

Step-by-Step

20 Review homework and answer questions.
40 Demo: Canvas
10 Break
40 Demo: Audio & Video
40 Final: Progress Review

Quick Primer on Using Video

Video and canvas add a dimension of multimedia to the web experience that goes well beyond print. This should excite many of you, but it can be daunting at the same time. The language of story telling on video, tools like After Effects, Final Cut Pro and Premier and the production requirements of making the videos are another world altogether.

When it is done right, video gets people’s attention, conveys emotion and personality, and engages engages people in a way that photo and text alone can’t. It can improve the website experience, but it can also cripple it, suck up bandwidth, drive people away, and suck the energy out of what could otherwise be a good website by attracting too much of the attention.

Ask yourself, when you use video:

  • What are the goals for my video strategy?
  • What types of videos will I post?
  • Will I be concepting, shooting, editing and uploading videos?
  • How can I measure success or failure?

That said, Flash integrates well with video. Too bad that Apple threw it a monkey-wrench by not supporting it on its iPhone or iTablets.

The MetaProject exemplifies how flash integrates with video seamlessly working together.

You can, however, use Google’s swiffy to convert flash sites to HTML5, SVG, and javascript.

Problems of keeping video in the background like images. It takes a lot of room, requires a lot of bandwidth and careful planning, and the right video. Random Dance uses video on the splash page, and then uses it throughout the site.

Still, video can be difficult to integrate, so think about that as you work on your final. You need not integrate video or canvas in your final, just show me that you can do it in the homework.

News and External Resources

Subscribe to the following two magazines using (RRS): A list Apart has been a beacon for web development since the web’s earliest days with timely articles, and it still remains one of the best resources out there. Smashing Magazine is another popular web design magazines that you should be reading.

There are a zillion other resources on the web, and you need to plug in to stay up to date. As this especially exciting time shows, the best is yet to come. Plug in and keep abreast of the creative solutions that become standardized practices.

Though the time it has taken each of you to understand HTML and CSS has varied, everyone should be on board by now. The more you code, the better you become.

All of you should be reaching out to the larger web community. If I have been a cheerleader that encourages you to do that, then I can feel confident that you will fish for a lifetime.

Final Assignment Links

Updated links that I expect to be up and live as they will be graded for your final grade.

Example of landing page from several semesters ago.

    Week 2

  1. Website Analysis*

    Week 3

  2. landing page— links to your assignments and a picture next to your name.
  3. HTML markup of Analysis
  4. Worksheet: behind the scenes on creative process for midterm (7 steps)*:

    Week 4

  5. Portfolio exhibiting the CSS selections
  6. HTML Wire Frame from PhotoShop comp

    Week 5

  7. incorporate CSS Layout Strategies in web site

    Week 6

  8. Quiz
  9. Peer Review Notes / Advice

    Week 7

  10. Typography Poster
  11. Finished Midterm: Portfolio

    Week 8

  12. Final Worksheet*

    Week 9

  13. Responsive Redesign of Portfolio

    Week 10

  14. CSS3 Collateral
  15. Class Exercise

    Week 11

  16. CSS3 Animatics
  17. Class Exercise

    Week 12

  18. Final: Modular Navigation

    Week 13

  19. Multimedia Demonstration

    Week 14

  20. Forms
  21. Peer Review Notes / Advice

    Week 15

  22. Final — You have 5 days extra to hand it in before I determine my final grade

Each assignment exhibits a skill. If you have used that skill in building your portfolio, link to that page and explain how it satisfies the homework. For example, for Week 11 CSS Animatics, if you used a hover that fades in your final, point to the page that exhibits that feature and let me know where to look if it is not completely obvious.

The final website sells something. It does not have to be lots of pages, but the quality has to be ready for public scrutiny. It should have many of the topics we covered, like CSS3, Multimedia, PHP, forms, media queries, etc.

Definitions

These are the terms that participants should be familiar with during this unit:

Codec

A codec is a device or computer program capable of encoding and/or decoding a digital data stream or signal. The word codec is a portmanteau of ‘compressor-decompressor’ or, more commonly, ‘coder-decoder’. A codec (the program) should not be confused with a coding or compression format or standard – a format is a document (the standard), a way of storing data, while a codec is a program (an implementation) which can read or write such files. In practice “codec” is sometimes used loosely to refer to formats, however.

A codec encodes a data stream or signal for transmission, storage or encryption, or decodes it for playback or editing. Codecs are used in videoconferencing, streaming media and video editing applications. A video camera’s analog-to-digital converter (ADC) converts its analog signals into digital signals, which are then passed through a video compressor for digital transmission or storage. A receiving device then runs the signal through a video decompressor, then a digital-to-analog converter (DAC) for analog display. The term codec is also used as a generic name for a video conferencing unit.

12 Homework

Homework for the Final

  1. Finish your website.
  2. Test it.

Homework for the Unit

  1. Create a page featuring multimedia, including canvas and video.
  2. Ideally, you are able to incorporate canvas and video in the final, but the final does not have to include multimedia.
  3. A link to the multimedia page has to be on the work-sheet.

11 Canvas

The canvas element was originally developed by Apple for OSX as a way to encourage easy customization of dashboard widgets. It utilized Apple’s HTML rendering engine called webkit to create 2D graphics at around the same time as the WHATWG (Web Hypertext Application Technology Working Group) came together to create what would become HTML5. Apple, of course, played a central role in the creation of HTML5, and the technology was adopted by other the browser vendors.

What Is It?

Canvas is a drawable region that uses Javascript drawing functions to create dynamically generated graphics. This is what other drawing programs do. Illustrator draws vectors using postscript to create pictures, Canvas uses javascript. A difference is that the vectors are always rasterized at screen resolution in canvas, meaning that they are turned into a bitmap.

How To Use the Canvas Element

You first have to create the canvas element, and you do that in the body of the document:

<canvas  id="canvas" height="250" width="300">
	<p>Use a browser that supports the canvas element
</canvas>

The canvas element needs to be initialized in the Javascript, which appears between the <script type="application/javascript"> and </script> tags, and that is usually done in the head of the document:


The actual instructions are written right after the canvas element has been initialized. The following examples show the instructions that draw a square and a circle.

Square

You draw on the canvas by coding the exacting steps the computer requires to draw these shapes. There is only one shape it supports natively, and that is a square. All other shapes have to be drawn path by path. Luckily, there are drawing functions that make it possible to create complex shapes.

If we take a red square as an example, you first specify the fill style and then fill the rectangle based on the given coordinates. Click the draw button and you will see this red square appear in the canvas window. If you change the values, the square will change.

Javascript Code View



var canvas=document.getElementById('theCanvas');
var context=canvas.getContext('2d');

//code for the square
context.fillStyle = "rgb(255,0,0)";
context.fillRect(50, 50, 50, 50);

Use a browser that supports the canvas element



Paths

Paths require a few more steps. You have open and close a path using the following code: beginPath() , and closePath(), though the shape automatically closes when you stroke() or fill() the path. In that case, the closing of the path can be skipped. There are path methods that draw lines, arcs, bezier and quadratic curves.

The following circle has all of its steps annotated, so show exactly how many steps it takes to create a red circle with a white fill that has a shadow, the letter P and a stroke to create a no parking sign. Copy the code and replace the code for the square in the Javascript Code View, click Draw It if you haven’t already done so, and you can play with the code, add to it, subtract, to see how it works. If you get excited, I have included many more definitions below that you can use to draw simple shapes.

context.beginPath(); //Begin drawing path
context.strokeStyle="#f00"; // sets stroke color
context.fillStyle="#fff"; //sets fill color
context.arc(175,120,100,0,Math.PI*2, true); // draws circle
context.lineWidth=40; // sets width of stroke
context.shadowOffsetX="3" // adds shadow offset x
context.shadowOffsetY="3" // adds shadow offset y
context.shadowBlur="7" // adds shadow blur
context.shadowColor="#888"// sets shadow color
context.stroke(); // draws stroked circle

//remove shadow from inside of circle
context.shadowOffsetX="0" // removes offset x
context.shadowOffsetY="0" // removes offset y
context.shadowBlur="0" // removes blur
context.fill(); // draws fill
context.closePath; // closes path

context.beginPath();  // draws P
context.lineWidth=15; // width of line
context.strokeStyle="#000"; // color of stroke
context.fillStyle="#000"; // color of fill
context.font="9em sans-serif"; // size of font
context.strokeText("P",120,190); // text stroke
context.fillText("P",120,190); // text fill
context.closePath; //  but closes path

context.beginPath();   // draws Slash
context.strokeStyle="#f00"; // sets stroke color
context.moveTo(100,50); // begin vector
context.lineTo(240,210); // end vector
context.lineWidth=25; // width of line
context.stroke(); // draw stroke
context.closePath; // not necessary but closes path

Definitions:

You can copy these definitions and paste them into the editor to create a shape. Check out the example shapes to see what definitions are required.

Styles

set the fillStyle
context.fillStyle="color"

set the strokeStyle
context.strokeStyle="color"

line widths
context.lineWidth=number

line join styles
context.lineJoin="style" (bevel, round, miter)

line end styles
context.lineCap="style" (butt, round, square)

Rectangles

draw a rectangle
context.strokeRect(left, top, width, height)

fill a rectangle
context.fillRect(left, top, width, height)

erase a rectangle
context.clearRect(left, top, width, height)

paths

begin a path
context.beginPath

complete a path
context.closePath

move the pen to a location
context.moveTo(horizontal, vertical)

draw a straight line from current pen location to a new location
context.lineTo(horizontal, vertical)

stroke the current path
context.Stroke()

fill the current path
context.fill()

Text

set the font
context.font="bold italic size font-family"

set the alignment
context.textAlign="left right center"

fill some text
context.fillText("string to fill", top, left)

stroke some text
context.strokeText("string to stroke", top, left)

Shadows

shadow color
context.shadowColor="color"

shadow horizontal offset
context.shadowOffsetX=number

shadow vertical offset
context.shadowOffsetY=number

shadow blur
context.shadowBlur=number

taken from Westciv

Simple Shapes

More code examples to paste into the Javascript Code View.

Smily Face

context.beginPath();
context.arc(75,75,50,0,Math.PI*2,true); // Outer circle
context.moveTo(110,75);
context.arc(75,75,35,0,Math.PI,false);  // Mouth (clockwise)
context.moveTo(65,65);
context.arc(60,65,5,0,Math.PI*2,true);  // Left eye
context.moveTo(95,65);
context.arc(90,65,5,0,Math.PI*2,true);  // Right eye
context.stroke();

Caution Sign

context.beginPath();   // Triangle
context.strokeStyle="#000";
context.fillStyle="#ff0";
context.moveTo(70,20);
context.lineTo(137,120);
context.lineTo(3,120);
context.lineTo(70,20);
context.lineWidth=3;
context.stroke();
context.fill();
context.closePath;

context.beginPath();   // !
context.fillStyle="#000";
context.font="5em sans-serif";
context.fillText("!", 58,108);
context.closePath;

Play Time

See if you can draw this figure using the shapes similar to the ones already drawn in the demo, or draw your own shapes. You can copy and paste the definitions, just make sure you initiate the object, give it properties, draw it and then create it, and if this seems laborious, be glad you are not a computer, who does nothing but this type of routines.

Better yet, watch someone else create a canvas based on processing, a sister visual programing language developed to teach visually oriented people programming, right before your eyes, using popcorn.

Turn Postscript Into Javascript

Drawing these primitive shapes by hand is really only for the purpose of understanding how canvas works. In its raw form it will never be a drawing tool for design students.

But that can change if someone were to write drawing software that could be translated to the canvas element. This is exactly what Mike Swanson has done. He created an Adobe Illustrator to HTML5 Canvas plugin. [Unfortunately, the plugin has not been updated, and it did not load the last time I tried it with Illustrator CC. Still, this is a good learning opportunity for you to understand how canvas works.]

This is an Illustrator plug-in that transforms Illustrator art into canvas art, allowing you use Illustrator as a front end to draw with, and the plugin will render it into Javascript code equivalent that can be rendered in the canvas element. Check out the Yellowstone Map as an example, and if you go to the website, you will see that the plugin is able to create motion graphics as well. We do not have the ability to install Illustrator plug-ins in the school’s computers, but please try this on your computer, as Illustrator is a very good front end to drawing directly on the canvas. If you follow his tutorial, you can even animate!

Illustrator

So here is an example of Illustrator art I created turned into Javascript. It takes only 5700 lines of code! To put that into perspective, the Illustrator file requires about the same number of lines using postscript to create the picture. Here is a text version of the Illustrator file, and the html source so you can see that there are an equal number of instructions.

Wrap Up

Advanced examples using the canvas element from the web:

Make Your Own Game

Step by step explanation of how to create your own game using javascript and canvas.

11 Audio & Video

HTML5 audio and video provide native playback of both audio and video by the web browsers themselves.

History

Audio and video playback was previously handled through proprietary plug-ins, originally Quicktime, RealPlayer and Microsoft’s Media player, but then Sorenson, who created the CODEC (from COmpression/DECompression) Apple was using for Quicktime, created a similar CODEC for MicroMedia’s Flash, propelling this ubiquitous plugin to become the preferred software for delivering video streaming.

Apple did not like that (it sued Sorenson to try and stop this from happening), as Flash killed Apple’s Quicktime and all the others video players (Real Player and Microsoft Media Player).

Flash became the default delivery system for video on the web. Adobe purchased MicroMedia for 3.5 billion in 2005, and inherited Apple’s wrath. This point should not be lost in the current debate between Flash and HTML5 video, which has been forced by the iPhone not playing Flash.

That battle appears to have been won by Apple. Flash is no longer considered ubiquitous. HTML5 video has taken over from Flash and its use in ads is no longer what it once was. Flash has been implemented on Android, but its performance is spotty, introduces vulnerabilities and eats up precious resources at the time of this writing. Flash is not dead, and its still good at what it does on the desktop, but its future of this ubiquitous proprietary standard has suffered a major hit.

The Quick and Easy Way to Embed Video

You can upload your video to Google’s YouTube or Vimeo, and embed it in your page. The tools to do that are provided by these video sharing sites, and the process is painless enough. Include the code to embed into your web page and these services will take care of displaying your video in the right format.

You can even tell both YouTube and Vimeo to display the video using HTML5 on your own browser, and it will do so seamlessly, and as you can see, you can style it on the fly. The media is my son Taiyo and some footage of the 2nd Ave Subway (under construction).

These sites generate the code that you put in your page, and from Youtube, it looks like this:

<iframe width="560" height="349" src="http://www.youtube.com/embed/LpOOh0fU4fk" frameborder="0" allowfullscreen>
</iframe>

Transforming the Video

It was the case that the transform properties actually transformed the videos from YouTube in real time, but Google has discontinued that, possibly having to do with the ability to finally go full screen.

Embedding your own Video and Audio

There are times when you need to display video and audio from your own server, and not rely on some other service. You can do that yourself, and it is almost as easy as displaying an image. I say almost as easy, because the issue as to what browsers can display which audio or video format requires that we need to create several version of each to satisfy all of the browsers.

Audio

HTML example of an audio with only a mp3 source file and an explanation that is supposed to show up if the browser does not recognize the audio tag:

<audio controls src="http://b.parsons.edu/~dejongo/12-fall/stuff/KillingACountry.mp3" type="audio/mpeg"> The browser you're using does not recognize the HTML5 audio tag. You can download the song here: <a href="http://b.parsons.edu/~dejongo/12-fall/stuff/KillingACountry.mp3">
link</a>.</audio>

What actually happens in Firefox is that the HTML 5 property is recognized, but the proprietary CODEC is not recognized. This means that you do not get the option to download the music, but see this instead:

what firefox displays when it cannot play a CODEC

Proprietary CODEC Problems

The mp3 audio file format is proprietary. For that reason, not all browsers support mp3 audio files. Only Safari and IE9 play this audio format. Opera or Firefox users are not able to play the mp3 format. Implementing this would require them to pay royalties. They do support the royalty free ogg format, so we need to approach this another way.

The Solution

I need to create an ogg file from the mp3 file, and serve up both files, and the browser will pick whatever one they can play. Since I have an mp3 file, I need to create the ogg or ogv file. Translating the audio file from mp3 to the ogg format can be done using Miro Video Converter, or if you want more control, Handbrake. With Miro Video Converser, drag the file to the conversion window, select Theora from the drop down menu and convert. It will create a theora.ogv file that works just fine in Firefox and Opera.

Putting both sources in the HTML5 tag allows the browser to choose the one that they can play, and the following code works in Firefox.

<audio controls>
You are not able to hear this sound because the browser you are
using is not standards compliant. You can download the song
from this <a href="http://b.parsons.edu/~dejongo/12-fall/stuff/KillingACountry.mp3">link</a>.
<source src="http://b.parsons.edu/~dejongo/12-fall/stuff/KillingACountry.mp3" type="audio/mpeg">
<source src="http://b.parsons.edu/~dejongo/12-fall/stuff/KillingACountry.ogg" type="audio/ogg">
</audio>

CSS Code View

The Video CODEC Problem

Video has the same problems as audio. Some browsers manufacturers pay royalties and can play the H.264 CODEC while others rely on a royalty free CODEC. Just like with audio, Safari and Internet Explorer can display the proprietary formats while Firefox, Opera and Chrome support royalty free formats.

There is movement toward a single open source standard. Google purchased On2 Technologies, the creators of the VP8 video codex, and combined it with Vorbis, an open source audio format, and has been giving it away, meaning that they released the code to the open source community. Google’s WebM Project is still new, and not yet supported by all browsers, but the intention is that WebM replace the proprietary H.264 format that Apple and Microsoft Endorse.

Google has even gotten religious, and stopped supporting the .H264 CODEC in Chrome, claiming it’s only supporting open source software. It hopes to accelerate the adoption of its WebM format.

The industry is entrenched, however, and to become ubiquitous the CODEC has to be supported by all kinds of playback devices, like phones and computer chips, so do not expect major changes any time soon, even if the future belongs to open source.

Microsoft makes a pug-in for Chrome users to play the proprietary CODEC. So there you have it, the messy world of building a brave new future.

Translating Video from H264 to Theora Ogg

What this all means is that you have to translate your video into several different formats if you want to serve it yourself, just like audio, and include source links to each of them. The browser will then play whichever one it is most attracted to.

There are plenty of ways to get the .h64 CODEC, but to translate to ogg requires

I need to create an ogg file from the mp3 file, and serve up both files, and the browser will pick whatever one they can play. Since I have an mp3 file, I need to create the ogg file. Translating the audio file from mp3 to the ogg format can be done using Miro Video Converter, or if you want more control, Handbrake.

Here is example code for inserting video into the browser, using both ogg and H264 CODECs:

<video width=480 height=270 controls>
<source src="http://b.parsons.edu/~dejongo/12-fall/stuff/10_example.ogg" type=video/ogg>
<source src="http://b.parsons.edu/~dejongo/12-fall/stuff/10_example.mp4" type=video/mp4>
Download the example video in
<a href="http://b.parsons.edu/~dejongo/12-fall/stuff/10_example.ogg">oog</a>, or
<a href="http://b.parsons.edu/~dejongo/12-fall/stuff/10_example.MP4">mp4</a> format.
</video> 

CSS Code View

Download this video and transcode it, then upload it and get it to play in Firefox.

This is, of course, only the beginning. An example of what’s coming is the use of javascript to make a much more customized player and the ability to initiate actions that control web content from the movie itself, as in popcorn as demonstrated in this canvas sketch demonstration. The possibilities of HTML5 and open source video are endless and belong to the future.

11 Modular Websites & Interaction

Week 11
11/12

Programming on the web. Scrips on the server and the client create the modern web experience. 1. Introduction to PHP. Activity: Use PHP includes to make final website modular. 2. JQuery as a way to create dynamic web pages. Activity: Create a dynamic web page using jQuery.

Homework

1) For the class: Implement a PHP include for your navigation and a jQuery script into your final website. 2) For the final: finish the remaining page for your website for peer review. Read chapters 19 and 20. Due: The following week.

Materials

Additional materials for this unit can be found by following these links:

Goal

The goal of this unit is to:

  • Be exposed to programing languages.
  • Understand the benefits to modular web site design.
  • Add interactivity to the website.

Outcomes

At the end of this unit, students will have:

  • Used PHP to create a modular web page.
  • Created interactivity by implement jQuery in a web page.
  • Been left with a general idea of both server side and client programing languages for the web.

Step-by-Step

20 Review homework and answer questions.
60 Server Side Scripting: Modular Websites with PHP
10 Break
60 Client Side Scripting: Interaction with Javascript and jQuery

Examples

Other Course Examples

Syllabus of the other Web Design Basics section and the syllabus of a design course CORE INTERACTION-think interface. This should give you some perspective on what you have been learning here.

Javascript, JQuery and PHP

Jquery has been the most popular implementation of jQuery. A set of Jquery Tutorials to get you started.

CMS or Content Management System are modular websites, and they are everywhere. The benefits are that content can be accessed and updated by the clients themselves. Once the template is set up, the navigation and look are taken care of. It is possible to acquire templates and modify them for your own usage, or to build them from scratch.

Disadvantages are that the site needs to be maintained and becomes vulnerable to being hacked if you don’t.

This site is a modular site running WordPress. Take a look at the wordpress showcase and see other examples. Other popular CMSs are Joomla and Drupal.

News and External Resources

Resources that will aid in your understanding of HTML and CSS.

  1. Learn To Code Academy
  2. Eloquent JavaScript
  3. Net Magazine’s 25 best books for web designers and developers. Of which the most relevant title for this section is DOM Scripting, which I read a while ago, and it is a designer friendly approach to learning Javascript.
  4. Safari Visual Effects Guide
  5. Opera Developer
  6. Mozilla Developer: CSS Reference and Demos

Definitions

These are the terms that participants should be familiar with during this unit:

PHP

PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. It also has evolved to include a command-line interface capability and can be used in standalone graphical applications.[2] PHP can be deployed on most web servers and as a standalone interpreter, on almost every operating system and platform free of charge.[3] There is also commercial software such as RadPHP, a rapid application development framework for the PHP language. A competitor to Microsoft‘s Active Server Pages (ASP) server-side script engine[4] and similar languages, PHP is installed on more than 20 million websites and 1 million web servers.[5]

PHP was originally created by Rasmus Lerdorf in 1995. The main implementation of PHP is now produced by The PHP Group and serves as the de facto standard for PHP as there is no formal specification.[6] PHP is free software released under the PHP License which is incompatible with the GNU General Public License (GPL) due to restrictions on the usage of the term PHP.[7]

PHP is a general-purpose scripting language that is especially suited to server-side web development where PHP generally runs on a web server. Any PHP code in a requested file is executed by the PHP runtime, usually to create dynamic web page content or dynamic images used on web sites or elsewhere.[34] It can also be used for command-line scripting and client-side GUI applications. PHP can be deployed on most web servers, many operating systems and platforms, and can be used with many relational database management systems (RDBMS). It is available free of charge, and the PHP Group provides the complete source code for users to build, customize and extend for their own use.[3]

PHP acts primarily as a filter,[35] taking input from a file or stream containing text and/or PHP instructions and outputting another stream of data; most commonly the output will be HTML. Since PHP 4, the PHP parser compiles input to produce bytecode for processing by the Zend Engine, giving improved performance over its interpreter predecessor.[36]

Originally designed to create dynamic web pages, PHP now focuses mainly on server-side scripting,[37] and it is similar to other server-side scripting languages that provide dynamic content from a web server to a client, such as Microsoft‘s Asp.net, Sun MicrosystemsJavaServer Pages,[38] and mod_perl. PHP has also attracted the development of many frameworks that provide building blocks and a design structure to promote rapid application development (RAD). Some of these include CakePHP, Symfony, CodeIgniter, and Zend Framework, offering features similar to other web application frameworks.

On JavaScript

Mastering CSS is akin to building amazing things with Legos. Understanding JavaScript is like manufacturing Legos. Though related, they are simultaneously altogether different.

Javacript

JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented,[6] imperative, and functional[1][7] programming styles.

JavaScript was formalized in the ECMAScript language standard and is primarily used in the form of client-side JavaScript, implemented as part of a Web browser in order to provide enhanced user interfaces and dynamic websites. This enables programmatic access to computational objects within a host environment.

JavaScript’s use in applications outside Web pages — for example in PDF documents, site-specific browsers, and desktop widgets — is also significant. Newer and faster JavaScript VMs and frameworks built upon them (notably Node.js) have also increased the popularity of JavaScript for server-side web applications.

JavaScript uses syntax influenced by that of C. JavaScript copies many names and naming conventions from Java, but the two languages are otherwise unrelated and have very different semantics. The key design principles within JavaScript are taken from the Self and Scheme programming languages.[8]

Javacript Libraries

A JavaScript library is a library of pre-written JavaScript which allows for easier development of JavaScript-based applications, especially for AJAX and other web-centric technologies.

Some JavaScript libraries, such as YUI, are classified as frameworks since they exhibit full-stack capabilities and properties not found in general JavaScript libraries.

While JavaScript, as first developed by Netscape (and later Mozilla), has long had a presence on the Web for many websites, it gained a particular pitch with the rise of the Web 2.0 era of computing, in which JavaScript became increasingly used for the development of user interfaces for applications, both web-based and desktop-based. JavaScript was also combined with CSS to create dynamic web pages, which have also become popular as a more efficient and accessible alternative to Flash -based websites.

With the expanded demands for JavaScript, an easier means for programmers to develop such dynamic interfaces was needed. Thus, JavaScript libraries such as Prototype, script.aculo.us, Ext Core, MooTools and jQuery and JavaScript widget libraries such as Ext JS and Dojo Toolkit were developed, allowing for developers to concentrate more upon more distinctive applications of AJAX. This has led to other companies and groups, such as Microsoft and Yahoo! developing their own JavaScript-based user interface libraries, which find their way into the web applications developed by these companies.

Almost all JavaScript libraries are released under either a copycenter or copyleft license to ensure license-free distribution, usage, and modification.

jQuery

jQuery is a cross-browser JavaScript library designed to simplify the client-side scripting of HTML.[1] It was released in January 2006 at BarCamp NYC by John Resig. Used by over 55% of the 10,000 most visited websites, jQuery is the most popular JavaScript library in use today.[2][3]

jQuery is free, open source software, dual-licensed under the MIT License or the GNU General Public License, Version 2.[4] jQuery’s syntax is designed to make it easier to navigate a document, select DOM elements, create animations, handle events, and develop Ajax applications. jQuery also provides capabilities for developers to create plug-ins on top of the JavaScript library. This enables developers to create abstractions for low-level interaction and animation, advanced effects and high-level, theme-able widgets. The modular approach to the jQuery framework allows the creation of powerful and dynamic web pages and web applications.

11 Homework

Homework for the Final

  1. Develop and document the information architecture of the finished site in your work-sheet.
  2. As You develop the navigation, create it as a PHP include.
  3. Test it.

Homework for the Unit

  • Replace the navigation of your final with a PHP include.
  • create a JavaScript/jQuery script for use in your final website.

11 JavaScript/JQuery

If Html is for content and CSS is for presentation, than Javascript is for behavior. It really takes mastery of all three to become a web designer. Unfortunately, it would be too much for this class to tackle all three, so we just touch on Javascript and give you some idea of how it works. If you want to learn more, try Kahn Academy or Codecademy for Javascript or Jquery.

Javascript goes as far back as the origin of the web. You will recall that the web was inspired by Apple’s Hypercard, which had been implemented in a proto-web kind of way in the offices where the web was born. Well, hypercard had a scripting language called Hyperscript that inspired Javascript.

Javascript transforms the content of web pages in much the same way as HyperScript transformed the content of the hypercard stacks. Javascript scripts are executed upon loading or by a user action, and do something to the content of the web page. Much of the added functionality on the web is due to Javascript.

Where Javascript Enters the Picture

When the browser requests content from the server, the document is fetched or constructed by server side scripting, crosses the HTTP divide, and arrives at the client (the browser). The browser then parses the content, starting with the header, and constructs the document, including the requests for additional resources such as the CSS stylesheet, JavaScript scripts, fonts, and images, and organizes all of it into the web page we are all familiar with. In the case of Ajax, additional material can be requested and received without flushing the existing page, allowing the page to be updated asynchronously.

The DOM

The browser processes, or parses the information, transforming the tags, attributes, content, etc., into nodes that form a tree according to the document object model, the DOM. See the demonstration.

HTML DOM tree

The browser attempts to heal any errors that come up as the document tree is constructed. Each browser does that in their own way, meaning that the tree structure of the document can be different from one browser to the next. Part of the HTML5 specification is to create a unified way for browsers to handle non-valid documents, making sure that all browsers create the same DOM for any given page.

JavaScript manipulates the properties and the elements in the DOM as soon as the page is loaded, or afterwards, if triggered by the user. Slight variations in how the different browsers handle JavaScript create big problems, which may or may not be the same from browser to browser. You can imagine that it used to be a real pain to program JavaScript.

This pain kept the more integrated Javascript implementations out of general usage, mostly relegating it to simple code snippets for much of its existence. The solution came with the development of cross browser JavaScript Libraries, which provide a simplified unified interface, or framework for implementing Javascript across the various browsers.

There are well over 50 of such open source libraries, of which jQuery is but one. They all simplify the task of creating highly responsive web pages, abstracting away browser specific features that let designers concentrate on design and user interactivity.

Then again, jQuery has won the hearts and minds of the web development community and has become ubiquitous since its release. It is the “write less, do more” library we all know and love.

The browsers have cleaned up their act and support a uniform DOM implementation, these days. While this alone does not make jQuery superfluous, it is possible to make the case to write Javascript instead of jQuery. If you wish to learn Javascript, you can read Eloquent Javascript (pdf) for free on the web.

jQuery

jQuery is one of the many JavaScript libraries created to ease JavaScript development. John Resig, the person who created the library, originally wanted to call it jSelect, but the url was already taken, so it became jQuery. One of the most important things that jQuery does is provide a more uniform and easier to access ability to select DOM elements, removing the problems caused by different Javascript implementations and DOM error resolution.

jQuery is very flexible when it comes to selecting DOM elements with the jQuery function, and it works similar to the way selectors do in CSS.

In the same way that jQuery simplifies selecting DOM elements, it also makes manipulating the node objects much easier. It does not just return the DOM object, but wraps each one of them with standard functions that make it really easy to manipulate them. You can show, toggle, hide, animate and otherwise manipulate and attach events to these objects with ease.

The Focus of jQuery

From a slideshow by John Resig:

In a nutshell:

  • $(“div”).addClass(“special”);
  • Find some elements — Better CSS Selector support than most browsers!
  • Now that we’ve found the elements, let’s change them!

jQuery is Magic

Many of jQueries perceived magic happens for designers, since many of its effects are visual whenever it manipulates the document’s HTML or CSS, which it often does. It’s also magic in the way it simplifies AJAX and the utilities jquery has are really useful, but that takes us well beyond the scope of this lecture. Since it’s best to learn jQuery’s visual effects through examples, lets do that. I will use the following files in this basic tutorial.

Connect to the jQuery Library

jQuery is a collection of javascript routines stored in a library. You access those routines when using jQuery. You can host this library yourself, but its more usual to let Google host it for you.

Download the compressed jQuery library to use on your site. It is one big jumble of words and symbols with everything not necessary for its execution having been removed. You can take a look at the uncompressed jQuery library if you like, but unless you know Javascript, it will not make sense.

Save the compressed jQuery library in your “js” script folder with the name “jquery.min.js” and link to it:

<script src="js/jquery.min.js" type="text/javascript">

Or link to it using Google:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript">

Where to Put the Code

Both JavaScript and jQuery need to be between <script></script> tags. Though these tags can be placed anywhere in the document, jQuery scripts are usually put in the head of the document using a function that takes care of the issue in Javascript where the code can run before the web page has been loaded, because it looks at the DOM.

Javascript code, on the other hand, is usually placed at the bottom of the document, so that the scripts runs after all the elements in the body have loaded.

If the scripts are used by other web pages on the site, it is common to create an external script.js file, in the same way that you would create a central external style.css file.

<script type='text/javascript' src=js/scripts.js></script>

In the head of the document a standard script tags links to the jQuery library served by Google:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>

This works when your document is on the server, but not if you are developing your files locally on your hard disk. In that case, you need to include “http:” in front of the href address that Google left out. It should work fine after that.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>

Why does Google leave “http:” out? That way the script will work for both http and https (http secure) sites, but just know that this doesn’t work when you are developing on your desktop.

You can also download a copy of the “jquery.min.js” file and link to that.

Once you have connected to, or downloaded the jQuery library, you set up the open and closing script tags in which to embed the code:

<script type="text/javascript">

</script>

The Ready Event

Next comes the initialization function called the ready event which waits for the document to be ready before it executes the jQuery code. This does not mean that the document and all the linked elements are fully downloaded, but only that the DOM is finished, which the browser creates before it starts to parse the web page.

<script type="text/javascript">
	$(document).ready(function() {

	});
</script>

The ready event starts with the dollar sign $ which stands for the jQuery object. If you want, you can replace the “$” with “jQuery” as I do in button #3 below. They are synonymous. This is where all of jQuery’s functionality is accessed from.

The jQuery object is passed a function that says, “when the document (DOM hierarchy) is loaded and ready to be manipulated, then fire off this function.” The ready event keeps jQuery from prematurely executing before the page DOM has loaded.

The Event

The jQuery library does not do anything by itself, it just enables us to do all kinds of stuff. From a designers perspective, it’s a way to capture events from the page, and then to do something, usually with CSS, like assign classes, removing classes, adding CSS to an object, or animating the CSS.

CSS does this in a limited way all by itself. The link element animates when we hover the mouse over it. You can use the hover event in jQuery, but you can also use many other kinds of events. It’s able to capture that click or double click and do things other than open a link, as there are over 40 events that it can watch out for. That’s what makes it exciting.

For example, Inside the ready event, a click handler is added:

<script type="text/javascript">
	$(document).ready(function() {
		$(".jq-1").click(function() {
	});
</script>

The click handler selects the object that, when clicked, executes whatever is in its brackets. In this case, it is the effect toggle, which toggles the CSS display value.

<script type="text/javascript">
	$(document).ready(function() {
		$(".jq-1").click(function() {
		$("p").toggle();
		});
	});
</script>

Tutorial

The files for this basic tutorial.

You will want to put the following code into the header:

<style type="text/css">
section {width: 800px; margin: 0 auto; background: hsla(50,100%,50%,.5); padding: 40px; position: relative; left: 0;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
	$("li.one").click(function(){
		$("h1").toggle();
	});
	$("li.two").click(function(){
		$("article").slideToggle({
		});
	});
});
</script>

And in the body, have the following code:

	<section>
	<header>
	<h1>jQuery Tutorial</h1>
		<nav>
			<ul>
				<li class="one"><a href="#">Toggle Header</a></li>
				<li class="two"><a href="#">Slide Body Copy</a></li>
			</ul>
		</nav>
	</header>
	<article>
		<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 		</p>
		<p style="display:none">Except the code itself.
		</p>
	</article>
	<footer></footer>
</section>

Functions

Functions are a way of reusing code. Much like the external style sheets are all referenced by the different pages. Functions can be called any number of times rather than having to repeat all of that code every time. Writing functions is easy:

function colorMe(){
	$("p").css("color","hsla(220,100%,50%,1)");
	$("h2").css("color","hsla(20,100%,50%,1)");
}

The empty parentheses signify to not pass it any parameters. We do not need to worry about that here. We need to call the function to use it, which we do as follows:

$("jq-1").click(function() {
	colorMe();
});

Four Buttons

The jQuery code is ready and watching the buttons to catch a click. When that happens, the corresponding code is executed. You execute the code by clicking the button.

By clicking the first button class="jq-1", all the paragraphs <p> will be toggled from visibility: default; to visibility: hidden; and vice versa, meaning that all paragraphs that are currently hidden will show.

Clicking the second button class="jq-2" toggles the site’s navigation, which is in a div with id="static".

Clicking the third button class="jq-3" will hide this slow, with this being the object being talked about in the click handler, which is the third button. It will not come back until the page is refreshed

Clicking the forth button class="jq-4" changes the CSS color value on a number of different elements. It does this by calling the function colorMe which contains the code that changes the CSS of the elements.

Test it out: 

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function colorMe(){
	$("p").css("color","hsla(220,100%,50%,1)");
	$("h2").css("color","hsla(20,100%,50%,1)");
	$("pre").css("color","hsla(120,100%,50%,1)");
	$("li").css("color","hsla(170,100%,50%,1)");
	$("h1").css("color","hsla(270,100%,50%,1)");
	$("h3").css("color","hsla(320,100%,50%,1)");
	$("#site-description").css("color","hsla(320,100%,50%,1)");
}
$(document).ready(function() {
	$(".jq-1").click(function() {
		$("p").toggle();
	});
	$(".jq-2").click(function() {
		$("#static").fadeToggle();
	});
	jQuery(".jq-3").click(function(){
		$(this).hide("slow");
	 });
	$(".jq-4").click(function() {
			colorMe();
	});
});
</script>


Oh oh, You just hid all of the paragraphs. Better click the button again.

Toggle P toggles between display: default; and display: none;. The paragraphs that show up here, including this one and the one above were styled display: none;. That is why they show up while the other disappear when you click the button.

Javascript Performs on the DOM in the Browser’s Memory

If the letters in the headline are red, you clicked the Toggle P button without clicking on the Color Text button or its reset, blue if you clicked the Color Text button before toggling the paragraphs or black if you clicked the reset for the color Color Text button before clicking the first button.

This happens because Javascript does all of its work in the DOM hierarchy that the browser keeps in memory. The changes to the page are done only in memory. Whatever changes in value that jQuery makes on the DOM stay that way until the page is refreshed, in which case it requests the original values from the server and resets the DOM.

The point to take away from this is that the Browser keeps the entire web page including all of its resources in memory, and that is where Javascript’s changes take affect, changing the DOM, and thus, changing the way the page looks.

You can reset the colors if you want.

Rethinking Website Design

Major design decisions can be based on interactive code, like what happens when the code is executed on this page when clicking the buttons above.

jQuery is a powerful way to manipulate your CSS and HTML. From a designers’s point of view, it’s an extension of HTML and CSS, an amazing expansion of what’s possible over using just HTML and CSS alone.

This introduction gives you a taste of what’s possible. It will take some time to redesign your web pages once you have the power of Javascript as harnessed by jQuery under your belt. My guess is that you’ll be egging yourself on to learn jQuery after this course has finished. Linda.com has good tutorials that will help you find your way.

Examples

Javascript and jQuery scripts can often by copied, and with a few tweaks, used to add behavior to your website. The follow examples give you a place to start.

Simple Javascript Random Image Slideshow. Copy the script, paste it between the body tag, replace the images and set the delay, to something other than 1 second.

<script language="javascript">
/*
Random image slideshow by Tyler Clarke (tyler@ihatecoffee.com) For this script and more, visit http://www.javascriptkit.com
*/
var delay=1000 //set delay in miliseconds
var curindex=0
var randomimages=new Array()
	randomimages[0]="http://b.parsons.edu/~dejongo/12-fall/stuff/12-gallery/thumb/img_1.jpg"
	randomimages[1]="http://b.parsons.edu/~dejongo/12-fall/stuff/12-gallery/thumb/img_3.jpg"
	randomimages[2]="http://b.parsons.edu/~dejongo/12-fall/stuff/12-gallery/thumb/img_2.jpg"
	randomimages[3]="http://b.parsons.edu/~dejongo/12-fall/stuff/12-gallery/thumb/img_4.jpg"
	randomimages[4]="http://b.parsons.edu/~dejongo/12-fall/stuff/12-gallery/thumb/img_5.jpg"
	randomimages[5]="http://b.parsons.edu/~dejongo/12-fall/stuff/12-gallery/thumb/img_6.jpg"
	randomimages[6]="http://b.parsons.edu/~dejongo/12-fall/stuff/12-gallery/thumb/img_7.jpg"
	randomimages[7]="http://b.parsons.edu/~dejongo/12-fall/stuff/12-gallery/thumb/img_8.jpg"
	randomimages[8]="http://b.parsons.edu/~dejongo/12-fall/stuff/12-gallery/thumb/img_9.jpg"
	randomimages[9]="http://b.parsons.edu/~dejongo/12-fall/stuff/12-gallery/thumb/img_10.jpg"
var preload=new Array()
for (n=0;n')
function rotateimage()
{
if (curindex==(tempindex=Math.floor(Math.random()*(randomimages.length)))){
curindex=curindex==0? 1 : curindex-1
}
else
curindex=tempindex
	document.images.defaultimage.src=randomimages[curindex]
}
setInterval("rotateimage()",delay)
</script>

JQuery develops a number of demos and a link to a complete jQuery Image Slider. Be forwarded. There are many default options and you will have to change the parameters to make it look good. The benefit is that this slider is fully documented.

Parallax scrolling is all the rage. This means that a number of elements scroll past at different speeds. The Nike website made this famous, and here is a tutorial of how to accomplish that. It is a great tutorial on GitHubwith source code.

If you find code you like but someone has compressed their Javascript into an unreadable form, you can use beautifier to made the code readable.

Smooth Scrolling Animation

Most people are attracted seeing their webpages scroll to a location on the page, which has led to a revolution in single page designs rather than multipage designs. A very simple solution is arbitrary anchor.

A much fancier single page website template is created by Peter Finlan. While it is tempting to use this as a starting point, try understanding how he implements jQuery and so something on your own instead.

Simple jQuery Slider

Everyone asks for an image slider. This one is simple. Download demo

Add CSS styles

#gallery {width: 601px; margin: 0 auto;}
#gallery li {display: inline; margin-right: 3px;}

Add link to jQuery

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>

or if on the desktop:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>

Add jQuery Code

$(document).ready(function() {
	$("#gallery li img").hover(function(){
		$('#main-img').attr('src',$(this).attr('src').replace('thumb/', ''));
	});
	var imgSwap = [];
	 $("#gallery li img").each(function(){
		imgUrl = this.src.replace('thumb/', '');
		imgSwap.push(imgUrl);
	});
	$(imgSwap).preload();
});
$.fn.preload = function() {
    this.each(function(){
        $('')[0].src = this;
    });
}

Add HTML

	<div id="gallery">
	<img src="gallery/img_1.jpg" alt="" id="main-img" />
	<ul>
	  <li><img src="gallery/thumb/img_1.jpg" alt="" />
	  <li><img src="gallery/thumb/img_2.jpg" alt="" />
	  <li><img src="gallery/thumb/img_3.jpg" alt="" />
	  <li><img src="gallery/thumb/img_4.jpg" alt="" />
	  <li><img src="gallery/thumb/img_5.jpg" alt="" />
	  <li><img src="gallery/thumb/img_6.jpg" alt="" />
	  <li><img src="gallery/thumb/img_7.jpg" alt="" />
	  <li><img src="gallery/thumb/img_8.jpg" alt="" />
	  <li><img src="gallery/thumb/img_9.jpg" alt="" />
	  <li><img src="gallery/thumb/img_10.jpg" alt="" />

Javascript is Back

Now that the browsers have cleaned up their act, it is possible to skip the need for jQuery and do everything in Javascript. You can try the Wallop Slider. The instructions for a slider are a little more complex, but it does not use the jQuery library.

The next frontier would be to develop your web site using Javascript and jQuery, but it is more important that you create good websites first. There is no Javascript or jQuery requirement for the final.

That should not stop anyone, however, from trying it out, once you have developed a solid website.

11 PHP

What is PHP?

PHP is similar to a lot of other programing languages. What sets it apart is the ability to seamlessly integrate into HTML. The name PHP is a recursive acronym for PHP: Hypertext Preprocessor. That tells you that PHP, which resides on the server, creates HTML files from PHP scripts on the fly.

As an end user, all you see are HTML pages, so PHP does its work behind the scenes on the server from which you request the page. This is different from Javascript, for example, which is executed by the browser on the page as it is served. The PHP constructs the page before javascript can act on it.

What we will do in this section, after briefly talking about some details of how PHP actually works, is show how PHP can modularize web development. If you want to learn more, use codecademy

Modular Web Development

One way to think about a web site is as a collection of pages, which is what we have done up to now. CSS helps us reduce redundancy by centralizing the instructions of what each page is to look like. A centralized style sheet saves us a lot of time. PHP allows us to do the same for the different parts of the web site that stay the same from page to page.

A web page is composed up of modules that remain pretty consistent throughout the site, like the header, navigation, asides, footer, etc. PHP allows us to separate these modules out as centralized external files. That means we will be creating modules like footer, header and navigation, and then use PHP to put them all together and serve them up as finished HTML pages.

PHP Basics

Everything will be done from the server, for it runs the PHP that executes the PHP scripts that we will write.

All you need to do to make PHP work is change the file extension of the file from .html to .php. Unless your computer is running PHP, however, you will need to put the files on the server.

Creating a Most Basic PHP Page

Open up a blank TextWrangler file and write:

<!DOCTYPE html>
<?php
echo "Hello World!";
?>

This is a legitimate HTML5 document if you recall that the html, head, title and body tags are optional.

Save the file on the server, and when you open it in your browser, you will see “Hello World!” in the upper left hand corner.

You have just executed a php script and created an HTML page. If you look at the code, all the php will have disappeared. Only the HTML is left.

A few things to note about the PHP script. First, the statement starts with <?php and ends with ?>. That is how you format the PHP code, which is written between these brackets.

The statement ends in a semicolon, just like CSS statements do. That signifies to the PHP processor that the statement is complete.

Content text is called a string, and is always surrounded by quotes while working within the PHP tags, just like attribute values are in quotes inside the HTML tag. Because we are writing code, and content is something that the code works on. As there is a conflict in the way that regular writing uses certain characters, like space and return for example, and for that reason needs to be differentiated from the code.

HTML is the other way around, where all of the code is separated from the content by tags, because it’s really about the content, while a coding language like PHP is really about the code.

The last thing you see is the word echo. This is a language construct, and it is what makes PHP Hypertext friendly. It tells the PHP processor to print the HTML to the screen. Use echo to turn PHP code into HTML.

Variables

No one likes to do anything twice, and programing languages are full of ways to optimize the code. One of the most fundamental and well known tenets of software engineering is theDRY rule – don’t repeat yourself.

Just as CSS centralizes the instructions for how the web page looks, and PHP modularizes the HTML web site into a number of components, programing languages create variables and give them names to optimize the code. This is how to write the last statement using a variable:

<!DOCTYPE html>
<?php
$myString = "Hello!";
echo $myString;
echo "I'm a PHP script!";
?>

The dollar sign $ signifies that myString is a variable, and the equal sign = assigns it to the text “Hello”. When this variable is echoed, it writes out “Hello”. The savings in this example are not exactly spectacular, but you get the idea. It saves programers from having to write and update the same code over and over again.

Functions

Another way that programming optimizes is to give names to common routines that it has to perform. These are called functions. Functions are more than just a name, because they often act on information, as in this simple example.

<!DOCTYPE html>
<?php
function myGreeting($Name){
    echo "Hello there ". $Name . "!
"; } myGreeting("Jane Doe"); myGreeting("John Doe"); myGreeting("Barbie"); myGreeting("Ken"); myGreeting("America"); echo "How Are You?"; ?>

The computer runs down the page just as in HTML. When it gets to myGreeting, it takes the value in the parentheses and passes it to the variable “$name.” The function then operates on that variable, in this case concatenating “hello there ” with the name, an exclamation mark and a line-break element. These three things are concatenated, or brought together, by the period. The entire result is then printed, and the computer goes to the next line and repeats the entire procedure over again, till the end, where echo tells it to print “How are You?”

Operators

Computers control the flow of electrons in circuits that are either on or off. Controlling this flow gives rise to how a computer works, and how computer languages work. We say that a program is running, because even if it does nothing on the screen, the flow is cycling, waiting for something to trigger a change in the flow.

Operators manipulate this flow, using simple logic and math in creative ways. Basic logic structures the flow and determines how the result is to be assigned; if this is equal to that or this and that. There are boolean operators that signify the outcome of the flow as true or false, causal statements, that say if condition is met, do that, or else it redirects the flow in another direction, and lots of mathematical operators that go way beyond addition and subtraction.

PHP’s use is primarily connected up with databases that store the snippets of content that PHP can pre-process into HTML pages. To do that it spends a lot of the time talking to databases and requesting and looping through the content to organize it into HTML pages. We are not going to go any further into the PHP language itself, but know that many of the larger sites use this kind of server side scripting.

Includes

You only learn something if it is truly useful. In that way, PHP provides a very powerful function to modularize the website with a bare minimum of code: PHP include. Include takes a file name and simply inserts that file’s contents into the script that issued the include command.

This means that you can create a common menu file that you want all your web pages to include. When you add a new page to your site, for example, instead of having to update the links on several web pages, you can simply change the one file.
To create a common menu file that all our pages will use, save a blank file as “navigation.html” in the same directory as the index.html and paste in the nav element. We then plug that menu into our index page, replacing the nav element with the following code:

<?php include("navigation.php"); ?>

That’s it. When a browser makes a request for your index page, it will include the code from your navigation.html file. And you can do this with the header, the footer, and any other parts of your web site that remains the same throughout the web site.

The example I’ve prepared does exactly that. The one thing I added was an ability to give the user feedback on the page they are on by adding both an id to each page and a unique class to each menu, and when they coincide, the menu lights up to show the current page.

Visitors do not see the PHP code. All the PHP is processed out. What remains is HTML, as if it had been written as one HTML document. Download the code the see the PHP

More

Next week’s lesson will cover forms, which often depends on a PHP script, and in the class after that, we take a look at WordPress, created using PHP, so there is a lot to server side scripting.

Here is the sample code for the PHP example:

modular.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Modular Web Sites</title>
<link rel="stylesheet" href="style.css" media="all">
</head>
<body id="modular">
<div id="wrapper">
<?php include_once("header.php"); ?>
<section>
<?php include_once("navigation.php"); ?>
<article>
<h2>Modular Web Development</h2>
<p>One way to think about a web site is as a collection of pages, which is what we have done up to now. CSS helps us reduce redundancy by centralizing the instructions of what each page is to look like. A centralized style sheet saves us a lot of time. PHP allows us to do the same for the different parts of the web site that stay the same from page to page.
<p>A web page is composed up of modules that remain pretty consistent throughout the site, like the header, navigation, asides, footer, etc. PHP allows us to separate these modules out as centralized external files. That means we will be creating modules like footer, header and navigation, and then use PHP to put them all together and serve them up as finished HTML pages.
</article>
</section>
<?php include_once("footer.php"); ?>
</div>
</body>
</html>

navigation.php

<!DOCTYPE html>
<nav>
<ul>
<li><a class="whatIs" href="whatIs.php">What Is PHP?</a></li>
<li><a class="modular" href="modular.php">Modular Pages</a></li>
<li><a class="basics" href="basics.php">PHP Basics</a></li>
<li><ul>
<li><a class="page" href="page.php">Writing PHP</a></li>
<li><a class="variables" href="variables.php">Variables</a></li>
<li><a class="functions" href="functions.php">Functions</a></li>
<li><a class="operators" href="operators.php">Operators</a></li>
</ul></li>
<li><a class="includes" href="include.php">Includes</a></li>
<li><a class="more" href="more.php">More</a>
<li><a class="example" href="example.php">Example Code</a></li>
</ul>
</nav>

header.php

<!DOCTYPE html>
<header>
	<h1>Modular Websites using PHP</h1>
</header>

footer.php

<!DOCTYPE html>
<footer>
	<a href="">Web Design 1</a>, Parsons, the New School of Design. Additional resources can be found at <a href="http://php.net/">PHP.net</a>, with tutorials and the manual at an <a href="http://php.net/manual/en/intro.pdo.php">Introduction to PHP</a>.
</footer>

CSS Styles

See the note that explains the special treatment for the navigation page highlight below.

/*structure*/
body{
	background: #aaa;
}

#wrapper {
	width: 650px;
	margin: 40px auto;
}
header {
	height: 75px;
	background-color: #eee;
	padding: 30px 30px 0px 30px;
	border-bottom: 4px double #aaa;
}
section {
	background: #ccc;
}
article {
	background: #eee;
	padding: .5em 1em 1em;
	margin-left: 210px;
	width: 380px;
	line-height: 1.3em;
	min-height: 420px;
}
footer {
	border-top: 1px solid #aaa;
	background-color: #eee;
	padding: 30px;
}

/*Navigation*/
nav {
	width: 160px;
	padding: 20px;
	float: left;
	background-color: #eee;
}
nav ul {
	padding-left: 20px;
}
nav ul li {
	list-style: none;
	padding: 2px 0 2px 0px;
	}
/* Notice
	  All the page ids are paired up with their unique menu item. That way the link on each page light up, so you know which page you are on
*/
body#whatIs a.whatIs,
body#modular nav ul li a.modular,
body#basics nav ul li a.basics,
body#page nav ul li a.page,
body#variables nav ul li a.variables,
body#functions nav ul li a.functions,
body#operators nav ul li a.operators,
body#includes nav ul li a.includes
{
	color: black;
	background: #fff;
}
nav ul li a{
	display: block;
	color: #000;
	text-align: left;
	padding: 10px;
	background: #ddd;
	border: 1px outset #eee;
	text-decoration: none;
}
nav ul li a:hover{
	color: black;
	background: #aaa;
}
/*style*/
h1 {
	font-size: 2em;
	font-weight: 700;
}
h2 {
	font-size: 1.5em;
	margin: 1.4em 0 .6em 0;
	font-weight: 700;
}
pre {
	background: #eef;
	padding: 1em;
	margin: 1em;
}