At The Forge

The first thing to understand about Dojo is that it is large, at least by JavaScript standards.

Listing 1. simple.html

<title>Dojo page title</title> <script type="text/javascript" src="/]avascript/dojo.]s"></script>

<script type="text/javascript">

dojo.require("dojo.widget.Editor"); </script> </head>

<div class="dojo-Editor">

editor goes here </div>

Listing 2. simple-form.html

<title>Dojo page title</title> <script type="text/]avascript" src="/javascript/dojo.]s"></script>

<script type="text/javascript">

dojo.require("dojo.widget.Editor"); </script> </head>

<form method="POST" action="/parse.php">

<textarea name="text" class="dojo-Editor">

write something! </textarea> <input type="submit" /> </form> </body> </html>

save documents; you simply work with them, and you can expect the computer to save what you've done reliably.

This month, we take a simpler approach, including our rich-text editor in an HTML form submission. Unfortunately, it's still not obvious how we can pull this off, because HTML forms consist of <input> and <textarea> tags. Luckily, the Dojo team has taken this into consideration. Notice that we define a Dojo widget by its class, not by its tag type. This means we can attach the dojo-Editor class to anything, not only to an empty <div> tag. If we attach it to a <textarea>— which is a block element, just like <div>—our text editor will be attached to a textarea, which will be submitted to the server. In other words, we replace our <div> with:

<textarea name="text" class="dojo-Editor">

Hello from the Dojo editor! </textarea>

Listing 2 shows an example of how this might look when incorporated into a simple HTML form. When the contents of the form are sent to the server, all formatting is preserved using HTML tags. Your application will need to parse this HTML to understand any formatting that might appear in the text.

Of course, if your plan is to take the input text and simply display it in a Web browser, not much (if any) work is needed on your part. You can stick the input into a database and then retrieve it whenever it is needed. (I haven't checked into the security of this widget to make sure it is immune to cross-site scripting attacks, so you might want to investigate it further before simply accepting, storing and displaying user data.)

Conclusion

As you can already see, Dojo offers a wide variety of functions and doesn't take much effort to start using. But using many of the other widgets Dojo includes, such as an attractive DatePicker, requires that we use Dojo's sophisticated event handler, which we did not examine here. Next month, we will look at events in Dojo and how that package lets us incorporate special effects, Ajax and many more widgets into our Web applications.■

Reuven M. Lerner, a longtime Web/database consultant, is a PhD candidate in Learning Sciences at Northwestern University in Evanston, Illinois. He currently lives with his wife and three children in Skokie, Illinois. You can read his Weblog at altneuland.lerner.co.il.

Resources

The main source for information about Dojo, as well as Dojo software releases, is at dojotoolkit.org. Documentation for the toolkit is still a bit sparse, but it has improved significantly in the last few months, and continued improvements seem likely, given Dojo's growing popularity. The main URL for Dojo documentation is at dojotoolkit.org/docs, with Dojo.book (the Wiki-based Dojo documentation) at manual.dojotoolkit.org/index.html.

Some good articles about JavaScript toolkits, including Dojo, are at www.sitepoint.com/article/javascript-library.

Finally, a good introduction to rich-text editing with Dojo is at dojotoolkit.org/docs/rich_text.html.

PGI Unified Binary"

Now, PGPcompilers can generate a single PGI Unified Binary executable fully optimized for both Intel EM64T and AMD64 processors, delivering all the benefits of a single x64 platform while enabling you to leverage the latest innovations from both Intel and AMD. PGI Fortran, C, and C++ compilers deliver world-class performance and a uniform development environment across Linux and Windows as part of an integrated suite of multi-core capable software development tools. Visit www.pgroup.com to see why the leading independent software vendors in structural analysis, computational chemistry, computational fluid dynamics and automotive crash testing choose PGI compilers and tools to build and optimize their 64-bit applications.

The Portland Group

www.pgroup.com ++ 01 (503) 682-2806

The Portland Group, Inc. is an STMicroelectronics company. PGI, The Portland Group, PGI Unified Binary are trademarks or registered trademarks of STMicroelectronics. Other brands and names are the property of their respective owners.

Was this article helpful?

0 0

Post a comment