• Feed RSS

MyWebSql – Open Source & Ajaxed MySQL Manager

MyWebSql – Open Source & Ajaxed MySQL Manager: "
MyWebSql is a web-based and open source MySQL client that is built with PHP.

It has an Ajaxed interface and besides the rows of tables, it can control views, stored procedures, triggers and functions.

MyWebSql

Data can be exported and imported easily (query results can be exported as well).

MyWebSql comes with a syntax highlighting rich-text SQL editor to run queries (the last-ran query is shown automatically which is a nice reminder).

The application is improved frequently and, within time, can become a good alternative to mature solutions.
"
read more

Experiment CSS3 Properties Easily With CSS3 Playground

Experiment CSS3 Properties Easily With CSS3 Playground: "
Mike Plate, a freelance web and mobile developer, has created an impressive CSS3 Playground to help seeing the properties in action easily.

The web application enables you to style a box with a text (that can be resized and re-positioned) with the help of sliders and color-pickers.

Once the properties (like radius, box-shadow, CSS3 transforms, etc.) are updated the result is displayed instantly with the CSS code generated.

CSS3 Playground
"
read more

HTML5 Reset – A Base For HTML5-CSS3 Projects

HTML5 Reset – A Base For HTML5-CSS3 Projects: "
While starting a web project, we usually use a set of resources like CSS-reset, various JS hacks for IE, etc. to overcome browser incompability issues.

HTML5 Reset is a project which aims to offer a base for the HTML5-CSS3 projects which covers these issues by default.

HTML5 Reset

Besides the standard HTML tags, it has rules to reset the new tags like title, header, footer and JavaScript-powered fixes for IE.

The set comes in 2 versions:


  • Bare Bones (stripped down to the essentials)
  • Kitchen Sink (when we want the option to remove features, rather than add them)

"
read more

Feature-Rich, Robust & Professional CMS: Vivvo

Feature-Rich, Robust & Professional CMS: Vivvo: "
Vivvo is a professional and "commercial open source" CMS application that is built with PHP, uses MySQL for storing data and offers a "top-notch" experience.

The application is ready to power any type and size of website from a portal to a newspaper, a blog, etc. as it is already preferred by 1000s of websites.

Vivvo CMS

The CMS comes as a downloadable package to install on your own servers (has a web-based installer) with powerful features for managing the content like publishing articles, static pages, blogs, images, photo galleries, videos, podcasts and keeping revisions of them.

It has the tools to equip any website with functional modules like an event calendar, commenting system, integrated search, ability to show related articles and integrate with popular forum softwares.

Also, the application helps the content to spread with social bookmarking syndication, "email to a friend", print version, subscribe, RSS and more.

Vivvo Admin

Vivvo has an impressive and slick admin interface which has a permission-based user management system where it is possible to define editors, writers, photo gallery managers, members, etc.

It is SEO-friendly in means of the URLs created, ability to customize meta tags/keywords and auto-sitemap generation. And, the 20 free templates that the CMS comes with are all SEO optimized.

Besides these features, it is always to think of something missing. But Vivvo is ready to cover it with 100+ free plugins and widgets (like multi-site manager, Twitter updater) where it is possible to create new ones as the application is open source.

Vivvo is very well documented with user guides, a knowledge base and a highly active community behind it.
"
read more

Best Practices To Design a Perfect HTML Navigation Bar

Best Practices To Design a Perfect HTML Navigation Bar: "
The navigation bar is an inevitable element in every website. In this post I want to share with you some simple practices and suggestions aimed at designing a perfect HTML navigation bar.

Let’s start illustrating the typical HTML structure. Here is a schematization of a typical navigation bar that contains some links:



The HTML code is really simple, nothing more than <div> layer with an unordered list inside. As you probably know, the HTML5 specification introduced a new element that identifies the navigation bar which is the <nav> tag. The <nav> tag substitutes the more general <div> tag but, as you can see in the following code, it doesn’t change the conceptual structure of the navigation bar.


HTML 4 Code


<div id="nav">

<ul>

<li><a href="/index">Home</a></li>

<li><a href="/link1">Link 1</a></li>

<li><a href="/link2">Link 2</a></li>

<ul>

</div>



HTML 5 Code


<nav>

<ul>

<li><a href="/index">Home</a></li>

<li><a href="/link1">Link 1</a></li>

<li><a href="/link2">Link 2</a></li>

<ul>

</nav>



Using an unordered list for organizing the navigation bar is always a good practice to follow especially when you have to implement a little bit more complex interaction between main links and any submenus. Furthermore, this approach allows you to have more control on the CSS code of the various elements that compose the navigation, thus simplifying the customization.



Here is an example of HTML structure for a basic navigation bar with submenus:

<div id="nav"> <!-- nav container -->

<ul>

<li><a href="/link1">Link 1</a> <!-- main item -->

<ul> <!-- item submenu -->

<li><a href="/s-link1">Sub Link 1</a></li>

<li><a href="/s-link2">Sub Link 2</a></li>

</ul> <!-- close submenu -->

</li>

<ul>

</div>

CSS code suggestions


Now take note of the following three simple suggestions for great CSS code. Set the “height” attribute for the tag <li> equal to the height attribute of the <ul> tag:



For a perfect vertical alignment of the text, set the “line-height” attribute for the tag <li> equal to the height attribute of the <ul> tag:



To make the area of your link fully clickable set the attribute “display” of the tag <a> to block:



Interaction with pages


You can create various kind of interactions between the items of the navigation bar and a certain page visited by the user. A simple interaction consists in changing the status of a specific tag to “active”, for example, if the current page is the home page or if the current post is in a specific category which is present in the navigation bar. In the picture, the current post is in the category “Apple” and the tab “Apple” in the navigation bar is “active”.

If you use WordPress you can use the following code for identify the home page and make the “home” tab of your navigation bar “active”:

<?php if(is_home()){ ?>

<li class="active">Home</li>

<?php } else { ?>

<li><a href="<?php echo get_option('home'); ?>">Home</a></li>

<?php } ?>

If you use a category-based navigation bar you can use the following code to highlight a tab of a specific category when the post is in that category. For example, if your navigation bar has a tab “Apple” and the current post is in the category “Apple” you can make the tab “active” using this code:

<?php

global $post;

$categories = get_the_category();

foreach($categories as $category) {

$cat_name = $category->cat_name;

} ?>

<ul>

<?php if(!is_home() && $cat_name=='Apple'){?>

<li class="active-sn">Apple</li>

<?php } else { ?>

<li><a href="<?php echo get_option('home'); ?>/category/apple">Apple</a>

</li><?php } ?>

<ul>

That’s all. If you have any suggestion or feedback please leave a comment!
"
read more

The Most Powerful and Feature Rich Web-Based Code Editors (IDEs)

The Most Powerful and Feature Rich Web-Based Code Editors (IDEs): "
With all the talk of Cloud computing at the moment and after reading a short article on Dzones blog a few months back that questioned whether or not It Was the Right Time for Web-Based IDEs? (it was a split poll), we were inspired enough to venture out and find out what web based IDEs (integrated development environment) are available and which actually are the best. The results were a little bit surprising.
What we found was literally hundreds upon hundreds of different web based editors, tools and generators for every possible language you could think of. The problem was that very few met with the criteria of being the powerful and feature rich IDE we were looking for. A lot of these tools had either not been updated in years or did they pack enough features to be deemed useful or functional in the grander scale. Other tools, look like they may have potential, but development has disappointingly slowed down.
As you may have guessed there have been many attempts at browser based IDE’s over the past few years, so what we have compiled for this article is a selection of IDEs that are not only functional, polished and professional, but are also ready to take the next big step and be the best web based code editing solution. Here is our favorite selection of web-based IDEs:
Reader Opinion: What do you think? Are you ready to take the step and use a web based IDE?

