06.05.2013 Views

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

var PrinterTool = {};<br />

PrinterTool.windowSettings = 'toolbar=no,location=no,' +<br />

'status=no,menu=no,scrollbars=yes,width=650,height=400';<br />

[ 37 ]<br />

Chapter 2<br />

The first line is a <strong>com</strong>ment with the $Id$ tag required by the coding st<strong>and</strong>ards. If this<br />

file were checked into CVS, the line would be replaced with something like this:<br />

// $Id: print_tools.js,v 1.0 2008/07/11 08:39 mbutcher Exp $<br />

As you can see, CVS will add some information about the version of the file. This<br />

information includes the name of the file, its version number, when it was checked<br />

in, <strong>and</strong> who checked it in.<br />

Directly beneath the ID <strong>com</strong>ment is the file-wide documentation block.<br />

Documentation blocks use a special <strong>com</strong>ment style beginning with a slash <strong>and</strong><br />

two asterisks: /**. Automated documentation tools can later scan the file <strong>and</strong> pick<br />

out the documentation blocks, automatically generating API documentation for<br />

your script.<br />

The role of the file-wide documentation block is to explain what the code in the file<br />

does. The first line should be a single-sentence description of the file. Additional<br />

paragraphs may be added.<br />

In the following line, we define our PrinterTool object:<br />

var PrinterTool = {};<br />

This code is declaring the PrinterTool variable <strong>and</strong> assigning it an empty object literal<br />

({}). This line plays an interesting role in the structure of our application, <strong>and</strong> we will<br />

see constructs like this both within <strong>Drupal</strong> <strong>and</strong> in the later chapters of this book.<br />

An object literal is a notation for defining an object by using its<br />

symbolic delimiters, rather than by using a new constructor. That is,<br />

instead of calling the new Object() constructor, we use the symbolic<br />

representation of an empty object, {}, to declare an empty un-prototyped<br />

object. We will use this method frequently in this book.<br />

The role of the PrinterTool object is to serve as a namespace for our application.<br />

A namespace is an organizational tool that allows the software developer to collect<br />

various resources together . This is done without having to worry that these<br />

resources will be in conflict with those created by other developers.<br />

Objects that function as namespaces should always begin with an initial<br />

capital letter, such as <strong>Drupal</strong> or PrinterTools.<br />

This material is copyright <strong>and</strong> is licensed for the sole use by Richard Ostheimer on 18th June 2009<br />

2205 hilda ave., , missoula, , 59801

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!