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...

12 June 2007

The joys of JavaScript error messages

Today I meant to type

someObject.someProperty
but instead I typed
someObject..someProperty
with the incorrect extra period.

Firefox kicked back the amazingly helpful

XML descendants internal method called on incompatible Object
which I stared at dumbfounded. All of Firebug's glorious power was seemingly useless against this error. It didn't help that I was working atop a custom Dojo build.

Then I flipped back to my editor which thankfully still had the cursor next to the extra period. A simple backspace and I was moving again...

Subscribe Subscribe to The Return of Agent Zlerich