Class 6 – CSS browser compatibility chart

Posted: October 31st, 2009 | Author: | Filed under: css | Tags: , , | No Comments »

The Quirksmode site has a good chart outlining all the majors browsers’ support of standard CSS commands.

The red elements in the chart indicate the features of CSS not supported by the browsers.  This chart makes it easy to see why web developers dislike Microsoft Internet Explorer.


Class 7 – Assignment #1

Posted: October 31st, 2009 | Author: | Filed under: assignments, php | Tags: , , | No Comments »

Your in-class assignment today is to update your e-commerce pages from the previous class to be more “dynamic” and “templatized”.

Templatize the common sections of all pages in the entire site

Use separate PHP include files for the top ad banner, global navigation, breadcrumbs, skyscraper ad, and footer.  On a real site, these sections would be the more-or-less the same on all pages, so you would want to have them stored in reusable files.  These files will be included into the main XHTML file for each page using the include() function of PHP.  Feel free to check out the include examples that are up on the server.

Note: As a convention in this class, whenever you create a file that has a snippet of XHTML that is included into another page but never displayed directly on its own, I would like you to give it a name prefixed with the “_” character.  For example, the include files used in this assignment could be called:
  • _header.php
  • _breadcrumbs.php
  • _ad_banner.php
  • _ad_skyscraper.php
  • _footer.php
Templatizing these parts of the page will allow you to reuse those sections on multiple pages on your site, if you ever build it out to be more than one page, without having to rewrite the code for each.  Naming the files with this convention will make it obvious when looking at a list of your own files which ones are main XHTML pages and which ones are meant to be include files.

Templatize the products

Once you have finished that, it’s time to start templatizing the actual products that are displayed on the page as well.  This would, in theory, allow you to use the same page template for multiple categories of products.

We will do this in a different way than how we templatized the repeating sections of the page.  We will be using multidimensional arrays this time.  This exercise will be useful as a preparation for when we start to store data in databases.

Eventually, we will want the data for the products to be pulled from a database.  But for now, we’re just going to store data in an array as an intermediary step to that goal.

To templatize the products, create a PHP multidimensional array that contains all of your product data.  And use a PHP foreach loop to loop through that array and display the product data for each product on your page, rather than having it all hard-coded in the XHTML.

Do the tutorials, understand the examples

You are going to have to go through all the PHP tutorials on the Tizag site and my introduction to arrays in order to get a grasp of arrays and multidimensional arrays in particular.

Here is an example of how to get starting using a multidimensional array for this assignment.  I did not show how to use the foreach loop here, so you will have to investigate that, based on the example of looping through an array using the foreach command shown here.

Be sure to keep a backup of the work you did on the e-commerce page in previous classes – do not overwrite it, just make a copy of it.

Links to helpful documentation


Class 7 – Introduction to PHP

Posted: October 31st, 2009 | Author: | Filed under: php | Tags: | No Comments »

Today we enter the realm of server-side technologies.  PHP is the server side scripting language that we will be focusing on, but many of the high-level concepts we will be exploring with PHP could just as easily apply to other server-side languages like ASP.NET, Ruby, Python, Java Server Pages, and others.

What is PHP used for?

You may wonder why we even need server-side languages, given the we have seen how the vast majority of web pages are created with a combination of XHTML, CSS, and Javascript.  Use Firefox to View -> Page Source on any web page and you will probably see XHTML, CSS, and Javascript code, but absolutely no PHP.

Web developers use XHTML, CSS, and Javascript to control how content shows up in the web browser and how the user interacts with that content.  That’s the sole purpose of client-side technologies.   Server-side technologies, like PHP, are used to control how that content is assembled and managed on the server before it has even been sent to the browser.  Thus, PHP is used to dictate what is often referred to as the “business logic” of a web site.

There are three main uses of PHP:

  1. web page templating
  2. storing and retrieving content
  3. tracking user sessions

These three uses are not mutually-exclusive.  For example, templating and tracking users depends upon the ability of PHP to store and retrieve content.

Web page templating

