Activate your free membership today | Log-in

Thursday, July 3rd, 2008

Shrinking frameworks; Dojo in 6k

Category: Dojo

Dojo is a framework that you can bend for your needs. You have very fine grained control on what you want in your base dojo.js, how other components are loaded, and a final custom JavaScript file.

Brad Neuberg showed a project, SearchTools, that added local search via Gears, and had a custom Dojo that wasn’t Dojo in a very small package.

Alex Russell has taken this further and explained how he got Dojo to 6k by implementing a stub loader, so many of the functions were lazy loading stubs instead of full method bodies.

His use case was mobile, or small embedded devices in general:

On an iPhone with a clean cache the stubbed-out dojo.js cut in half the time required to load and evaluate. Sure, it’ll take more time on the network when parts of the toolkit are actually used (say, in response to a click event), but for mobile device scenarios, it’s going to be hard to beat the flexibility and speed of the stub loader when pulling Dojo into a page.

The post really wasn’t about Dojo per se, but John Resig parsed the sentence: “Even so-called “lightweight” libraries like jQuery” and in one part of a three part post hit back:

The way it’s worded you would assume that you were paying a large, up-front, cost to using jQuery when, in fact, there is very little overhead. jQuery has been shown to be the fastest loading JavaScript library for non-cached code and considerably fast for cached code.

If we ignore the frameworks and think of the meta-point it is a lot more interesting.

Posted by Dion Almaer at 10:12 am
Comment here

++++-
4.4 rating from 17 votes

Friday, June 27th, 2008

Working with Web Services with ease; dojo.data and the WikipediaStore

Category: Dojo

Revin Guillen has posted about the Dojo dojo.data API and how you can layer access to Web services in a very elegant way.

His example shows building access to Wikipedia (demo):

Dojo recently received a new data store that demonstrates exactly what we want: dojox.data.WikipediaStore. It does just what it sounds like, turning Wikipedia into a simple object you can query from your code. Building it with Dojo’s handy dojox.rpc package makes for a simple, compact, DRY implementation.

In only four steps:

  1. Create the web service object
  2. Declare the new data store, inheriting from ServiceStore
  3. Give it a fetch method
  4. Give it a _processResults method

The service descriptor looks like:

JAVASCRIPT:
  1.  
  2. {
  3.     "SMDVersion": "2.0",
  4.     "id": "http://en.wikipedia.org/w/api.php",
  5.     "description": "Wikipedia API",
  6.  
  7.     transport: "JSONP",
  8.     envelope: "URL",
  9.     additionalParameters: true,
  10.     target: "http://en.wikipedia.org/w/api.php",
  11.     parameters: [
  12.         { name: "format", optional: false, "default": "json" }
  13.     ],
  14.  
  15.     services: {
  16.         query: {
  17.             parameters: [
  18.                 { name: "action", type: "string", "default": "parse" }
  19.             ]
  20.         }
  21.     }
  22. }
  23.  

which you can use when you create the store:

JAVASCRIPT:
  1.  
  2. dojo.require("dojo.io.script"); // for cross domain JSONP
  3. dojo.require("dojox.rpc.Service");
  4.  
  5. dojo.addOnLoad(function(){
  6.     var mu = dojo.moduleUrl("dojox.rpc.SMDLibrary", "wikipedia.smd");
  7.     var wikipedia = new dojox.rpc.Service(mu);
  8.  
  9.     wikipedia.query({
  10.         action: "parse",
  11.         page: "Main Page"
  12.     }).addCallback(this, function(article){
  13.         dojo.body().innerHTML = article.parse.text["*"];
  14.     });
  15. });
  16.  

Posted by Dion Almaer at 8:50 am
Comment here

+++--
3.8 rating from 16 votes

Wednesday, June 25th, 2008

Badging Flickr with Dojo

Category: Dojo, Examples

Dylan Schiemann has a really nice case study post on implementing a Flickr badge with Dojo.

What is particularly interesting is how he starts with a simple version:

HTML:
  1.  
  2. ...
  3. <link rel="stylesheet" href="/dojo/dojox/image/resources/image.css" />
  4. <style type="text/css">
  5.         img.thing { width:50px; height:50px; }
  6. </style>
  7. ...
  8. </head>
  9. ...
  10. <div dojoType="dojox.image.FlickrBadge" rows="8" cols="3" username="dylans"
  11.         tags="dojotoolkit,italy"></div>
  12. ...
  13. <script type="text/javascript" src="/dojo/dojo/dojo.js"
  14.         djConfig="parseOnLoad: true"></script>
  15. <script type="text/javascript">
  16.         dojo.require("dojox.image.FlickrBadge");
  17. </script>
  18. </body>
  19.  

And then shows how he tweaks it for performance, explaining what he is doing along the way:

