Write code more rapidly with code hinting support for JavaScript, the DOM (Document Object Model), and Spry.
To complete the tasks demonstrated in this tutorial, you need the following software and files:
lrvid4048_dw.zip (ZIP, 3MB)
Intermediate knowledge of JavaScript, HTML, and Spry
Adobe® Dreamweaver® CS4 has enhanced code-hinting support for JavaScript, DOM scripting, and the Spry framework. Code-hinting is available for both JavaScript documents and script blocks within your HTML files. The new code-hinting is available to you on primitive JavaScript as well as on any user-defined functions, parameters, classes, class properties and methods, and variables with which you might be working. As you are working, Dreamweaver inspects both your code and any external JavaScript files referenced in your document. This capability gives you real-time code-hinting support for any external JavaScript libraries, such as the Yahoo! User Interface (YUI), jQuery, and Prototype libraries. Code-hinting is dynamic in Dreamweaver, so changes made to external libraries are reflected as you code.
In this tutorial, you will learn how to initialize a YUI calendar widget and bind it to a Spry data set on your web page.
Writing the code for a YUI calendar widget is a very efficient, streamlined process in Dreamweaver CS4. To initialize the YUI calendar widget:
Note: The YUI calendar widget used in this tutorial is available for download through the Adobe website. To access the calendar widget, click the Extend Dreamweaver button on the Standard toolbar, and then choose Browse For Web Widgets.


Note: When you place the period after calendar, the code hinting window opens. Notice cal1 is the first suggestion. This demonstrates the dynamic, introspective nature of the Dreamweaver code hinting function. You'll notice the variable cal1 is defined three lines earlier in the code on line 131. As soon as code for cal1 was written, it was added to the code-hinting feature's store.


For code hinting to work properly, the JavaScript has to be well-formed. Any errors can disable code-hinting and slow you down. To help you correct and detect errors, Adobe has added syntax error indicators in Code View that display a warning on the information bar and highlights the affected lines. To detect syntax errors:

Once you remove the comment, Dreamweaver detects a syntax error and displays a warning in an information bar at the top of the document window. Dreamweaver also highlights the line containing the error.

You have successfully created a YUI calendar widget. However, the calendar is not bound to any Spry data (that is, there is no relationship to the data in the data set and the calendar). To bind the calendar to specific dates:
var dates = cal4.

var dates = cal4.getCurrentRow();
This code returns the value of any selected current row. Because you are registering this code to an observer object, every single time the row data changes, it will update the calendar widget.


This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
James Williamson is the director of training for Lodestone Digital, an Adobe and Apple Authorized Training Center. He is an Adobe Master Instructor and has over 13 years of web, print, and digital video experience. He has been a featured speaker at Flashforward and MAX and is a contributing author to the popular Flash Magic series from New Riders.
James is also a co-host for Lodebearing, the occasionally regular tech podcast, which can be found on iTunes and at loadbearing.com.