Most web sites have elements of the page that are repeated on each page.  Very commonly, global navigation or other important navigation elements are repeated on all pages of a site.  For example, Google uses the same global navigation links across many of its sub-sites. Notice that the global navigation remains mostly the same from page-to-page, with slight changes:

Global navigation of Google home page

Global navigation of Google home page

Global navigation of Google home page with logged-in user

Global navigation of Google home page with logged-in user

Global navigation of Google Images with logged-in user

Global navigation of Google Images with logged-in user

Global navigation of Google News with logged-in user

Global navigation of Google News with logged-in user

It is very unlikely that Google engineers have hand-coded each of the pages on the Google site individually to have the same XHTML and CSS code for this top section.  If this were the case, and Google decided to make a slight change to the layout of this top navigation section, the engineers would have to go through the code of each one of the pages of all these Google sub-sites, and change the XHTML accordingly.  This would be a very inefficient and expensive way of maintaining a site.

It is much more likely that the engineers have coded this top section once, and are reusing that same code on each of the pages, with slight variations.  If they then wanted to make a change to this top section across the site, they would change that one bit of code, and the rest of the site would update automatically.  This would be referred to as being a template.

Take another look at the websites you frequently visit, and you will probably see that there are many sections of content that are repeated on each page.

Storing and retrieving content

When you visit many sites, you will see that the content is updated regularly but the design often does not change.  For example, news sites, e-commerce stores, and blogs all have regularly udpated content (news, products, and blog posts, respectively), while maintaining a consistent design.

Every time a new product is added to a store, the web developers do not usually have to hand-code the new product information.  Rather, they build a site that allows an administrator to enter the details of a new product into a form, and when they click submit, that information is stored in a database.  And each time a consumer visits the e-commerce site, the server-side code retrieves the latest list of products from the database and fits them into a web template.

As an example, consider the products on Amazon.com.  The listings of Sheets and the listings of Comforters look identical in layout and design, however the products that are listed in those two sections are different.  This is because the data is being pulled from two different data sets in a database – one for sheets, and one for comforters, but the data in each case is being fit into the same template.

Amazon.com Sheets

Amazon.com Sheets

Amazon.com Bedding

Amazon.com Comforters

Thus, the storage and retrieval of data is critical for any dynamic web site.  And this use of server-side scripting generally goes hand-in-hand with the templating of web pages.  In this case, the template would control the general layout and design of the products section of the site.

Data can be stored and retrieved to/from a variety of different places

  • databases, which store data in a way that is conceptually similar to spreadsheets
  • files, such as text or image files
  • web services, which are a mechanism that allows one server to store and retrieve data from another server
  • cookies, which are small bits of information that a server can store temporarily on the client computer

PHP can be used to handle the details of using each of these storage mechanisms.

Tracking user sessions

It is often desirable for a web site to be able to track visitors.  For example, a user who logs in to their webmail account expects to see their own mail and not someone else’s.  Thus, in order for the webmail web server to properly determine which user is currently using the site, it must track each visitor to the site in some way in order to differentiate between multiple users visiting the site at the same time.

Sometimes you want to track users even when they haven’t logged into your site.  For example, if you were giving a tutorial on your site, you may want to know how far each user has gotten in the tutorial, even without requiring them to log in.

Tracking users usually involves using cookies at the very least.  Often, it will also involve the other sorts of data storage as well.


Class 2 – Web Dev Discussion List

Posted: October 28th, 2009 | Author: | Filed under: course info | Tags: , | No Comments »

You should have received notification that you are subscribed to the Web Dev Intensive email discussion list.  That email should have information on how to send email to the list, as well as how to subscribe or unsubscribe from the list, so please don’t delete it.

Emails sent to this list at

Picture 3

will be received by everyone in the class, as well as former students from past classes.  So it might be useful if you have questions, problems, or anything else you want to share with the class.  Use it however you want.

If you have not yet received notification of the list, send a test email to the list address above.  If for whatever reason, you have not been subscribed to the list yet, I will be notified automatically and will add you to the list.


Class 6 – Assignment: create a Tic-Tac-Toe game using JQuery

Posted: October 24th, 2009 | Author: | Filed under: assignments, javascript, jquery | Tags: | No Comments »