CodeRun – A free, Cross-Platform Browser-Based IDE

CodeRun – A free, Cross-Platform Browser-Based IDE is a free and open-source web based IDE, which features native support for C#/.NET (3.5), PHP (5.1), JavaScript, HTML and CSS. C# support includes ASP.NET, WCF, Silverlight and WPF browser application development and deployment. Database support includes SQL Server 2005 and Amazon SimpleDB.
Syntax coloring and code completion are featured to help you during development. It also features an online debugger that allows you to set breakpoints, step through your code, inspect call stack, and other debugging actions.
You could either use the feature-rich and powerful CodeRun as a complete replacement for your desktop IDE, or you could use it to upload existing code and test it in the cloud or for sharing with your peers.
CodeRun Home →
Demo →
CodeRun Screenshot & Screencast
CodeRun

Bespin

From Mozilla Labs, Bespin aims to be a ‘top-of-the-line text editor that lives in your browser’. It is based on the latest web standards and does require a “modern browser” with support for HTML5 and specifically the Canvas element with the ability to draw text.
Depending on what you’re trying to accomplish and how much time you’re willing to invest, there are several ways in which you can use Bespin: You can try the IDE directly (Bespin demo), download Bespin Embedded for use in your own applications or you can setup your own Bespin server (not for the faint of heart!).
Bespin →
Demo →
Bespin Screenshot & Screencast
Bespin

Kodingen

Kodingen →
Kodingen Screenshot
Kodingen

Amy Editor

The very popular, feature rich and very powerful Amy Editor supports syntax highlighting for multiple languages, opening multiple files in different tabs and features an integrated debugging tool, and even allows you manage multiple projects all from within this web-based editor.
Amy Editor →
Amy Editor Screenshot
Amy Editor

ecoder

ecoder is a simple, web-based code editor, which includes a file browser, file uploader, and tabbed system to allow multiple files to be edited at the same time. using this web-application developers can edit code directly online, real-time syntax highlighting is handled by textarea and keyboard short-cuts lend it the feel of a locally installed application.
ecoder →
Download ecoder via SourceForge →
ecoder Screenshot
ecoder

Codeita

Codeita is a powerful, easy to use, cloud-based, web development environment. It’s a powerful code editor, an advanced svg image editor, and a useful project management and collaboration tool. It allows users to code, develop, brainstorm, communicate and then publish projects and files to your web server. No more hassles with backups and syncing your laptop with your desktop. Or your personal laptop with your business laptop. Complete with code highlighting, local/live editing, project sharing, image editing and more.
Codeita →
Codeita Screenshot
Codeita

ShiftEdit

ShiftEdit is currently under development but is functional. It features most of the things you’d expect from an IDE including built-in FTP, tabbed interface and with support to edit HTML, JS, CSS or PHP files.
ShiftEdit →
ShiftEdit Screenshot
ShiftEdit

Workspace

Workspace is a complete online development environment that gives you complete management of your Web-based projects. With a syntax highlighting editor built right in, you can edit text, PHP, JavaScript, HTML, Java, Perl, SQL and other types of files directly on a remote server. Finding and managing those files is made easy with a cutting-edge file management utility embedded right in the app. With this utility, users can connect to, and manage the files on an arbitrary number of ftp sites simultaneously.
Workspace →
Workspace Screencast

markItUp!

markItUp! is a JavaScript plugin built on the jQuery library. It allows you to turn any textarea into a markup editor. Html, Textile, Wiki Syntax, Markdown, BBcode or even your own Markup system can be easily implemented.
markItUp! is not a web based IDE nor is it meant to be a “Full-Features-Out-of-the-Box”-editor. Instead it is a very lightweight, customizable and flexible engine made to meet the developer’s needs in their CMSes, blogs, forums or websites.
markItUp! →
markItUp! Screenshot
markItUp!

jsFiddle – Online Editor for the Web

jsFiddle is an editor that allows you to you save and run your applications all within the web browser. It currently supports JavaScript, MooTools, jQuery, Prototype, YUI, Glow and Dojo, HTML and CSS.
jsFiddle – Online Editor for the Web →
jsFiddle Screenshot
jsFiddle - Online Editor for the Web

Ideone.com

Ideone is an online compiler and debugging tool which allows you to compile, run, test and share code online in more than 40 programming languages. It also offers access to the free Ideone API which is available as a webservice, with it’s functionality allowing you to build your own ideone-like service.
Ideone.com →
Ideone Screenshot
Ideone.com

CSSDesk

CSSDesk is no where near to being a fully featured IDE, nor does it try to be. What it is is a cool, simple and very easy to use testbed for any CSS and HTML experimentation. Have you ever found yourself needing or wanting to try something out in CSS and HTML but don’t want to open up a text editor and throw together all the pieces to get started? That’s where CSSDesk comes in. Simply edit the placeholder code, and you’ll see the result updated live.
CSSDesk →
CSSDesk Screenshot
CSSDesk

PHPanywhere

PHPanywhere is a complete web based free IDE for the PHP language, in other words it is an application that gives developers all the code editing capabilities they need to develop PHP applications online. It includes a real-time syntax code editor with support for all web formats and a powerful FTP editor.
PHPanywhere →
PHPanywhere Screenshot
PHPanywhere.net

Rendera – HTML5 Editor

Are you struggling with all of the new CSS3 and HTML5 properties and features? Rendera can help. Type in your HTML code and see it rendered in realtime, then style it with CSS using any of the HTML 5 or CSS3 tags that your browser supports.
You may want to learn HAML and SASS, it support those too. You can also try out some Javascript interactions as well. They’ve loaded jQuery, jQuery Tools and jQuery UI so you can experiment with those libraries too.
Rendera – HTML5 Editor →
Rendera Screenshot
Rendera - HTML5 Editor

Drawter.com – DrawAble Markup Language

Drawter is a web based editor (written in JavaScript and based on jQuery library) that quite literally allows you to draw your website’s code, with each tag being presented as a layer you have drawn.
Currently Drawter is available in Pro version (it is still FREE), which means that knowledge of HTML and CSS is essential. The future goal of Drawters development is to build an Amateur version, which will allow you to draw your website without any knowledge of HTML or CSS what-so-ever. Watch out for its launch some time this year.
Drawter.com – DrawAble Markup Language →
Drawter Screenshot
Drawter.com - DrawAble Markup Language

Live Style Sheet Editing!

If all of the above web based editors, plugins and tools are too much for you, how about just playing about with this little tool. Edit the visible stylesheet and few your results live, its more fun than useful, but will certainly relieve development stress!
Live Style Sheet Editing! →
Live Style Sheet Editing! Screenshot
Live Style Sheet Editing!
"
read more

HTML5 Apps: What, Why, and How

HTML5 Apps: What, Why, and How: "
If you want to build web apps, you might want to think about using HTML5. HTML5 is the new hotness when it comes to app development, and it has the potential to change the way software is made and sold. It also activates the millions of people out there who know how to make web pages, and never thought their skill set could be used for something else. But before jumping into development, there are some things you should know about HTML5. In this tutorial, I’ll teach you the basics!



What is HTML5?