HTML:
  1.  
  2. ...
  3. <link rel="stylesheet" href="/dojo/dojox/image/resources/image.css" />
  4. <style type="text/css">
  5.         img.thing { width:50px; height:50px; }
  6. </style>
  7. ...
  8. </head>
  9. ...
  10. <div id="flickrSidebox"></div>
  11. ...
  12. <script type="text/javascript" src="/dojo/dojo/dojo.js"></script>
  13. <script type="text/javascript">
  14.         function initBadge(){
  15.                 new dojox.image.FlickrBadge({rows: 8, cols: 3,
  16.                         username: "dylans", tags:"italy,dojotoolkit"},
  17.                         "flickrSidebox").startup();
  18.         }
  19.         dojo.addOnLoad(function(){ dojo.require("dojo.badge");
  20.                 dojo.addOnLoad(initBadge)});
  21. </script>
  22.  

It is nice to see his thought process, and how you can start with functionality, and then go back and tweak away.

Posted by Dion Almaer at 7:06 am
Comment here

+++--
3.7 rating from 24 votes

Tuesday, June 17th, 2008

Dojo gets AIM API Support from AOL

Category: Dojo

James Burke of AOL announced that AOL has released Dojo modules which wrap AOL's Web AIM API. This is a very big announcement as the Web AIM API lets developers incorporate core AIM functionality into any web page including the ability to sign on, send and receive IMs, and obtain a user's Buddy List.

My employer, AOL, just open-sourced some Dojo modules that include a wrapper for the Web AIM API and UI widgets for user presence, the buddy list and sending and receiving instant messages (IMs).

The modules are open source versions of the modules used by AOL Webmail, so they have history in a real product. The modules are designed for Dojo 1.1 and above.

This has been released as part of the AIMDojo project with version 1.0 immediately available for download. James has included demos of Dojo and WEB AIM integration.

Posted by Rey Bango at 7:45 am
Comment here

+++--
3.6 rating from 32 votes

Wednesday, June 11th, 2008

Ajaxian Featured Tutorial: A Double Dose of Dojo

Category: Dojo

The team at Dojo have been really working hard to improve their documentation and put more information in the hands of Dojo developers. Between DojoCampus.org and the SitePen blog, they've really come a long way to providing solid education material for the Dojo community.

Normally, the Ajaxian Featured Tutorial consists of one really good educational piece but two really awesome tutorials were recently posted and I decided to give Ajaxian readers a two-fer:

Tutorial 1: Dojo Drag and Drop, Part 1: dojo.dnd

In the first part of this series, Revin Guillen takes you through the ins-and-outs of Dojo's drag and drop API named dojo.dnd.

What I really like about Revin's tutorial is his extensive code samples that reinforce the concepts. His demo code on building a drop handler, for example, is very extensive and concise allowing the reader to easily understand how to create the drop handler:

JAVASCRIPT:
  1.  
  2. // calculate simple totals in the wishlist and cart titles
  3. var setupCartTitle = function(){
  4.     var title = "Shopping Cart";
  5.     var cartLength = cart.getAllNodes().length;
  6.     if(cartLength){
  7.         var items = cartLength> 1 ? " items" : " item";
  8.         title += " (" + cartLength + items + ")";
  9.     }
  10.     cartPane.setTitle(title);
  11. };
  12. var setupWishlistTitle = function(){
  13.     var title = "Wishlist";
  14.     var wishlistLength = wishlist.getAllNodes().length;
  15.     if(wishlistLength){
  16.         var items = wishlistLength> 1 ? " items" : " item";
  17.         title += " (" + wishlistLength + items + ")";
  18.     }
  19.     wishlistPane.setTitle(title);
  20. };
  21. dojo.connect(cart, "onDndDrop", setupCartTitle);
  22. dojo.connect(wishlist, "onDndDrop", setupWishlistTitle);
  23.  

Tutorial 3: A Beginner’s Guide to Dojo Charting, Part 1 of 2

Next up Doug McMaster teaches you how to leverage Dojo's charting capability:

In this two part guide, we look at how easy it is to get Dojo Charting up and running, and then examine in greater detail the options available for different looks for your charts. Today in Part 1, we start with a basic example and then examine all the options available in defining your plot type. Part 2 will cover the options available in defining the axes and data sets for your charts.

Doug explains how to easily create charts by customizing the available 2D charts included in Dojo charting API. Code as simple as:

HTML:
  1.  
  2. <title>Basic Charting</title>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4.  
  5. <script type="text/javascript" src="dojo/dojo.js" djConfig="isDebug: true"></script>
  6.  
  7. <script type="text/javascript">
  8.  
  9. dojo.require("dojox.charting.Chart2D");
  10.  
  11. makeCharts = function(){
  12.  
  13.         var chart1 = new dojox.charting.Chart2D("simplechart");
  14.         chart1.addPlot("default", {type: "Lines"});
  15.         chart1.addAxis("x");
  16.         chart1.addAxis("y", {vertical: true});
  17.         chart1.addSeries("Series 1", [1, 2, 2, 3, 4, 5, 5, 7]);
  18.         chart1.render();
  19.  
  20. };
  21.  
  22. dojo.addOnLoad(makeCharts);
  23.  
  24. </script>
  25. </head>
  26. <div id="simplechart" style="width: 250px; height: 150px;"></div>
  27. </body>
  28. </html>
  29.  

produces a nice chart like this:

Posted by Rey Bango at 9:00 am
1 Comment

++++-
4.3 rating from 35 votes