Advanced assignment

For those of you who are finished with all the previous assignments and feel comfortable with everything so far, here is the advanced assignment.

Your job is to make a tic-tac-toe game online using XHTML, CSS, Javascript, and JQuery.

Tic-tac-toe is a two player game.  One player is “X” and the other player is “O”.

Wireframes

Here is the beginning screen before either player has moved:

Beginning tic-tac-toe board

Players can click on any empty square.  But once a square has been clicked, it cannot be clicked again.

When the first player clicks on any square, that square becomes an “X”:

screen2

The next player then clicks on any empty square, and it becomes an “O”:

screen3

The players then take turns until one player has three of their squares in a row, either horizontally, vertically, or diagonally.  For example, the “X” player in this example has three X’s in a row vertically, so she has won:

screen4

When a player wins, the browser detect the winning state, and should pop up a message that indicates who has won.

screen5

It is possible that neither player has won after all the squares have been clicked.  If this is the case, the browser should show an appropriate message:

screen6

Once the player clicks the “Start over” button or clicks the little “x” at the top right of the message box, the game should start over, the message box should disappear, and the game board should become blank again.


Class 6 – Assignment(s)

Posted: October 24th, 2009 | Author: | Filed under: assignments, css, javascript, jquery, xhtml | Tags: | No Comments »

Please complete all client-side assignments

This week marks the end of covering the client-side technologies, XHTML, CSS, and Javascript.  Next week, we will begin with the server-side technologies, PHP, and MySQL.  So the major assignment for this week is to make sure all your assignments from past weeks are completed, working, and linked from your blog so I can grade them. There will be a general amnesty for late assignments – if you complete them by the end of the week, you will receive a full grade.

PS: Please test the links to your assignments before posting them to your blog.  If the links don’t work, then I can’t see your assignments, which means you get a zero grade for them.  Not a happy conclusion to your hard work.  Also, a screenshot of your assignment is not a substitute for a link to it.  There are several of you who are repeat offenders on both counts – please go through your old posts and make sure all links to past assignments are present and working.

The assignments so far are:

  • Class 1 – Information architecture wireframes
  • Class 2 – Convert simple wireframe to XHTML code
  • Class 3 – Convert three simple wireframes into XHTML & CSS code
  • Class 3 – Convert a wireframe from Class 1 into XHTML & CSS code
  • Class 4 – Convert BlackBook design comp into XHTML & CSS code
  • Class 4 – Convert MTV Videos design comp into XHTML & CSS code (**optional, but recommended)
  • Class 5 – Javascript key-logger
  • Class 5 – Convert e-commerce wireframe into XHTML, CSS, and Javascript code
  • Class 6 – Same e-commerce page as in Class 5′s assignment, but using JQuery
  • Class 6 – Tic-tac-toe game using JQuery (**optional, but not heavily recommended)

Quiz

We will be having a quiz next week on the client-side material, so please make sure you have done all the assignments and gone through all the previous reading material that has been assigned.


Class 5 – What is the Javascript Document Object Model?

Posted: October 23rd, 2009 | Author: | Filed under: javascript | Tags: , , , | No Comments »

In your studies of Javascript, you will most likely come across the Document Object Model (DOM for short) at some point. The DOM is simply the internal representation the browser has of the contents of a web page.  We have already discussed some aspects of the DOM without calling it such.

The layout engine

Whenever you write XHTML and CSS code, the web browser does some internal processing to determine out how the page is supposed to look.  The part of the browser responsible for this task is known as the layout engine.  The different browsers often have slight different layout engines which means the browsers sometimes display the contents of any given page slightly differently.

The internal representation that the browser makes of the page, the DOM, is made accessible to any Javascript code on the page as a series of built-in Javascript variables.   For example, “window” is a built-in variable that holds information about the entire browser window.   “document” is another built-in variable that contains all the information about the content in the <body> section of the page.

Developers can write Javascript code to interact with the DOM to either detect or to change how the page is internally represented.

Object-oriented DOM variables