HTML5 is a W3C spec in the making.


It started at WHATWG, and is the future gold standard for HTML. If you have been around for awhile, you many know that XHTML 2 was the next major version, but that fell apart. The reasons are varied, but one main point of contention was that few websites use perfect syntax, and XHTML 2 was going to enforce perfect syntax. It has also always been extremely hard to say exactly what perfect syntax is. When the browser vendors realized how hard it was going to be to make the switch to XHTML 2, things just broke down.

At that point a bunch of people broke away from the W3C and started the WHATWG. These guys wanted to rethink not just HTML, but the whole standards making process. They started work on a new HTML5 standard. They operated from the principal that there is no perfect, and it’s not their job to tell the world how to do HTML. Instead they focused on looking at what was happening in the real world of HTML.

They also took the time to codify some conventions that sprung up in the community. That is where a lot of the new elements in the HTML5 spec (like the progress bar, video, and audio tags) came from. People have been making due, and they just wanted to make specific pieces of markup to help people do what they have already been doing.

Besides just markup, the WHATWG started creating some new JavaScript APIs. This is where HTML5 started to look “app”-like. They created standards for offline data storage, and an offline application cache, so that whole apps could be stored offline. They also started new working groups around widgets and device access (for using devices like cameras and accelerometers).


An interesting side note to the whole standards process is this: for awhile the differences in rendering engines were so great that one approach to be cross-browser compliant was to sniff which browser the user was on and deliver a different experience based on that.


The WHATWG and others always thought that browser sniffing wasn’t such a good idea. What is commonly recommend now is progressive enhancement. In a nutshell, progressive enhancement is this. Instead of just deciding that one browser would get experience Y and another would get experience Z, why not detect advanced feature support and build up to a great experience? If, at any point, the browser doesn’t support advanced feature X, the user would just get the default experience.

The Last Numbered Spec


This leads to another point about the HTML5 spec: it will probably be the last numbered spec. In the future, instead of revving HTML versions, like HTML6, the W3C will just maintain the latest version of HTML, and there will be a gold standards spec. Web developers can use progressive enhancement to handle the fragmentation, while waiting for browser vendors to catch-up to the spec.

So What are HTML5 Apps?


With HTML5 defined, what is an HTML5 app?

Essentially, a HTML5 app uses all the shiny, new pieces of the HTML5 draft to create an app-like experience.


This means storing data offline, being functional, and acting like a real app instead of just being content for perusal. You probably use web apps now, like Gmail. Gmail actually has an HTML5 version; if you visit Gmail on an iPhone or iPad, you can check it out.



Why Should I Use HTML5?


Why would I want to use HTML5 instead of Objective-C, Flash, Silverlight, or some other kind of device-specific environment? First, there are a couple reason not to use HTML5.

  1. If I was making the latest, greatest 3D shoot-em-up, I would not use HTML5. It just doesn’t have the rich graphics libraries needed to make intense games like those; however, they are working on standards to allow 3D graphics programs into the browser.
  2. If you need to use the camera on devices, or local files system, HTML5 would not be the best choice. There are workarounds, using a native wrapper, which I will discuss shortly, and there are also some standards coming that will help with that.

While there are specific cases for not using HTML5, many apps that get produced today for iOS and Android could work just as easily in HTML5. Besides just technically being able to do it, there are other good reasons to use HTML5.

You Already Know How to Use It


Right now, if you are a web developer, you have all the tools you need to get into this. HTML5 app development is only little more then changing how you think about webpages. In some instances you can just add a few lines to your HTML, and add some stuff on your server and you will have a full, working, offline HTML5 app.

The more we work with standards, the more useful they become.


Besides, web developers already understand cross-browser problems. While there will be more cross-browser issues than ever, web developers have a distinct advantage over other kinds of developers, because they already have this in their pocket. The other part of cross-browser development is standards. The more we work with standards, the more useful they become. Web developers have led the charge in some respect, and now it’s paying off. Instead of having to learn a whole other non-standards-compliant add-on, you can simply rely on what standards bodies have been working towards.

Finally, when it comes to writing code, it can be difficult to see that you might also be doing something political.

When you look at how a handset manufacturer handles itself, and how it chooses to lock in its developers, by choosing to work outside that system you are supporting the notion of freedom.


It’s a small notion, but it matters, because in the long run we want our handset developers to be open, and let us hack on them as much as we want.



How can I use HTML5?


Actually using HTML5 isn’t that hard. It can range from a couple lines of code, to writing a whole new app. Here are a few ways to get started.



1. Create a Mobile Friendly Website


Many websites are only a few tweaks away from a friendlier mobile experience. The first thing to do is take a look at the viewport.

<html>
<head>
<meta name="viewport" content="user-scalable=no, width=device-width"/>
</head>

The viewport meta tag is not a standard yet, but it is a widely accepted convention. Many mobile browsers use this tag to setup certain aspects of web page rendering.

More info on viewport, check out the following documentation:


Besides just the viewport, make sure that your webpages are flexible; for example, use dynamic widths, instead of static widths. Mobile devices are all shapes and sizes, just like browser windows. Designing with the idea of flexibility in mind will automatically make your web pages more mobile-friendly.

The Doctype


A great little tidbit about the next version of HTML5 is this: the doctype went the way of the dodo. It still has to be there, because of many reasons, but it’s been shriveled to mean almost nothing.

<!DOCTYPE html>

This is awesome. No longer do we have to copy and paste a long string of text, because who can remember that thing, anyway?



2. Take Your Website Offline


Some browsers now implement the application cache. The application cache allows you to tell the browser in advance what resources a web page will need offline. The browser will then download those files for offline usage. When the client goes offline the browser will refer to those cached resources.

The application cache isn’t something that you can do by just changing your markup, though. You will need the ability to change the content-type headers on the server. To do that in Apache, you can either put this in a configuration file, or in a .htaccess file.

AddType text/cache-manifest manifest

Once you do that, you can add the following markup to your html element in your webpage. You can call your manifest anything you want, but make sure it’s at the root of your site, and it ends with a .manifest.

<html manifest="my.manifest">

Then, you can create your manifest file. Simply list all the pieces you will need while you are offline. You can’t put cross-domain files here and you won’t want to list anything that changes often. Here is an example manifest file.

CACHE MANIFEST

# Version 1

my.html
my.css
my.js
my.png

When you have this all setup, check it out in a browser that supports the application cache.

If you need to update a resource, just change the manifest file. Even adding a comment will prompt the browser to update the application cache.

The application cache is notoriously hard to debug. This book has some good methods for checking your application cache status.



3. Make Your Videos Accessible Everywhere


If you host video content on your site, and use a flash player to play it, you’re missing out on an opportunity to display video to people using the iOS devices and phones that don’t support flash (which is most phones).

HTML5 has two new tags that make displaying multimedia easier: audio and video. Here is an example video tag.

<video src="myvideo.mp4" controls />

Now, if you want to support as many browsers as possible, you will need to encode your content in a couple different formats. Then, list them like so.

<video poster="myvideo.jpg" controls>
<source src="myvideo.m4v" type="video/mp4" />
<source src="myvideo.ogg" type="video/ogg" />
<embed src="/to/my/video/player"></embed>
</video>

This makes sure that your content can be seen in Firefox, Safari, Chrome, and mobile phones. Finally, for browsers that don’t support the video tag, you can still fallback to a flash player. When a browser doesn’t support a tag, it will usually just not deal with it, and continue recursing till it finds a tag it does know. In this fashion, if you put the embed or object inside the video tag, a browser like IE will use the object. However, a browser that supports the video tag will ignore the embedded flash.



