Tuesday, May 29, 2012

Adding Fast-Forward and Rewind Buttons with HTML5

Yes, it’s back to adding buttons I’m afraid. But you’re a dab hand at adding them by now, so I won’t need to tell you what to do until you get to the JavaScript stage.

Let’s define the buttons and throw in the function names for the onclick events because you now know what’s what:
<button id=”rewind” title=”reverse” onclick=”changePlaybackSp
eed(‘-’);” >&laquo;</button>
<button id=”ffwd” title=”fast forward” onclick=”changePlaybackSp
eed(‘+’);” >&raquo;</button>
You’ll use the HTML entities &laquo; and &raquo; to mimic the typical symbols you find on such buttons: « and » respectively.
Notice that the name of the function you’ll define is changePlaybackSpeed(). The attribute that you’ll change to make this work is the playbackRate attribute that you encountered in Table 5.1.

There is a caveat though: Currently, only the WebKit-based browsers, Safari and Chrome, support the playbackRate attribute. Therefore, the only way you can sort of mimic the intended functionality on other browsers is to alter the video’s currentTime attribute, moving it either forward or backwards:
function changePlaybackSpeed(direction) {
     if (video.playbackRate != undefined) {
          if (direction == “-”) video.playbackRate -= 1;
          else video.playbackRate += 1;
     }
     else {
          if (direction == “-”) video.currentTime -= 1;
          else video.currentTime += 1;
     }
}
If video.playbackRate is defined, you check the direction parameter passed in—again “-” for back and “+” for forward—and decrease or increase playbackRate accordingly. If the playbackRate is 0, the video is effectively paused and playback stops. Otherwise, you move the video’s currentTime backwards or forward by 1.
TIP: Although Safari and Chrome support the playbackRate attribute, they work in different ways. Both support the incrementing of the parameter to fast forward, but Chrome doesn’t support rewinding. Safari on the other hand actually starts to play the video backwards, right to the start.
Your simple but slightly more awesome than it was at the start of the chapter media player now has a full set of rather grey but functional buttons and a working progress bar (Figure 5.7).

With a bit of jiggery pokery with CSS, you can style the player to your taste and achieve what you see in Figure 5.8 or perhaps something better.

Just when you thought you were finished with this simple media player, you’ll make one final addition to increase its awesomeness—progress bar seek functionality.
NOTE: The code for this styled player and for the unstyled player is available on the website at www.html5multimedia.com.

Friday, May 25, 2012

Creating articles and sections with HTML5

If you write for a living, as I do, you learn to organize content into chunks, and sub-chunks, concepts and sub-concepts, ideas and more detailed ideas, and so on. The basic rule for organizing content in this way is that if you create a sub-section, you have to create two sub-sections. Otherwise, there is no point in creating a sub-section.
In line with our recurring theme of the unity between content and design in HTML5 layout, content in HTML5 pages (where it has to be broken down) is broken down into articles. Moreover, where there is a need for distinct sub-sections within an article, those sub-sections are sections.

As you create a CSS file to match your HTML layout elements, you might well assign specific formatting to articles, and to sections. For example, you might choose to indent section content, or place a unique background behind it. In the following example, article content is set off with a unique background and text color, and within articles, sections are indented.

The code for the <article> and <section> elements in the preceding illustration, including placeholder text and headings is:
<article>
   <h3>First article</h3>
   <p>First article content ....</p>
   <p>more content....</p>
   <section>
        <h3>1st section heading</h3>
        <p>1st section content</p>
   </section>
   <section>
        <h3>2nd section heading</h3>
        <p>2nd section content</p>
   </section>
</article>
Or… you might not apply specific CSS rules to articles and sections, and simply wrap content in the <article> and <section> elements for content organizing purposes, while relying on the <body> tag, the <p> (paragraph) tag, or custom class styles that you define in Dreamweaver for formatting article and section content.

Wednesday, May 23, 2012

Using Comments to Make Code More Readable