These built-in variables that hold the browser’s internal DOM information are object-oriented, which for our purposes means that these variables do not necessarily hold just text or numbers.  They often are wrappers that contain other properties, functions, or other objects “inside” of them.  For example, the “window” object has a “title” property inside of it, which is simply a variable that holds the text inside the <title> tag in the XHTML.

When one property, function, or object is inside of another, we use dot notation to indicate the hierarchical relationship.  So window.title indicates that title is a sub-property of the window object.  The code window.close() tells the browser to run the function called close() that is inside of the window object, which happens to close the window automatically.  Similarly, window.alert(“hello”) tells the browser to run the alert() function of the window object and pass it the parameter, “hello”.

The DOM on a need-to-know basis

There are lots of built-in variables, objects, and functions in the DOM, and it can easily become overwhelming.  However, in practice, we only use a few of these.  Don’t try to memorize them all.  By following the conventions taught in this class, it is not necessary that you delve too far into the details.

There are some things you will want to know:

  • window is the highest level DOM object.  All other DOM objects are sub-objects of window.  In fact, your own variables and functions that you define in your code are also automatically created as sub-properties of window.
  • document is a sub-object of window.  So to get access in Javascript to information concerning the stuff inside the <body> tag, you use the window.document object.  Fortunately, for convenience, you can refer to the document object as simply document.  It’s not necessary to specify the full window.document variable name. The “window.” part is implicit in all variable names, so you don’t need to write it.
  • You can get the DOM representation of any element in the <body> tag by using the getElementById() function of the document object.  For example, var el = document.getElementById(‘foo’); will find the XHTML element that has the id attribute set to “foo” and store it in memory in an object named “el”.    The variable “el” now holds an element object, which is a standard type of object used to hold all the information about individual XHTML elements.  Element objects have a variety of properties and functions that are especially useful when dealing with individual XHTML elements.
  • The className property of the element object holds the name of the class that is specified in the XHTML.  For example, to detect the class of an XHTML element that looks like this <p id=”p1″ class=”foo”>…</p>, you would first get an element object that holds information about this element by using var el = document.getElementById(‘p1′); Then you would access this element’s className property by referring to it as el.className.  For example, if you said, alert(el.className);, the word “foo” would pop up in an alert window.
  • The style property of the element object contains information about the CSS used to control the design of that element in the browser.  For example, to get the font-size property of an element such as <p id=”p1″>, you could (in theory), access that information through the DOM by referring to the element’s style.fontSize property in Javasacript.  First you would get a reference to the element object by using var el = document.getElementById(‘p1′);, then you would access this element’s font-size property, for example, with alert(el.style.fontSize);
  • Image elements have a src property which represents the source file used to display the image.  For example, if you have an image tag in your XHTML like this, <img id=”img1″ src=”images/monkey.jpg” />, you can manipulate the src attribute in Javascript by doing something like, var el = document.getElementById(‘img1′); img1.src = “images/cat.jpg”;

See also


Class 5 – Assignment #2

Posted: October 17th, 2009 | Author: | Filed under: assignments, javascript | Tags: | No Comments »

Your coding assignment is to convert the following wireframe diagram into a fully functioning page, using XHTML & CSS for the layout and Javascript for the interactive behaviors.

Note: this is a wireframe, not a design comp.  So do not try to use make your pages pixel-perfect based on this diagram.  Use the diagram as a rough guide, and just make sure the Ad Banner and Skyscraper Ads you use are the size that is written into the wireframe.  All other design elements, including dimensions, colors, fonts, and borders are up to you.

E-Commerce Assignment wireframe

When someone mouses over any of the product thumbnails, the thumbnail should disappear, and a div containing information about that product should appear.  The information div should show up as exactly the same height and width in exactly the same place where the thumbnail was on the page.

When the user then mouses out of the product info div, the info div should disappear, and the product thumbnail image for that product should reappear.

So the trick to this assignment will be to first create the layout with all the basic page elements using XHTML & CSS.  Be sure to create an “img” tag and a “div” tag for each product.  The img tag should be visible when the page first loads, and the div tag should be invisible by setting its “display” property to be “none” in the CSS.

Create the mouseover and mouseout Javascript event handlers so that when you mouse over an image the image disappears and the div shows up.  And when you mouse out of the div, the div should disappear and the image should re-appear.

Tips / Spoilers

Note: don’t read this if you want to figure out the solution yourself.

Solution #1: Here is an example of how I would set up the product thumbnails in terms of both XHTLML and Javascript.  You can use this exact code for the thumbnails on your own pages, but be sure you understand how it is working.

Solution #2: It just so happens that you don’t even need to use Javascript to complete this assignment.  Here is an example that has no Javascript and relies instead upon the CSS :hover pseudo-class to do the same thing.

Solution #3: Here is a slight variation on the CSS-only solution outlined in Solution #2.  This version makes the product thumbnail become partially transparent when it is moused-over, instead of disappearing entirely.


Class 5 – In-class Assignment #1

Posted: October 17th, 2009 | Author: | Filed under: assignments, javascript | Tags: | No Comments »

Your assignment in class today is to develop a sort of text-capturing script.  The page is going to be divided into two identical  panels.  In the left panel, you will have one text input, one password input, and one textarea input.  When a user begins to enter text into any of the fields in the left panel, the corresponding field in the right panel will start to be automatically filled-in with the same text that they entered in the left.

To do this assignment, you will have to look into Javascript “keyup” events.

Here is the information architecture wireframe for this in-class assignment:

Text-capturing wireframe

Text-capturing wireframe

The best way to approach this assignment is to first lay out the page in XHTML and CSS before doing any Javascript coding.  Then start thinking about the how the logic of this type of interaction might be structured.  Break it down into discrete individual steps.

Here are the basic steps that need to be handled in order for something like this works

  1. set event handlers to detect the “keyup” event whenever a user types anything into any of the form elements on the left side of the page
  2. if a keyup event is triggered, call a function
  3. in that function, first get the values of all form elements on the left side of the page and store them each in their own variable
  4. Take the values stored in those variables and insert them into the corresponding form elements on the right side of the page

I expect you’ll have questions for me about exactly to do this, so please try to figure it out based on the examples so far, and ask for help when you get stuck.

Hint

Dealing with keypress, keyup, or any other type of supported Javascript event is not so different from the examples we went over for mouseover, mouseout, and click events.  You create an XHTML attribute called “onkeypress” or “onkeyup” in each element you want to detect these events for, and set its value to be a call to a Javascript function…

<input type="text" name="first_name" id="first_name" onkeyup="doSomething();">

To get an XHTML element into memory in Javascript, you access it based on its “id” attribute.  So, for example, to get an element with the id=”first_name” into memory, we would do the following in Javascript:

var firstNameElement = document.getElementById("first_name");

To get the value of a text input, password input, or textarea element, you can use the .value property of the element in Javascript.  So, for example, to get the value of the element retrieved above, we could do something like:

var firstNameValue = firstNameElement.value;

To set the value of a text input, password input, or textarea element, you can do the reverse.  For example:

firstNameElement.value = "some new value here";

where “some new value here” can be left as a string literal, as in what we just saw, or replaced by a variable that holds a string in memory, such as:

var newName = "Amos";
firstNameElement.value = newName;

Class 4 – Assignment #2

Posted: October 10th, 2009 | Author: | Filed under: assignments, css, xhtml | Tags: | No Comments »

For those of you who have completed assignment #1, your next assignment is to go through the same process with this new design comp:

app_screenshot

The image files necessary for this assignment are, as with the previous one, available on the server here.

The global navigation buttons (i.e. “Home”, “Friends’ Videos”, “Featured Videos”) should be done using an unordered list <ul> element, as recommended in the previous assignment.

The only font used on this page is Tahoma.

  • The light blue font color has hexadecimal code, #AEBEE1
  • The dark blue font color is #3B5998
  • The dark gray font color used for the regular text on the page is #333333
  • The light gray font color used for dates is #999999

Some of the background colors used are #F7F7F7 and #D8DFEA.

The light gray borders used between listings in the “Recent Activity” area is #DDDDDD.

The “+” and heart buttons that show up to the right of each video in the “Recent Activity” section should use the sprite rollover technique we discussed in Class 3.  The example of the sprite technique is available here.