Wednesday, June 4th, 2008

Nexaweb announces dojo.E markup and runtime

Category: JavaScript, Library, Dojo

Nexaweb has released a new product that build on Dojo, dojo.E:

dojo.E provides developers with the ability to use an XML based markup language to add in their Ajax behaviors. Markup whether — XML, HTML or CSS — simplifies development by allow developers to convey in simple text format what they would otherwise need to convey in code. Markup also provides a great abstraction layer that separates the implementation from the usage.

This release, which is an Apache style open source project itself, consists of two pieces:

dojo.E Markup

dojo.E Markup allows developers to describe their dojo components using a simple markup language that translates directly into dojo classes. For example declaring a button in dojo would be done one of two ways;

HTML:
  1.  
  2. <div dojoType=”dijit.form.Button” label=”Hello, world”/>
  3.  

Using JavaScript new dijit.form.Button(htmlElement, “Hello, World”);

dojo.E Markup provides a third way that allows developers to describe the button as follows:

HTML:
  1.  
  2. <script type=“text/xml” dojoType=“dojoe.XmlScript”>
  3.    <ui xmlns:dijit=“dijit”>
  4.         <dijit :form.Button label=“Hello, World!”
  5.            onclick=“alert(’It works!’)”/>
  6.     </ui>
  7. </script>
  8.  

dojo.E Runtime

The runtime provides additional markup that makes modifying the HTML DOM or the dojo Components easier.

XML:
  1.  
  2. <xm :xmodify document=”ui”>
  3.         </xm><xm :append select=”//widget.SortList”>
  4.                 <li>{0}</li>
  5.         </xm>
  6.  
  7.  

The xModify syntax above tells the dojo.E runtime to append a “

  • {0}
  • ” tag to the dojo SortList component. The select statement in this case is a XPath statement and not a CSS selector. In the actual sample this snippet above is wrap with a “Macro” which allows the developer to parameterize the “{0}” and execute the xModify snippet when the developer clicks the “Add” button.

    You can play with this in a live editor that shows samples such as a todo list:

    XML:
    1.  
    2. <declarations>
    3.         <dojoe :Macro id="add" xmlns:dojoe="dojoe">
    4.         <![CDATA[
    5.         <xm:xmodify xmlns="html" xmlns:xm="dojoe" xmlns:dijit="dijit" document="ui">
    6.                 <xm :append select="//widget.SortList ">
    7.                         <li>{0}</li>
    8.                 </xm>
    9.        
    10.         ]]>
    11.         </dojoe>
    12. </declarations>
    13. <ui xmlns:dijit="dijit" xmlns:dojox="dojox" xmlns="html">
    14.         <div id="input_container">
    15.                 <span>ToDo:</span>
    16.                 <input style="width: 184px; margin-left:3px;" id="textbox" type="text" class="input_tbx" value="Item"/>
    17.                 <input class="button" type="button" value="Add" onclick="dojoe.containers.macro.get('add').execute(document.getElementById('textbox').value);" />
    18.         </div>
    19.         <div id="list_container">
    20.                 <dojox :widget.SortList  title="SortList From Markup" style="width:300px; height:150px;">
    21.                         <li>A. Download and Install the dojo.E</li>
    22.                         <li>B. Build dojo.E Application</li>
    23.                         <li>C. Profit</li>
    24.                 </dojox>
    25.         </div>
    26. </ui>
    27.  

    Posted by Dion Almaer at 8:36 am
    17 Comments

    +++--
    3.4 rating from 40 votes

    Tuesday, June 3rd, 2008

    Dojo Firebug Lite: Beyond console.log

    Category: Dojo, Debugging

    Mike Wilcox has posted on Firebug Lite for Dojo and shows how he has taken it beyond console.log().

    I was most excited about the DOM inspector:

    Yes, I did say that a DOM inspector would imitate existing tools. However, I implemented this for a colleague who was struggling with a particularly nasty IE 6.0 bug one day (more like one month), as he expressed a wish to view the dynamic DOM to verify hover states in IE6 — the one browser without this tool. Because Firebug Lite already had some nice formatting built in with the dirxml() method, it was just a matter of grabbing the current event target from the onmousemove event, and displaying the result in its own section. The current target is outlined, and clicking on it makes it “stick”.

    As much as everyone loves Firefox, the Dojo team is committed to the Open Web, which means encouraging competition amongst browsers. One way of fostering that competition is through debugging tools, such as Firebug Lite. We are trying to make it as easy as possible to code for large user-base browsers like Internet Explorer, or preferred browsers, like Safari or Opera, or… [your favorite browser here].

    Dojo Firebug Lite

    Posted by Dion Almaer at 6:45 am
    9 Comments

    ++++-
    4.1 rating from 17 votes

    Tuesday, May 27th, 2008

    dojo.workers: a showcase

    Category: Dojo, Showcase

    dojo.workers

    Pete Higgins of Dojo has created a nice example, dojo.workers, that puts together coverflow with Dijit and some dojo.query animations.

    He even takes out his frustrations with IE 6 as he creates a branch that looks like this ;)

    JAVASCRIPT: