JSDoc: How to document your JavaScript

Monday, March 2nd, 2009 | Business, Tutorials | No Comments

JSDoc is meant to do for Javascript, what Javadoc does for Java.

It does.  

You can download and install JSDoc easily:

  1. Download JSDoc
  2. Expand the tgz.gz file (I use Winrar)
  3. Optional – I copy the jsdoc folder to my C: drive to make things easier
  4. Reminder – you need a perl runtime installed.  ActivePerl is recommended
  5. Open up a command prompt 
  6. Change to your JSDoc folder (mine is c:\JSDoc-1.10.2\)
  7. Run it: “perl jsdoc.pl test.js” (to test it against the built in JS file)

Usage of JSDoc is as simple as Javadoc was.  An example of usage taken from the official JSDoc page is below:
[sourcecode language=’jscript’]/**
* Shape is an abstract base class. It is defined simply
* to have something to inherit from for geometric
* subclasses
* @constructor
function Shape(color){
this.color = color;

// Bind the Shape_getColor method to the Shape class
Shape.prototype.getColor = Shape_getColor;

* Get the name of the color for this shape
* @returns A color string for this shape
function Shape_getColor(){
return this.color;

* Circle is a subclass of Shape
function Circle(radius){
this.radius = radius;

* A very rough value for pi
Circle.PI = 3.14;

* Get the radius of this circle
* @returns The radius of this circle
function Circle_getRadius(){
return this.radius;

// Circle is a subclass of Shape
Circle.prototype = new Shape(null);

You can use the reference on the official site to learn about more of the “@” attributes you can use for JSDoc.  

The example code is here:

Tags: , , , , , ,

Illustrator Tutorial: Create a vector RSS Icon (a la web 2.0)

Thursday, February 19th, 2009 | Business, Tutorials | No Comments

Test IconNot being an artist or designer by default (I do some design by usually by applying formulas — I find a completely deterministic experince, a happier experience), I attempted to learn more about all those pretty graphics we see out there these days.  

I grew up in Photoshop, and have recently been “seeing the light” of Adobe Illustrator.  Don’t get me wrong, I’ve used Illustrator for quite a while, but I’m just now learning all the various tools that I need to know.  

See the icon in this article?  I made it.  All by myself.  Of course with the aid of an excellent tutorial:

Spoon Graphics BlogCreate a Vector RSS Icon with Illustrator

Tags: , , , , , , ,

Introduction to JSON (JavaScript Object Notation)

Wednesday, February 18th, 2009 | Business, Tutorials | 3 Comments

JSON, JavaScript Object Notation, is a very useful tool for AJAX developers (and many others I’m sure).

XML is fairly difficult for JavaScript to parse out.  It also includes quite a bit of infrastructure overhead in certain applications.  

Implementation of JSON can be very easy, it is imported natively in JavaScript through the eval() procedure.  It is also supported by many server side languages.

Lets take a basic example of an XML statement and see it’s JSON equivalent:

<book id=”123″><author>Tom Jones</author></book>

{“book”: {“id”:”123″, “author”:”Tom Jones”}}

It may seem more cryptic, but if you look, that’s just because there are fewer iterations of key words.  The compression gets extended when you implement longer arrays of data.

The best part about JSON, in my opinion, is the speed increase you get when using it in javascript.  Please implement something in XML and JSON with the same data, you will notice a significant performance increase.

JSON is easy to consume in JavaScript:

objJSON = eval(jsonDataFeed);

You can access data (using our example earlier):


Server side implementation can be quite simple as well:

$dataObject = array();
$dataObject["book"] = array();
$dataObject["book"]["id"] = 123;
$dataObject["book"]["author"] = "Tom Jones";
echo (json_encode($dataObject));

Ask any questions in the comments below.  

Here are some articles to continue your exploration of JSON:

Tags: , , , , , , ,

Basic AJAX Tutorial: Smooth Scrolling Text Marquee with a jQuery plugin

Monday, January 26th, 2009 | Business, Tutorials | 72 Comments

This tutorial covers:

  • What is a plugin?
  • Installing a plugin
  • The jQuery Marquee plugin
  • Implementing the jQuery Marquee plugin

What is a plugin?
A plugin is an addition to the core jQuery functionality.  Plugins are made to be simply integrated into an existing jQuery web page.

For this tutorial, we will be working with the jQuery Marquee plugin from remy sharp’s b: log.  Take a look, he did a good job putting his post together.

Installing a plugin
Installing plugins is very easy.  This is the easiest part of working with all plugins.

Pretty much:

  1. Download the plugin
  2. Upload the plugin to your server
  3. Include the plugin in your document

First, download the jQuery Marquee plugin here (taken from the original post, The Silky Smooth Marquee).  If it just displays in your browser, right click on the link and select “Save Link As…”.

Now that we have the plugin, we just need to post it on our site.  Upload it to your javascript folder (I normally use “/js” for this).

Finally we need to include the JS library in your document, so we add the following line (into a very basic document):

     <script language="javascript" src="js/jquery.js"></script>
     <script language="javascript" src="js/jquery.marquee.js"></script>


It’s uploaded!

The jQuery Marquee plugin
Whenever working with a plugin, normally the plugin page has helpful instructions on it’s use, and examples.  In this case that is true.

Again, I’m going to link back to the original page — The Silky Smooth Marquee.

On that page the author has detailed:

  • Demo
  • Download
  • Usage
  • How it works
  • Events
  • Support

Very helpful.  Additionally, it helps to look and see if there are any useful comments.  Usually commenters point out minor flaws in the code posted (or major!), and supply resolutions.  If you follow the conversation thread on the post, you will see commenters have requested functionality that was implemented back into the plugin.

Implementing the jQuery Marquee plugin
Now the final part.  This is both easy and hard.  The easy part is usually getting the basic implementation working.  The hard part comes in when you try to do exactly what YOU want to do with THEIR plugin example.  Usually it can be done.  Sometimes there are minor modifications that have to be made to the original plugin.

Once you have added the library, all you need to do is include the code.  There is a great example page, jQuery Marquee Demo, that shows the various implementations.

For our purposes we’ll implement a basic marquee on our page:

     <script language="javascript" src="js/jquery.js"></script>
     <script language="javascript" src="js/jquery.marquee.js"></script>
     <marquee behavior="scroll" direction="up" scrollamount="1"
          height="75" width="150">
          <p>This is a test of a Smooth Marquee using jquery.</p>
          <p>This is a test of a Smooth Marquee using jquery.</p>
          <p>This is a test of a Smooth Marquee using jquery.</p>

The plugin automatically binds to the marquee tag.  Does yours work?  Check out our example of jQuery scrolling text marquee.

That was too easy?

Yes.  If you look at the comments, one common request is to adjust the scroll speed.  You can see that our scrollamount is already set to the minimum, 1.

The author recommended setting the timeout (refresh rate) to a larger number.  By default, it is set to 25ms.  If we wanted to go twice as slow, we just have to change that to 50ms.  This is where modifying the core code of the plugin comes in.  If you want to go ahead and do this:

  1. Open up the jquery.marquee.js file.
  2. Find the line: “setTimeout(animateMarquee, 25);”
  3. Change it to: “setTimeout(animateMarquee, 50);”
  4. Upload the new jquery.marquee.js file

The sky is the limit.

Please give us feedback on this tutorial, also take some time to thank the author of this plugin, Remy he’d probably appreciate a follow on Twitter, or even a comment on his blog.

Tags: , , , , , , ,

How to link to iTunes: iTunes Link Maker

Friday, January 23rd, 2009 | Tutorials | 11 Comments

I was just about to write a post about an album I’ve been listening to, and an audiobook I just finished “reading”.

I wanted to know how I could link directly to those items in iTunes.  Here’s how..

iTunes Link Maker

An official tool by Apple, it lets you find items in iTunes and link to them.

First you must enter the item you are searching for (I usually leave it as all media):

Apple iTunes Link Maker

Once you hit search, you see a results screen where all matching items are listed.  Click the arrow to the right of what you want to link to (keep in mind, clicking on the arrow next to an artist, will link to that artists page):

Apple iTunes Link Maker

Finally you get the HTML to copy from the page, and insert into your document!

Apple iTunes Link Maker


Recently I’ve discovered there’s a way to setup these links as an affiliate, to make 5% commission off sales made through your blog links.  Check out my article, iTunes Link Affiliate: How to Make Money Linking to iTunes Music

Tags: , , , , ,

Basic AJAX Tutorial: jQuery toggle and slide

Wednesday, January 21st, 2009 | Business, Tutorials | 20 Comments

In this tutorial we will review:

  • Definition of AJAX
  • Introduction to jQuery
  • Basic document jQuery preparation
  • Binding jQuery actions to an anchor (A) tag
  • Toggling visibility of a div
  • Sliding in and out of that div

It sounds like a lot, but it’s all very easy.

Definition of AJAX
The term AJAX means Asynchronous JavaScript and XML.  That means AJAX technically defines a method for javascript to communicate with XML.  Over the past few years AJAX has been interpreted as a means for implementing all “web 2.0” functionality in the front end.  That added things like animations to the general term “AJAX”.

Introduction to jQuery
jQuery is one of my favorite libraries with a good toolset for working with AJAX techniques.  You can find out more information on jQuery at their site.

jQuery is a “fast and concise Javascript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development”.  Taken from the website itself.

As a javascript library, we will have to include the jQuery library on a page, and implement some of it’s more basic functions.

Basic jQuery document preparation
The first thing we need to do is incorporate the jQuery library in our page.  So download jQuery (direct link to the Google Code location).

Now that we have our JS library, we need to tell our document where it is (I renamed my js file to jquery.js, and threw it in the js folder):

     <script language="javascript" src="js/jquery.js"></script>


We inserted the SCRIPT tag to include the jquery library when the page is loaded.

Binding jQuery actions to an anchor (A) tag
Lets create a basic link in our document:

     <script language="javascript" src="js/jquery.js"></script>
     <a href="#">Click Here</a>

We now have a link that does nothing.  We are preparing to bind jQuery to the anchor.

Toggling the visibility of a div
We need to do 2 things to toggle the visibility of a div with jQuery.  First off, we need a DIV to toggle!  Second we need to bind jQuery commands to the anchor link.

We will take advantage of the jQuery toggle effect.

To do this, we change our code below:

     <script language="javascript" src="js/jquery.js"></script>
     <script language="javascript">
     $(document).ready(function() {
          $('#toggleButton').click(function() {
               return false;
     <a href="#" id="toggleButton">Click Here</a>
     <div id="toggleSection">
          Content to toggle on and off

This step we did a lot.

First we added [id=”togglebutton”] to the A tag.  That lets us identify it in the jQuery code.

Second we added the “toggleSection” DIV to the document.  The entire div will be toggled on and off.  Again, here we identified the DIV as “toggleSection” to be able to target it with the jQuery code.

Third, we added the jQuery code that actually does the toggling in the HEAD section of the document.  jQuery is a javascript engine, so we have to execute the commands in SCRIPT tags.  The first line of the code, “$(document).ready(function() {” is complicated.  Lets dissect this code.

Finally we put “return false;” in the code, that tells the link NOT to use the HREF value.  This means “#” will not be loaded.  It’s annoying, because that brings the browser to the top of the page in certain browsers.

$(document) — this is the HTML document itself.  It is the same as “document” in normal javascript.

.ready( — this is us looking at the “onLoad” part of jQuery.  When the document is ready, it executes  the “ready” method.  Here we are defining what the ready method is.

function () { — basically, we are creating a new function that will fill in for the document.ready method.  When the document is ready, our code will be executed.  This is smart, as executing code when the page isn’t ready can result in missing elements that aren’t loaded yet.

After that statement, we have “$(‘#toggleButton’).click(function() {“, another complicated statement.  Lets break it down:

$(‘#toggleButton’) — we are looking for the “toggleButton” via jQuery.  This code finds it for us.

.click( — Instead of setting the value of the “ready” method before, we are setting the function of when the “toggleButton” is clicked. So we need to create a function…

function () { — again, creating a function inline.  This will be assigned to the button’s “click” method.

Finally we do the fun stuff, toggling the DIV on and off with “$(‘#toggleSection’).toggle();”.  By now it should be easier to read this line.  We are finding the toggleSection div, and calling the jQuery method of “toggle()” which will toggle the visibility of the DIV.

It is important to note the “return false” part of this.  By returning false, we are telling the HREF that it should NOT execute the HREF value (which is #, and would bring the browser to the top of the screen).  If we don’t return false, the browser will still load the HREF value, and we will have some minor issue cross browser.

We’re done!  We are toggling the visibility, check out the demo — jQuery toggle demo.  Fortunately, we can still have a little more fun..

Sliding in and out of that div
In the previous step, we toggled the visibility of a DIV.  It’s not too exciting, as we could easily do that with javascript before with stylesheets and basic DOM code.  What is great about the jQuery library is all of the additional methods for animation it gives us.  Lets setup that div to not just appear, or hide — but to slide in and slide out.

For that we will take advantage of the slideUp and slideDown methods, they are just 2 of many Effects available in jQuery.

     <script language="javascript" src="js/jquery.js"></script>
     <script language="javascript">
     $(document).ready(function() {
          $('#toggleButton').click(function() {
               if ($('#toggleSection').is(":hidden"))
               } else {
               return false;
     <a href="#" id="toggleButton">Click Here</a>
     <div id="toggleSection">
          Content to toggle on and off<br>
          More content<br>
          Slides are more fun with more content<br>
          Four lines should be enough

We have added a little more content to the DIV, so we can more easily see how the slideUp and slideDown work.  There are 2 interesting steps we hav taken.

First, we added an “if” statement to detect if the DIV is hidden or not.

Second, we added code to slideUp or slideDown depending on whether the DIV is actually hidden.

Check out the result on our example — jQuery slideUp and slideDown demo.

I hope this helped some of you out.  Let me know if it did.  Comments are open!

Tags: , , , , , , , , , , , , ,

Please share, it makes me happy:

Subscribe to Email Alerts

Follow Me

Follow seangw on twitter



prestashop theme

virtuemart template