20 June 2007

Programmatic GreekingWidget for dojo

When playing with dojo's fancy container and layout widgets, it is nice to be able to greek quickly. Pasting a bunch of generated lorem ipsum text gets old quickly, so here's a programmatic, custom dojo widget that'll generate as much or as little placeholder text as you need. The JavaScript source code uses the dojo 0.4.x APIs. Please feel free to use and improve this widget however you like. Here's an HTML snippet that demonstrates the widget's usage...

<html>
<head>
        <title>Usage and unit tests for GreekingWidget</title>

        <script type="text/javascript">
            djConfig = { isDebug: true };
        </script>

        <!-- Be sure to point to your local dojo installation -->
        <script type="text/javascript" src="dojo-0.4.3-widget/dojo.js"></script>

        <!-- Be sure to point to where you save the source code -->
        <script type="text/javascript" src="GreekingWidget.js"></script>

        <style type="text/css">
            .FooBarClass {
                color: red;
            }
        </style>
</head>
<body>
        <h2>Usage and unit tests for GreekingWidget</h2>

        <h3>Default options</h3>
        <div dojoType="GreekingWidget"></div>

        <h3>One sentence</h3>
        <div dojoType="GreekingWidget"
            paragraphs="1"
            sentencesPer="1"
            loremIpsum="true"></div>

        <h3>Generate blockquotes</h3>
        <div dojoType="GreekingWidget" 
            paragraphs="2" 
            tag="blockquote"></div>

        <h3>Add CSS class to make them red</h3>
        <div dojoType="GreekingWidget" 
            paragraphs="2" 
            addClass="FooBarClass"></div>

        <h3>Add CSS style to make them tiny</h3>
        <div dojoType="GreekingWidget" 
            paragraphs="2" 
            sentencesPer="20"
            addStyle="font-size:xx-small;"></div>

</body>
</html>
And here's the test page output...

3 comments:

Anonymous said...

Nice widget, Agent Zlerich! In fact, it's so useful, I'm gonna put it in a new Pragmatic Press book on Dojo (adapted for 0.9/1.0). It not only acts as a good example of building a widget, it's a perfect adjunct to examples. Your name and permalink will be immortalized in the comments. I thank you!

R Zlerich said...

Thanks Craig. I'm glad you found it useful. Please let me know when the book comes out-- I'm very interested in the changes going from dojo 0.4.x to the 0.9 series. If you're looking for any, I'd be happy to be a technical reviewer on the book. In the past I've done that for an O'Reilly JBoss book and the upcoming JSR 289 SIP Servlet 1.1 specification.

Anonymous said...
This comment has been removed by a blog administrator.

Subscribe Subscribe to The Return of Agent Zlerich