To round off this chapter, you learn about another basic feature of PHP: comments . A comment is simply text that is ignored by the PHP engine. The purpose of comments is to let you add messages to yourself (and other programmers) that explain what your code does. It ’ s always a good idea to add comments to your code, even if you ’ re the only programmer working on it. Sometimes code that makes sense when you write it can seem as clear as mud in three months ’ time, so comments can really help!
PHP supports single - line comments and multi - line comments. To write a single - line comment, start the line with either two slashes (//) or a hash symbol (#). For example:
// This code displays the current time
# This code displays the current time
To write multi - line comments, start the comment with a slash followed by an asterisk (/*) and end the comment with an asterisk followed by a slash (*/), as follows:
/*
This code displays the
current time in a nice,
easy-to-read format.
*/
So you might comment the PHP code in the hello_with_time.php script like this:
< ?php
// Get the current time in a readable format
$currentTime = date( “g:i:s a” );
// Display greeting and time to the visitor
echo “Hello, world! The current time is $currentTime”;
? > 

Friday, May 18, 2012

What's CSS1, CSS2 (2.1) and CSS3

CSS1


CSS has been around for quite some time. In fact, CSS1 reached Recommendation level back in December of 1996, which means it began development some time before that. Compared to what designers do with CSS today, CSS1 is quite simple and somewhat limited. But it started web design on its way to using CSS to do some vital positioning and formatting tasks, especially for
  • Backgrounds, margins, borders, and the padding of containers
  • Element attributes such as text color, typefaces, word, letter and linespacing
  • Many other features unsupported (or sorely lacking) in simple HTML and its cumbersome reliance on tables

Although it took some time to catch on, CSS1 brought a lot of options, if you will, to the HTML table. But we really didn’t start to see a major shift to CSS until CSS2. In fact, it wasn’t until the release of IE 5.0 for Mac in March of 2000 that any browser supported better than 99 percent of the CSS1 specification, which was almost two years after the W3C published the Recommendation of CSS2.

If you’re interested in checking out the CSS1 Recommendation, which includes the entire specification itself — something of a CSS1 manual — you can see it on the W3.org website at www.w3.org/TR/REC-CSS1/.

CSS2 (CSS 2.1)


CSS2 is a superset of (that is, it contains) CSS1; the W3C published CSS2 as a Recommendation in May of 1998. Among its most important enhancements are the inclusion of media-specific style sheets, which allows designers to create pages and sites tailored to various devices, such as special access visual browsers, aural devices for the hearing impaired, Braille devices, and mobile handhelds.

CSS2 also provides greater control over the positioning of elements than CSS1. Version 2.1 is the current Recommendation and is widely supported among many smartphones and other mobile devices. See Chapter 5 for the word on how to determine which devices support what CSS versions and to what degree.

You can see the entire CSS 2.1, complete with full documentation, specification at www.w3.org/TR/CSS2/.

CSS3


CSS3, discussed in some detail in Chapter 11, is such a major enhancement that it’s difficult to decide what to talk about first. It makes possible many effects that we now use other programs for — such as drop shadows on text, simple animations, rotating text and other objects, and so much more. This CSS level is truly a maturation of web design technology that’s akin to advancements reached by the desktop publishing industry at the turn of the 21st century.

I’m not saying that designers won’t need Photoshop or Flash anymore, but they won’t find themselves having to create separate files for each simple little effect as often.

Regarding mobile devices, expect to see CSS3 show up in many of the newer smartphones, such as the iPhone, Droid, and some others (though not Windows Phone 7, at least not as I write this). The mobile world, though, does not consist solely of advanced smartphone users. You can’t ignore the users of the millions of not-so-smart phone. It isn’t (ahem) smart.

One of the more exciting features is CSS3, especially for mobile web designers, is a feature called Media Queries. Typically (as discussed in Chapters 4 and 5), when you’re designing for mobile devices in CSS1 and CSS2, you design your style sheets based on device profiles. The result is a static version of the web page based on what’s built into the profile. Instead of working from a profile of what’s known about the device, Media Queries just go ask the device itself about its capabilities. For example: What is your screen
size, orientation, and resolution? Are you in portrait (upright) or landscape (rotated) mode? The answers, along with a whole bunch of other useful info, come back. The style sheet then formats the page accordingly. Chapter 11 looks at some of CSS3’s more exciting features. You can see the CSS3 specification at www.w3.org/TR/css3-roadmap.

If you really want to get a feel for the power behind CSS3, do a search for “CSS3 features” and see what the design community has to say about it. Designers are truly excited and chomping at the bit to use it. For example, check out “22 Handy HTML5 and CSS3 Tools, Resources, and Guides” at www.1stwebdesigner.com/freebies/22-handy-html5-css3-toolsresources-and-guides. 

Figure 2-5 shows a couple of simple text boxes formatted with solely with CSS3.

Wednesday, May 16, 2012

Search engine goodies sitemaps, tools and Site speed

Many search engines provide a number of tools to help webmasters improve the performance of their sites in the search engines, and to help webmasters with the best practices. Google has a number of webmaster tools a collection of tools geared towards helping webmasters manage the errors within their site, and see how Google sees their website—has been developed by Google, and is available for use, freely. Webmasters can also create a sitemap in XML format, to tell Google of all of the pages within our site, their importance within the scheme of the site as a whole, and how frequently they are updated, to help them decide when to return to re-index the updated content.
The webmaster tools in general, outline errors such as duplicate content, duplicate metadata within pages in the same site, as well as broken or forbidden links. More information can be found on the following pages:
  • https://www.google.com/webmasters/tools/home?hl=en
  • http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=40318

Site speed


One very new edition to the list of factors to a sites ranking in search engines is the speed of the site, as announced by Google in April 2010. Sites that take a while to load are penalized. More information can be found on the Google blog:
  • http://googlewebmastercentral.blogspot.com/2010/04/using-site-speedin-web-search-ranking.html
There are a number of tools available to help monitor and improve the speed of your website. Some potential tools include:
  • YSlow from Yahoo!: http://developer.yahoo.com/yslow/
  • Page Speed browser plugin: http://code.google.com/speed/page-speed/
  • Articles on speeding up your site: http://code.google.com/speed/articles/