Conclusion: Start Using HTML5 Tags Today


Tags like header, footer, nav, aside, article, and section are nice because they are semantic. They inform webpage consumers a little bit about your intentions for your content. It’s nice to use them. In the future, they will be more helpful than they are now, but there is nothing to stop you from using them today.

Some browsers, like IE, will “freak out” if you use these new tags, but don’t worry. IE does support adding tag types to the DOM, you just need to inform IE about them. To fix this, Remy Sharp created the HTML5 Shiv. If you include this in the head of your webpage, in an IE conditional comment, your page will render just fine.

Now you are using semantically useful HTML!



Bonus: Sell your Apps in an App Store


Yes, right now, you can take your HTML5 apps and sell them on the mobile app stores. Two projects are helping people develop “native” mobile apps, using nothing more then HTML, JavaScript, and CSS. Check these out:


Alternatively, our very own CodeCanyon, within the next month, will be launching a new category for HTML5 apps. In this category, we’ll be selling everything from advanced and custom video players, to libraries, to presentation apps.

To prepare for the category, we’ve launched a competition with $7000 worth of prizes. You have two weeks left to enter, if that interests you!



Wrapping Up


There should be nothing stopping you from exploring HTML5, and if you wanted to be ahead of the game, you should be building HTML5 apps right now. Thanks for reading!



About the Author


Alex Kessinger is a front-end web developer who currently works for Yahoo!
"
read more

25 HTML5 Features, Tips, and Techniques you Must Know

25 HTML5 Features, Tips, and Techniques you Must Know: "

This industry moves fast — really fast! If you’re not careful, you’ll be left in its dust. So, if you’re feeling a bit overwhelmed with the coming changes/updates in HTML5, use this as a primer of the things you must know.






1. New Doctype



Still using that pesky, impossible-to-memorize XHTML doctype?


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

If so, why? Switch to the new HTML5 doctype. You’ll live longer — as Douglas Quaid might say.

<!DOCTYPE html>

In fact, did you know that it truthfully isn’t even really necessary for HTML5? However, it’s used for current, and older browsers that require a specified doctype. Browsers that do not understand this doctype will simply render the contained markup in standards mode. So, without worry, feel free to throw caution to the wind, and embrace the new HTML5 doctype.



2. The Figure Element



Consider the following mark-up for an image:


<img src="path/to/image" alt="About image" />
<p>Image of Mars. </p>

There unfortunately isn’t any easy or semantic way to associate the caption, wrapped in a paragraph tag, with the image element itself. HTML5 rectifies this, with the introduction of the <figure> element. When combined with the <figcaption> element, we can now semantically associate captions with their image counterparts.

<figure>
<img src="path/to/image" alt="About image" />
<figcaption>
<p>This is an image of something interesting. </p>
</figcaption>
</figure>



3. <small> Redefined


Not long ago, I utilized the <small> element to create subheadings that are closely related to the logo. It’s a useful presentational element; however, now, that would be an incorrect usage. The small element has been redefined, more appropriately, to refer to small print. Imagine a copyright statement in the footer of your site; according to the new HTML5 definition of this element; the <small> would be the correct wrapper for this information.

The small element now refers to “small print.”




4. No More Types for Scripts and Links


You possibly still add the type attribute to your link and script tags.

<link rel="stylesheet" href="path/to/stylesheet.css" type="text/css" />
<script type="text/javascript" src="path/to/script.js"></script>

This is no longer necessary. It’s implied that both of these tags refer to stylesheets and scripts, respectively. As such, we can remove the type attribute all together.

<link rel="stylesheet" href="path/to/stylesheet.css" />
<script src="path/to/script.js"></script>



5. To Quote or Not to Quote.


…That is the question. Remember, HTML5 is not XHTML. You don’t have to wrap your attributes in quotation marks if you don’t want to you. You don’t have to close your elements. With that said, there’s nothing wrong with doing so, if it makes you feel more comfortable. I find that this is true for myself.

<p class=myClass id=someId> Start the reactor.

Make up your own mind on this one. If you prefer a more structured document, by all means, stick with the quotes.



6. Make your Content Editable


Content Editable

The new browsers have a nifty new attribute that can be applied to elements, called contenteditable. As the name implies, this allows the user to edit any of the text contained within the element, including its children. There are a variety of uses for something like this, including an app as simple as a to-do list, which also takes advantage of local storage.

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8">
<title>untitled</title>
</head>
<body>
<h2> To-Do List </h2>
<ul contenteditable="true">
<li> Break mechanical cab driver. </li>
<li> Drive to abandoned factory
<li> Watch video of self </li>
</ul>
</body>
</html>

Or, as we learned in the previous tip, we could write it as:

<ul contenteditable=true>



7. Email Inputs


If we apply a type of “email” to form inputs, we can instruct the browser to only allow strings that conform to a valid email address structure. That’s right; built-in form validation will soon be here! We can’t 100% rely on this just yet, for obvious reasons. In older browsers that do not understand this “email” type, they’ll simply fall back to a regular textbox.

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8">
<title>untitled</title>
</head>
<body>
<form action="" method="get">
<label for="email">Email:</label>
<input id="email" name="email" type="email" />

<button type="submit"> Submit Form </button>
</form>
</body>
</html>

Email Validation

At this time, we cannot depend on browser validation. A server/client side solution must still be implemented.


It should also be noted that all the current browsers are a bit wonky when it comes to what elements and attributes they do and don’t support. For example, Opera seems to support email validation, just as long as the name attribute is specified. However, it does not support the placeholder attribute, which we’ll learn about in the next tip. Bottom line, don’t depend on this form of validation just yet…but you can still use it!



8. Placeholders



Before, we had to utilize a bit of JavaScript to create placeholders for textboxes. Sure, you can initially set the value attribute how you see fit, but, as soon as the user deletes that text and clicks away, the input will be left blank again. The placeholder attribute remedies this.


<input name="email" type="email" placeholder="doug@givethesepeopleair.com" />

Again, support is shady at best across browsers, however, this will continue to improve with every new release. Besides, if the browser, like Firefox and Opera, don’t currently support the placeholder attribute, no harm done.

Validation



9. Local Storage



Thanks to local storage (not officially HTML5, but grouped in for convenience’s sake), we can make advanced browsers “remember” what we type, even after the browser is closed or is refreshed.




“localStorage sets fields on the domain. Even when you close the browser, reopen it, and go back to the site, it remembers all fields in localStorage.”
-QuirksBlog


While obviously not supported across all browsers, we can expect this method to work, most notably, in Internet Explorer 8, Safari 4, and Firefox 3.5. Note that, to compensate for older browsers that won’t recognize local storage, you should first test to determine whether window.localStorage exists.


Support matrix
via http://www.findmebyip.com/litmus/




10. The Semantic Header and Footer



Gone are the days of:


<div id="header">
...
</div>

<div id="footer">
...
</div>

Divs, by nature, have no semantic structure — even after an id is applied. Now, with HTML5, we have access to the <header> and <footer> elements. The mark-up above can now be replaced with:

<header>
...
</header>

<footer>
...
</footer>

It’s fully appropriate to have multiple headers and footers in your projects.


Try not to confuse these elements with the “header” and “footer” of your website. They simply refer to their container. As such, it makes sense to place, for example, meta information at the bottom of a blog post within the footer element. The same holds true for the header.



11. More HTML5 Form Features


Learn about more helpful HTML5 form features in this quick video tip.




12. Internet Explorer and HTML5



Unfortunately, that dang Internet Explorer requires a bit of wrangling in order to understand the new HTML5 elements.


All elements, by default, have a display of inline.


In order to ensure that the new HTML5 elements render correctly as block level elements, it’s necessary at this time to style them as such.

header, footer, article, section, nav, menu, hgroup {
display: block;
}

Unfortunately, Internet Explorer will still ignore these stylings, because it has no clue what, as an example, the header element even is. Luckily, there is an easy fix:

document.createElement('article');
document.createElement('footer');
document.createElement('header');
document.createElement('hgroup');
document.createElement('nav');
document.createElement('menu');

Strangely enough, this code seems to trigger Internet Explorer. To simply this process for each new application, Remy Sharp created a script, commonly referred to as the HTML5 shiv. This script also fixes some printing issues as well.

<!--[if IE]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->



13. hgroup



Imagine that, in my site’s header, I had the name of my site, immediately followed by a subheading. While we can use an <h1> and <h2> tag, respectively, to create the mark-up, there still wasn’t, as of HTML4, an easy way to semantically illustrate the relationship between the two. Additionally, the use of an h2 tag presents more problems, in terms of hierarchy, when it comes to displaying other headings on the page. By using the hgroup element, we can group these headings together, without affecting the flow of the document’s outline.

<header>
<hgroup>
<h1> Recall Fan Page </h1>
<h2> Only for people who want the memory of a lifetime. </h2>
</hgroup>
</header>




14. Required Attribute


Forms allow for a new required attribute, which specifies, naturally, whether a particular input is required. Dependent upon your coding preference, you can declare this attribute in one of two ways:

<input type="text" name="someInput" required>

Or, with a more structured approach.

<input type="text" name="someInput" required="required">

Either method will do. With this code, and within browsers that support this attribute, a form cannot be submitted if that “someInput” input is blank. Here’s a quick example; we’ll also add the placeholder attribute as well, as there’s no reason not to.

<form method="post" action="">
<label for="someInput"> Your Name: </label>
<input type="text" id="someInput" name="someInput" placeholder="Douglas Quaid" required>
<button type="submit">Go</button>
</form>

Required and Placeholder Attributes

If the input is left blank, and the form is submitted, the textbox will be highlighted.



15. Autofocus Attribute



Again, HTML5 removes the need for JavaScript solutions. If a particular input should be “selected,” or focused, by default, we can now utilize the autofocus attribute.


<input type="text" name="someInput" placeholder="Douglas Quaid" required autofocus>

Interestingly enough, while I personally tend to prefer a more XHTML approach (using quotation marks, etc.), writing 'autofocus=autofocus' feels odd. As such, we’ll stick with the single keyword approach.



16. Audio Support


No longer do we have to rely upon third party plugins in order to render audio. HTML5 now offers the <audio> element. Well, at least, ultimately, we won’t have to worry about these plugins. For the time being, only the most recent of browsers offer support for HTML5 audio. At this time, it’s still a good practice to offer some form of backward compatibility.

<audio autoplay="autoplay" controls="controls">
<source src="file.ogg" />
<source src="file.mp3" />
Download this file.
</audio>

Mozilla and Webkit don’t fully get along just yet, when it comes to the audio format. Firefox will want to see an .ogg file, while Webkit browsers will work just fine with the common .mp3 extension. This means that, at least for now, you should create two versions of the audio.

When Safari loads the page, it won’t recognize that .ogg format, and will skip it and move on to the mp3 version, accordingly. Please note that IE, per usual, doesn’t support this, and Opera 10 and lower can only work with .wav files.



17. Video Support


Much like the <audio> element, we also, of course, have HTML5 video as well in the new browsers! In fact, just recently, YouTube announced a new HTML5 video embed for their videos, for browsers which support it. Unfortunately, again, because the HTML5 spec doesn’t specify a specific codec for video, it’s left to the browsers to decide. While Safari, and Internet Explorer 9 can be expected to support video in the H.264 format (which Flash players can play), Firefox and Opera are sticking with the open source Theora and Vorbis formats. As such, when displaying HTML5 video, you must offer both formats.

<video controls preload>
<source src="cohagenPhoneCall.ogv" type="video/ogg; codecs='vorbis, theora'" />
<source src="cohagenPhoneCall.mp4" type="video/mp4; 'codecs='avc1.42E01E, mp4a.40.2'" />
<p> Your browser is old. <a href="cohagenPhoneCall.mp4">Download this video instead.</a> </p>
</video>

Chrome can correctly display video that is encoded in both the “ogg” and “mp4″ formats.


There are a few things worth noting here.

  1. We aren’t technically required to set the type attribute; however, if we don’t, the browser has to figure out the type itself. Save some bandwidth, and declare it yourself.
  2. Not all browsers understand HTML5 video. Below the source elements, we can either offer a download link, or embed a Flash version of the video instead. It’s up to you.
  3. The controls and preload attributes will be discussed in the next two tips.



18. Preload Videos


The preload attribute does exactly what you’d guess. Though, with that said, you should first decide whether or not you want the browser to preload the video. Is it necessary? Perhaps, if the visitor accesses a page, which is specifically made to display a video, you should definitely preload the video, and save the visitor a bit of waiting time. Videos can be preloaded by setting preload='preload', or by simply adding preload. I prefer the latter solution; it’s a bit less redundant.

<video preload>



19. Display Controls


If you’re working along with each of these tips and techniques, you might have noticed that, with the code above, the video above appears to be only an image, without any controls. To render these play controls, we must specify the controls attribute within the video element.

<video preload controls>

Options

Please note that each browser renders its player differently from one another.



20. Regular Expressions


How often have you found yourself writing some quickie regular expression to verify a particular textbox. Thanks to the new pattern attribute, we can insert a regular expression directly into our markup.

<form action="" method="post">
<label for="username">Create a Username: </label>
<input type="text"
name="username"
id="username"
placeholder="4 <> 10"
pattern="[A-Za-z]{4,10}"
autofocus
required>
<button type="submit">Go </button>
</form>

If you’re moderately familiar with regular expressions, you’ll be aware that this pattern: [A-Za-z]{4,10} accepts only upper and lowercase letters. This string must also have a minimum of four characters, and a maximum of ten.

Notice that we’re beginning to combine all of these new awesome attributes!

If regular expressions are foreign to you, refer here.



21. Detect Support for Attributes


What good are these attributes if we have no way of determining whether the browser recognizes them? Well, good point; but there are several ways to figure this out. We’ll discuss two. The first option is to utilize the excellent Modernizr library. Alternatively, we can create and dissect these elements to determine what the browsers are capable of. For instance, in our previous example, if we want to determine if the browser can implement the pattern attribute, we could add a bit of JavaScript to our page:


alert( 'pattern' in document.createElement('input') ) // boolean;

In fact, this is a popular method of determining browser compatibility. The jQuery library utilizes this trick. Above, we’re creating a new input element, and determining whether the pattern attribute is recognized within. If it is, the browser supports this functionality. Otherwise, it of course does not.

<script>
if (!'pattern' in document.createElement('input') ) {
// do client/server side validation
}
</script>

Keep in mind that this relies on JavaScript!



22. Mark Element



Think of the <mark> element as a highlighter. A string wrapped within this tag should be relevant to the current actions of the user. For example, if I searched for “Open your Mind” on some blog, I could then utilize some JavaScript to wrap each occurrence of this string within <mark> tags.

<h3> Search Results </h3>
<p> They were interrupted, just after Quato said, <mark>"Open your Mind"</mark>. </p>




23. When to Use a <div>


Some of us initially questioned when we should use plain-ole divs. Now that we have access to headers, articles, sections, and footers, is there ever a time to use a…div? Absolutely.


Divs should be utilized when there’s no better element for the job.


For example, if you find that you need to wrap a block of code within a wrapper element specifically for the purpose of positioning the content, a <div> makes perfect sense. However, if you’re instead wrapping a new blog post, or, perhaps, a list of links in your footer, consider using the <article> and <nav> elements, respectively. They’re more semantic.



24. What to Immediately Begin Using



With all this talk about HTML5 not being complete until 2022, many people disregard it entirely – which is a big mistake. In fact, there are a handful of HTML5 features that we can use in all our projects right now! Simpler, cleaner code is always a good thing. In today’s video quick tip, I’ll show you a handful of options.





25. What is Not HTML5



People can be forgiven for assuming that awesome JavaScript-less transitions are grouped into the all-encompassing HTML5. Hey — even Apple has inadvertently promoted this idea. For non-developers, who cares; it’s an easy way to refer to modern web standards. However, for us, though it may just be semantics, it’s important to understand exactly what is not HTML5.

  1. SVG: Not HTML5. It’s at least five years old.
  2. CSS3: Not HTML5. It’s…CSS.
  3. Client Storage: Not HTML5. It was at one point, but was removed from the spec, due to the fact that many worried that it, as a whole, was becoming too complicated. It now has its own specification.
  4. Web Sockets: Not HTML5. Again, was exported to its own specification.

Regardless of how much distinction you require, all of these technologies can be grouped into the modern web stack. In fact, many of these branched specifications are still managed by the same people.



Thanks for reading! We’ve covered a lot, but have still only scratched the surface of what’s possible with HTML5. I hope this served as a helpful primer!
"
read more

Who Needs University? The Best Nettuts+ Screencast Training Courses

Who Needs University? The Best Nettuts+ Screencast Training Courses: "

Education is expensive…very expensive! But, luckily, 95% of the tutorials and courses on Nettuts+ are free! And, should you require more training, a Tuts+ premium subscription is extremely cheap, at only $9 per month. Whether you’re hoping to learn jQuery, WordPress, CSS, Tumblr, PHP, CodeIgniter, or JavaScript, we’ve got you covered! Further, if screencasts are your thing, you’re particularly in luck, thanks to our in depth video courses, listed below!







1. Diving Into PHP



Diving Into PHP

Just as with the “jQuery for Absolute Beginners” series, you’ll start from scratch and slowly work your way up to some more advanced PHP topics; this is another incredible series that first aired on the ThemeForest Blog.

The Complete Series






2. Magento for Designers



Magento for Designers

Magento is a stunningly powerful e-commerce platform. In celebration of ThemeForest’s new Magento category, this mini-series will you teach how to get started with the platform: you’ll get to know the terminologies and learn how to set up a store and all related aspects of it; finally you’ll learn how to customize it to make it your very own.

The Complete Series






3. JavaScript from Null



JavaScript from Null (Premium)

Thanks to the wide adoption of libraries like jQuery and Mootools, JavaScript’s popularity has skyrocketed in the last few years. However, in the process, an interesting thing occurred: many newer developers are learning these libraries without taking the time to actually learn about raw JavaScript techniques. What percentage of jQuery users don’t know how to fade out an element with only raw JS? My guess is that it’s much higher than many would think.

If you want to truly understand the library you’re working with, and improve your skill-set, it’s vital that you learn the fundamentals of raw JavaScript. And this series will teach you what you need to know!

The Complete Series






4. Tumblr Theme Design – Start to Finish (Premium)



Tumblr Theme Design – Start to Finish (Premium)

Tumblr’s popularity over the last year has increased exponentially. The reason why is quite simple: Tumblr is flexible, powerful, and, most importantly, a pleasure to work with. Unfortunately, there aren’t many training resources available for the platform yet. In this video series, we’ll go through the process of taking a Tumblr theme, designed in Photoshop, and converting it into a fully working theme – in just a few hours.

The Complete Series


If you’re not already a Nettuts+ Premium member, you’ll want to sign up to get this course. You can view an introduction to it here.

  • Chapter 1: Intro
  • Chapter 2: Slicing the Design
  • Chapter 3: Creating the Markup and Adding the Tumblr Template Tags
  • Chapter 4: Adding the CSS
  • Chapter 5: Configuration Options
  • Chapter 6: @Font-Face and Custom Fonts
  • Chapter 7: Slide-out Panel – HTML and CSS
  • Chapter 8: Slide-out Panel – jQuery




5. CodeIgniter from Scratch



CodeIgniter from Scratch

After numerous requests, we launched a new screencast series on Nettuts+ that will focus exclusively on the CodeIgniter PHP framework. Over the course of 15 videos (so far!), you’ll learn how to use this framework.

The Complete Series






6. Regular Expressions for Dummies




If there’s one topic that most people agree is difficult to get into, it’s regular expressions. But fear not: you’ll get comfortable using this sometimes-confusing technology with these five screencasts.

The Complete Series


You can see the whole series here, and this is what you’ll get:





7. CSS: Noob to Ninja (Premium)




This exclusive premium video series will take you from a state of absolute CSS “noobness,” all the way up to ninja-status, capable of taking advantage of the latest CSS3 techniques. The series begins with the basics: the syntax, properties, etc. However, each new video expands upon the previous, as you work your way up and improve your skills.

The Complete Series


This series is for Premium members, but if you aren’t familiar with CSS, there’s no better way to learn! Get it here!

  • Part 1: Preparation
  • Part 2: CSS Properties
  • Part 3: Typography
  • Part 4: Floats
  • Part 5: Positioning
  • Part 6: Semantics, List Items, and Menus
  • Part 7: CSS Organizational Techniques
  • Part 8: Rounded Corners, Box Shadows, and Text Shadows
  • Part 9: CSS3 Gradients
  • Part 10: Custom Fonts with @font-face
  • Part 11: Taking Advantage of CSS Frameworks
  • Part 12: Extending CSS with LESS



8. jQuery for Absolute Beginners



jQuery for Absolute Beginners

So, everywhere you look, you see “jQuery this” and “jQuery that.” For the last year or so, this library has been the darling of the JavaScript world. But do you feel that you just can’t seem to learn the dang thing? Do you hate how the existing tutorials assume that you know WAY more than you actually do? If this rings true for you, I can help: check out the jQuery for absolute beginners series that first showed on the old ThemeForest Blog, and has since joined the Nettuts’ arsenal.

The Complete Series






9. WordPress for Designers




If you want to get into the WordPress community, we’ve got a great way to start: the WordPress for Designers series, from the old Themeforest Blog. You’ll learn everything from installing the platform to slicing a PSD file and turning it into a complete theme.

The Complete Series





10. The Ultimate Guide to Creating a Design and Converting it to HTML and CSS


The Ultimate Guide to Creating a Design and Converting it to HTML and CSS


This was a multi-part series across the Tuts+ sites, which demonstrated how to build a beautiful home page for a fictional business. We learned how to create the wireframe on Vectortuts+; we added color, textures, and effects on Psdtuts+; and we took our completed PSD, and converted it into a nicely coded HTML and CSS website.


The Complete Series





You’ll be a Pro in No Time!


Well, now you’re well on your way to becoming a well-trained web developer. What’s your favorite tutorial here on Nettuts+? Let us know in the comments!

If you enjoyed these screencasts over the last year or so, and would like to give back to Nettuts+, please do consider signing up for a Premium Tuts+ subscription. In addition to helping us out, you’ll gain access to source files, extra advanced tutorials and video series, and freebies…from all of the Tuts+ sites!
"
read more

Building Persistant Sticky Notes with Local Storage

Building Persistant Sticky Notes with Local Storage: "
HTML5 local storage is like cookies on steroids; it’s incredibly simple to use and yet still so powerful. In this tutorial, I’ll show you how to create “sticky notes” functionality, that allows your users to take persistent notes while browsing your site.





Step 1: The HTML


Because of the dynamic nature of this project, there isn’t really much to code in the way of regular old semantic markup. We’ll just simulate a web page by putting together some filler content:

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>HTML 5 complete</title>
<link rel="stylesheet" href="default.css" />
<link rel="stylesheet" href="stickies/stickies.css" />
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<article>
<header>
<h1> Sample Article Title</h1>
</header>
<p>Lorem ipsum dolor. . . </p>
<!-- a few lorem-ipsum paragraphs later . . . -->
<footer>
<p>Copyright 2010 Andrew Burgess</p>
</footer>
</article>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js"></script>
<script src="json2.js"></script>
<script src="stickies/stickies.js"></script>
<script>
</script>
</body>
</html>

There are a few important things to notice here: we’re including two CSS files: the first one is the simple styling for the page, which we’ve called default.css. Then, we’ve got a special CSS files for styles relating to our sticky notes; it’s called stickies.css, and as you can see, it lives in the “stickies” folder. At the bottom, we’re including four scripts:

  • jQuery, from Google’s CDN
  • JQuery UI, from Google’s CDN
  • JSON2, from Douglas Crockford
  • Our own stickies.js, which lives in the “stickies” directory

Then, we’ve got an empty script tag that we’ll use to start the engine a bit later.

And that’s it for HTML!



Step 2: The CSS


The contents of default.css is incredibly simple:

body {
margin:0;
padding:0;
background:#ccc;
font:14px/1.5 "Helvetica Neue", Helvetica, Arial, san-serif;
}
article, footer, header { display: block; }
article {
width:880px;
background:#fff;
margin:auto;
padding:40px;
}
article header {
color:#474747;
border-bottom:1px solid #474747
}
article footer {
font-size:90%;
color:#ccc;
}

That’s it; now, there’s the CSS from stickies.css to look after … but we don’t have that markup yet. So let’s start some JavaScript, and when that’s done, we’ll look at the CSS for the sticky notes.



Step 3: The JavaScript


Here’s the skeleton for our JavaScript application:

var STICKIES = (function () {
var initStickies = function () {},
openStickies = function () {},
createSticky = function (data) {},
deleteSticky = function (id) {},
saveSticky   = function () {},
markUnsaved  = function () {};

return {
open   : openStickies,
init   : initStickies
};
}());

We’ve got a few interesting techniques going on here. First is the self-involking function: it might look like we’re assigning a function to the variable STICKIES, but if you look closely at the end of the function, you’ll see that we’re running it right away. As a hint—to remind us that this isn’t a normal function—we’re wrapping the entire function in parentheses. So, STICKIES isn’t a function, it’s the returned value from that function, which is an object, in this case.

That brings us to the next technique: closure. Notice that of the six functions we create, only two of them are exposed to the user (really, only one is necessary for the usage we’re planning; if we wanted to build support for creating notes into your website, we could expose the createSticky and deleteSticky). Even though the self-involking function finishes executing before we even use the methods, we’ll be able to use the other functions that we’ve defined.

Okay, let’s move on to the content of these function.



initStickies


We’ll start by looking at the initStickies function:

var initStickies = function initStickies() {
$("<div />", {
text : "+",
"class" : "add-sticky",
click : function () { createSticky(); }
}).prependTo(document.body);
initStickies = null;
},

This is pretty simple. We’ll be using jQuery to create elements quite a bit, and we’re using some special syntax in v. 1.4: that’s passing an object literal with the specs for the element as a second parameter to the jQuery function. Here, we’re creating a button to create a new note. That mean we need a new div; we’re setting the text to ”+” and giving it a class “add-sticky”; then, we’re setting a click handler to call the createSticky method (it’s important to call createSticky from inside a function, and not have the click handler call directly to createSticky; this is because createSticky can take a single parameter, and we don’t want that to be the event object). Finally, we’re prepending this div to the body. We end by setting initStickies to null; yes, we’re essentially getting rid of the function that we’re running. This assures us that this function will only be run once; we don’t want the user of our API to inadvertantly add multiple “add note” buttons to page.

openStickies


Let’s move on to the next method, openStickies:

openStickies = function openStickies() {
initStickies && initStickies();
for (var i = 0; i < localStorage.length; i++) {
createSticky(JSON.parse(localStorage.getItem(localStorage.key(i))));
}
},

We start by running initStickies … but what’s with the fancy syntax? Well, you’re probably familiar with && operator: the boolean AND operator. You’d usually use it to check multiple conditions in an if-statement. Here’s what it actually does: it evaluates the first expression, and if that comes out true, it will go on to evaluate the second expression. In this case, if initStickies has not been set to null yet, we’ll run the function. This avoids the error that would come from trying to run a null variable as a function.

Next, we’re looping over each item in localStorage. Here’s what we do in that for-loop (from inside to outside):

  • localStorage.key() is a great function that returns the key name of localStorage value; it takes a number as a paramter. It’s a great way to loop over each item in localStorage.
  • Once we have the key for a stored item, we can pass it to localStorage.getItem() to get its value.
  • Then, we pass that value to JSON.parse(); this comes from Crockford’s library. Because we’re storing a few values for each note, we’re using JSON.stringify() on the other end to turn an object into a JSON string, which we store. Here, we’re converting it from a string back into an object.
  • Finally, we pass that object to createSticky(), which turns it back into a sticky note.

createSticky


Now, let’s look at that createSticky method.

createSticky = function createSticky(data) {
data = data || { id : +new Date(), top : "40px", left : "40px", text : "Note Here" }

return $("<div />", {
"class" : "sticky",
'id' : data.id
})
.prepend($("<div />", { "class" : "sticky-header"} )
.append($("<span />", {
"class" : "status-sticky",
click : saveSticky
}))
.append($("<span />", {
"class" : "close-sticky",
text : "trash",
click : function () { deleteSticky($(this).parents(".sticky").attr("id")); }
}))
)
.append($("<div />", {
html : data.text,
contentEditable : true,
"class" : "sticky-content",
keypress : markUnsaved
}))
.draggable({
handle : "div.sticky-header",
stack : ".sticky",
start : markUnsaved,
stop  : saveSticky
})
.css({
position: "absolute",
"top" : data.top,
"left": data.left
})
.focusout(saveSticky)
.appendTo(document.body);
},

Yes, it’s long, but it’s not going to be too hard. First, notice that this function takes a data object; as we just saw in openStickies, we’re passing the stored data to this function. However, if we aren’t passing in any data (i.e., we’re creating a brand new note), we’ll create the default note object. Since all notes have to be created at one point, all notes will start with this configuration. Notice that for the note id, we’re using +new Date(); that prepended unary plus operator converts the date we get from new date to a number, so this statement results in a number representing the number of milliseconds since January 1, 1970. Obviously, this number will be continually changing, so it’s a great way to uniquely identify each note.

The rest of the function is a long string of chained jQuery methods. Before we go through this, notice that we’re returning the result. If we exposed this method to developers using our mirco-API, it would return a reference to the sticky note div element.

So, here’s what’s going on:



  • First, we create the div that is the shell of the sticky note. Using that helpful jQuery 1.4 syntax, we give it a class of “sticky” and the id from the data object.



  • Then, we prepend a div to that one; this div gets a class “sticky-header”. div.sticky-header then gets two spans appended to it. The first, span.sticky-status, gets a click handler that calls the saveSticky function. However, that’s actually a hidden feature: this span will display the status of the sticky: saved or unsaved. There will be a few ways the sticky saves its data to localStorage; it’s possible that the user will think that clicking ‘unsaved’ will save the note, so we’ll provide them with that functionality. The second span, span.close-sticky, will be the delete button: when the user clicks it, we’ll remove the sticky from localStorage, via the deleteSticky method. We pass that method the note id.



  • Next, we’re appending another div to the main div.sticky; notice that we set the html property to data.text; when we save the note’s text, we’re using jQuery’s html() method, because using text() gets rid of line-breaks. We also set contentEditable:true on this div, because it’s the content of the note. As such, it also gets the class sticky-content. Finally, when a key is pressed on this div (meaning the user is changing the content), we want to mark it as unsaved, so we’ll call that function (which we’ll make soon).



  • Now, we’re using the jQuery UI draggable feature to make our sticky note moveable. In our parameter object, we’re using the handle property to make our notes only movable from the header bar. The stack property is a selector for the draggable elements to want to “stack”; by setting this, the currently dragged note will always come to the top. Finally, when we start dragging the note, we want to mark it as “unsaved” (because we have to save its coordinates, too), and when we stop dragging, we’ll save that sticky.



  • Next, we’re setting some styles for our div.sticky; we position it absolutely, and then set its top and left values to the ones in the data object. This way, the note will keep its position as well as its content when we refresh the page.



  • Finally, we’ll set an event handler for when we focusout of the sticky (essentially, click outside it after clicking inside it): we want to save the sticky. Lastly, we’ll append it to the body. For reference, here’s the html structure that we should have generated:

<div class="sticky ui-draggable" id="1281194825332" style="position: absolute; top: 40px; left: 40px;">
<div class="sticky-header">
<span class="sticky-status"></span>
<span class="close-sticky">trash</span>
</div>
<div contenteditable="true" class="sticky-content">
Note Here
</div>
</div>

And that’s our createSticky function.

deleteSticky


Now we have the deleteSticky function; it’s really simple:

deleteSticky = function deleteSticky(id) {
localStorage.removeItem("sticky-" + id);
$("#" + id).fadeOut(200, function () { $(this).remove(); });
},

As you recall, the deleteSticky function takes the id of a note as its parameter. localStorage.removeItem() is the method of the hour: we pass it the key to a locally-stored value to remove that key-value pair (Notice that when we store the note data, we’re prepending “sticky-” to the id). Then, we find the element with the given id, fade it our, and remove it. Note deleted!

saveSticky


Second-to-last might be the most important method today: saveSticky: this is the glue that makes it all work.

saveSticky = function saveSticky() {
var that = $(this),  sticky = (that.hasClass("sticky-status") || that.hasClass("sticky-content")) ? that.parents('div.sticky'): that,
obj = {
id  : sticky.attr("id"),
top : sticky.css("top"),
left: sticky.css("left"),
text: sticky.children(".sticky-content").html()
}
localStorage.setItem("sticky-" + obj.id, JSON.stringify(obj));
sticky.find(".sticky-status").text("saved");
},

The first line is a bit of resolution: there are three different elements we can call this function from. First, we’ll “jQuerify” this into that; then, if the element has either the “sticky-status” or “sticky-content” classes, we’ll get the parent div.sticky; if it doesn’t have either of those classes, then it’s div.sticky itself, so we’ll just use that.

Then, we need to get the values we want to store. As you can see, we’re getting the id, offset from the top and left, and the html of the child .sticky-content; remember, we’re using html() instead of text() because we want to keep the line breaks. Then, we use localStorage.setItem to store the data. Remember, it takes two parameters: the key and the value to store. Since localStorage only stores strings, we use JSON.stringify() to convert the object to a string.

Lastly, change the sticky status to “saved.”

markUnsaved


We’ve got one last function, which is just a helper function:

markUnsaved = function markUnsaved() {
var that = $(this), sticky = that.hasClass("sticky-content") ? that.parents("div.sticky") : that;
sticky.find(".sticky-status").text("unsaved");
}

Again, we have to start by resolving the reference to div.sticky; once we do, we can simply find the status span and set the text to “unsaved.”

Believe it or not, that’s all the JavaScript.



Step 4: The CSS, Revisited


Now that we know what our sticky note markup is, we can style it. It’s pretty simple; but look it over, and I’ll make a few comments at the end:

:focus {
outline:0;
}
.add-sticky {
cursor: default;
position:absolute;
top:1px;
left:1px;
font-size:200%;
background:#000;
color:#fff;
border:2px solid #fff;
border-radius:40px;
-webkit-border-radius:40px;
-moz-border-radius:40px;
text-align:center;
line-height:25px;
width:30px;
height:30px;
}
.add-sticky:hover {
background: #474747;
}
.sticky {
width:300px;
background:#fdfdbe;
box-shadow:3px 3px 10px rgba(0,0,0,0.45);
-webkit-box-shadow:3px 3px 10px rgba(0,0,0,0.45);
-moz-box-shadow:3px 3px 10px rgba(0,0,0,0.45);
}
.sticky-content {
min-height:150px;
border-left:3px double rgba(238, 150, 122, .75);
margin-left:30px;
padding:5px;
}
.sticky-header {
padding:5px;
background:#f3f3f3;
border-bottom:2px solid #fefefe;
box-shadow:0 3px 5px rgba(0,0,0,0.25);
-webkit-box-shadow:0 3px 5px rgba(0,0,0,0.25);
-moz-box-shadow:0 3px 5px rgba(0,0,0,0.25);
}
.sticky-status {
color:#ccc;
padding:5px;
}
.close-sticky {
background:#474747;
float:right;
cursor:default;
color:#ececec;
padding:1px 5px;
border-radius:20px;
-webkit-border-radius:20px;
-moz-border-radius:20px;
}

There are a few points of interest here:

  • Some browsers put an outline around elements with contenteditable=true when you’re editing the content. We don’t want that, so we’re getting rid of it with our :focus declaration.
  • The “Add Sticky” button is positioned in the upper-left corner; it looks vaguely similar to the “Add Dashboard Widget” in Mac OS X.
  • We’re using the border-radius and box-shadow CSS3 properties (and their appropriate vendor-prefix incarnations).
  • We’re also using rgba() for our shadow colours. It takes four parameters: the red, greed, and blue colours, and the alpha (transparency) value.

Other than that, it’s just your standard CSS. Here’s what a styled note should look like:

Note



Step 5: Starting The Stickies


Now that we’ve made our API, it’s time to get it started; we can do that from the extra empty script tag in our index.html file:

STICKIES.open();

Conclusion: The Final Product


Well, we’re done! Here’s the final product in action:




That’s all I’ve got for today; how do you plan to use HTML5 local storage to spice up your web projects? Let me know in the comments!
"
read more