SOS

Shane O’Sullivan’s technical blog… really ties the room together

Archive for the 'dojox' Category


New Demos for Dojo & Google search engine online

Posted by Shane O'Sullivan on 13 May, 2008

I’ve previously written about the data stores I committed to the Dojo Ajax Toolkit that enable you to search Google’s services for all sorts of things - books, news, blogs, images and everything else.

Now I’ve put some demos up on DojoCampus that show off a few of the stores.  Check them out at http://dojocampus.org/explorer/#Dojo_Data_GoogleSearchStore , especially the Google Images one - it’s shiny :-)

Posted in Ajax, Demo Engine, Dojo, Technical, demo, dijit, dojo.data, dojox, open source | 2 Comments »

Google and Dojo, F.E.E.D.I.N.G

Posted by Shane O'Sullivan on 6 May, 2008

This is the second in series of posts on the work I’m doing to bring the Google Ajax APIs and Dojo Ajax Toolkit together. The first post was Google And Dojo, Sitting in a Tree, which you can read for some background.

I have submitted a new data store to the DojoX project, dojox.data.GoogleFeedStore, which makes it possible to access any RSS or Atom feed, anywhere, directly from your own web page. Simply pass the URL of the feed to the GoogleFeedStore, and it will return it to you using the dojo.data.Read API.

Example

var store = new dojox.data.GoogleFeedStore();
store.fetch({
  query:{url:"http://shaneosullivan.wordpress.com/feed/"},
  onComplete: function(items) {
    dojo.forEach(items, "alert('Got feed entry with title ' + this.getValue(item, 'title'))", store);
  },
  count: 10
});

This will retrieve the first 10 entries in my blogs feed, and alert the title of each.

The huge advantage of this is that you no longer need any server side redirects to access RSS and Atom feeds from your own website. This Google service is the basis for Google Reader and iGoogle.

If you want to access an Atom feed from your own web server, you can also use the dojox.data.AtomReadStore that I wrote earlier. However, this is only useful if you have direct access to the Atom XML document using Ajax, and due to browser security issues, you can only load these documents from the web server hosting the web page. This new GoogleFeedStore removes that restriction, and has the added advantage that it also works with RSS.

Check out the demo page to get a feel for it (available in the May 6th nightlies), and there should be an example up on the Dojo Feature Explorer quite soon too.

As before, a big thanks to Google for providing such a cool service.

Posted in Ajax, Dojo, Feeds, Google, Javascript, Technical, dojo.data, dojox, dojox.data, json, open source | 4 Comments »

Google and Dojo, Sitting in a tree…

Posted by Shane O'Sullivan on 1 May, 2008

I’ve submitted a bunch of new data stores to the Dojo Ajax Toolkit that make it simple to search Google directly from your own site (ticket here).

Update: I’ve also submitted a store to read any Atom or RSS feed, anywhere, without any server redirects. See Google And Dojo, F.E.E.D.I.N.G

This is different from putting a search box on your site and redirecting to Google. With the new dojox.data.GoogleSearchStore family of data stores, you can retrieve google search results in JSON format, and display them on your site directly.

Pause a second…. let it sink in…..

There are no cross domain issues, and no server side component is required. It uses the dojo.io.script transport to access the Google Ajax API service. Just stick the following on your page:

<div dojoType=”dojox.data.GoogleWebSearchStore” jsID=”googleStore”></div>

and you have Google’s millions of servers at your fingertips.

The following data stores are available:

  • GoogleWebSearchStore - does a standard web search.
  • GoogleBlogSearchStore - searches blogs. A future enhancement I will be writing will be to write a data store that accesses Google’s extremely cool Ajax Feed API, which provides access to any ATOM feed, anywhere, in JSON. It’ll be possible to do a full web search of all blogs for certain topics, then using the feed store to pull down that complete feed .
  • GoogleLocalSearchStore - searches the Google Local service to find places, businesses etc.
  • GoogleVideoSearchStore - Does what it says on the tin, searches for videos.
  • GoogleNewsSearchStore - Finds news stories…. noticing a pattern yet?
  • GoogleBookSearchStore - Um, finds books..
  • GoogleImageSearchStore - Finds images. This provides both a thumbnail and full sized version, similar to the FlickrRestStore already provided by Dojo.

The potential applications are more or less infinite. Demos included in the check-in show how to integrate this with the extremely cool dojox.dtl templating engine to display the results in a number of different ways, as well as how to feed the results into the Dojo Grid, Gallery and SlideShow.

This code is included in the nightly checkouts of Dojo, and not in v1.1. To get it, either check it out from source control, or get it from http://archive.dojotoolkit.org/nightly/.

Have a look at the simplistic demo of it in action at http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/data/demos/demo_GoogleSearchStore.html (available from the May 1st nightlies).

A big thank you to Google for making this service available. Now go play!

P.S. Stay tuned for the Yahoo variant, coming soon!

Posted in Ajax, Atom, Dojo, Javascript, Technical, dojo.data, dojox, json, open source | 10 Comments »

Great Dojo Widget tutorial

Posted by Shane O'Sullivan on 22 April, 2008

Pete Higgins has posted a great tutorial on how to write a Dojo widget, taking as an example his recent addition, FisheyeLite.  Check it out at http://dojocampus.org/content/?p=100

Posted in Ajax, Dojo, Javascript, dijit, dojox, open source, widget | No Comments »

DojoX Calendar widget committed

Posted by Shane O'Sullivan on 11 April, 2008

Following on from my previous post about the cool new Calendar widget I wrote for the Dojo Ajax toolkit, the initial version has now been committed to the DojoX project.

dojox.widget.Calendar

Check out the calendar test page at http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/widget/tests/test_Calendar.html

Check out the dropdown date text box at http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/form/tests/test_DateTextBox.html

Some more work still has to go into the widgets, including allowing individual dates to be highlighted for specific event, and perhaps including a refactoring into a series of mixin classes, but it should be in great shape for 1.2!

Posted in Ajax, Calendar, Dojo, Javascript, Technical, dojox, open source | 4 Comments »

Dojo Ajax Demo Engine released

Posted by Shane O'Sullivan on 3 April, 2008

A great new demo engine has just been released for the Dojo Toolkit. Check it out at http://dojocampus.org/explorer/. It is based on the initial attempt at a demo engine I wrote a few months ago, but has since been updated with new demos, and made infinitely more sexy by css/theme master Nikolai Onken.

Dojo Demo Engine

The features include:

  • Demos for all three Dojo projects - Dojo (the base toolkit), Dijit (widgets) and DojoX (all that is newest and coolest) .
  • Source views for all demos. Not only do we show what Dojo can do, we show you how to do it! The source views also benefit from the very cool dojox.highlight project, which provides client side syntax highlighting.
  • Addressability - you can link directly to a demo, as I did with the dojox.highlight link above.
  • Search feature - a combo box that you can use to quickly find a demo on any subject. For example, type “image” into the box, and you’ll be shown a list of all demos to do with displaying images, such as dojox.image.Gallery, dojox.image.SlideShow etc.
  • Cool animated menus - totally aesthetic I know, but a very pretty addition by Peter Higgins. The menus separate the three projects, providing easier, clearer navigation.
  • Link hierarchies - each set of demos can have links attached to it, for example to extra tutorials or documentation. If you click a parent of that demo, you are shown all links of all children of that section. For example, click on the DojoX link on the top of the page, and you’ll be presented with a list of all links to all DojoX projects.
  • Browser Back Button management. Using the dojo.back package, you can navigate back and forward through the application using the browser’s back and forward buttons.

The demo engine is hosted on the extremely cool Dojo Campus website, which is a new learning resource for all things Dojo. It contains videos, tutorials and much more.

This version of the demo engine has many many examples in it. However, it is only the beginning, and there is a lot of room to add more content. The next step is to open the development process for community submissions of all the cool things people have done with Dojo. We will be making available the demo engine on Subversion, and writing development and submission processes to make it as easy as possible for people to contribute.

This is gonna be big!

Update: see http://ajaxian.com/archives/dojo-mini-and-the-feature-explorer for the Ajaxian post.
Share this post:digg it|kick it|Email it|bookmark it|reddit|liveIt

Posted in Ajax, Demo Engine, Dojo, Image Gallery, Javascript, Technical, demo, dijit, django, dojo.charting, dojo.data, dojo.event, dojo.image, dojo.query, dojox, dojox.data, dojox.image, json, open source | 10 Comments »

Sexy new Calendar widget for Dojo

Posted by Shane O'Sullivan on 24 March, 2008

I’ve submitted a sexy new Calendar widget to the Dojo Toolkit, called dojox.widget.Calendar. Check out a test page for it at http://www.skynet.ie/~sos/js/demo/dojo/dojox/widget/tests/test_Calendar.html. The ticket tracking it is at http://trac.dojotoolkit.org/ticket/6297.

The features of this calendar widget are:

  • Day view - the standard view, showing all the days in a month
  • Month view - lists the twelve months of the year.
  • Year view - lists all the years that can be chosen.
  • Cool animations between these views.
  • Cool animations when moving from month to month, and from year to year.
  • Cool animations when moving the mouse over the widget, courtesy of the dojox.widget.FisheyeLite widget. (tired of cool animations yet? Nah, me neither)

The daily, monthly and yearly views of the Calendar
The day, month and year views of the calendar widget

I was inspired to write it after seeing the very cool Calendar widget in the AjaxControl Toolkit, a .NET Ajax framework, which made me think “I wonder how long this would take to write with Dojo?“, taking into account the obvious: not a single line of code could be copied from the original.

The answer turned out to be about 3 hours or so, since Dojo already provided the majority of what I needed.

  • All the Date-related heavy lifting is done with dijit._Calendar, the existing Dojo calendar widget. This also handles the majority of the localisation issues.
  • Most of the animations are done using the dojo.animateProperty function.
  • Generating the HTML of the widget is mostly taken care of by the standard Dijit templating system.

What remained to do was changing the exiting dijit._Calendar HTML template to give a month and year view, and fiddling with CSS to get it looking right. A textbox popup widget was also submitted to integrate the Calendar with a text input field, called dojox.form.DateTextBox;

Hopefully this will make it’s way into the DojoX project fairly soon, and be available for general use.
Share this post:digg it|kick it|Email it|bookmark it|reddit|liveIt

Posted in Ajax, Calendar, Date Picker, Dojo, Javascript, Technical, dijit, dojox, open source | 4 Comments »

Writing a Django Template Widget With Dojo Data Stores

Posted by Shane O'Sullivan on 3 March, 2008

One of the very cool recent additions to the Dojo toolkit is support for the Django Template engine. It is essentially a very advanced browser based templating engine, that enables you to use things like FOR loops, IF statements and much more directly in a HTML template. Or, as the author puts it:

The Django Template Language is one part of Django, a “high-level Python Web framework that encourages rapid development and clean, pragmatic design.

This blog post is an in depth tutorial on working with DTL, Atom XML and Dojo data stores. To see the final working version, have a look here, or get the code from here. Extract the code at the same level as Dojo, and open the demoAtomDTL.html file. Note that you need either the nightly Dojo code, or v1.1 or later for this to work.

Simple Example

As a very simple example, you could write a single template, such as

<ul>
    <!--{% for item in items %}-->
        <li value="{{item.value}}">{{item.text}}</li>
    <!--{% endfor %}-->
</ul>

Then, you populate the template with some JSON data, e.g.

{
    items:[
        {value:1,text:"Choice 1"},
        {value:2,text:"Choice 2"},
        {value:3,text:"Choice 3"}
    ]
}

and it generates the following HTML.

<ul>
    <li value="1">Choice 1</li>
    <li value="2">Choice 2</li>
    <li value="3">Choice 13</li>
</ul>

Writing A Widget And Template To Work With Atom XML

The example above is simplistic, though still very useful of course. However it is possible to do much more interesting things with DTL. A recent enhancement to the code base means that a template can now be built using data from a dojo.data repository, rather than a simple JSON object. This means that you can have a single template that can be used with data from many different data sources (see here for an ItemFileReadStore and here for a Flickr data store example).

This post shows how to write a templated widget that uses a Dojo data store I have written for reading Atom XML data (which has been committed to the Dojox project), and transforming it using DTL into a nice fancy HTML widget, complete with visual effects. See http://www.skynet.ie/~sos/blog.php to see the final result. Do a “View Source” on that page to see how simple it is to include it on a page.

A Django templated widget built from an Atom XML file

Writing the Template

Firstly, the structure of the HTML to be produced must be decided. For this example, I’ll just create a series of DIV elements that contain a header for the title, and a body for the text. The body will also contain another DIV to list all the tags (or categories in Atom-speak). So, a single entry will end up looking like:

<div class="entry">
    <div class="entryTitle">This is an entry title</div>
    <div class="entrySummary">
        This is some summary text
        <div>
            Tags: <a href="http://shaneosullivan.wordpress.com/category/ajax">Ajax</a>
        </div>
    </div>
</div>

A template for this looks as follows:

<!--{% load dojox.dtl.contrib.html %}-->
<div id="{{rootId}}" >
    <!--{% for item in items %}-->
        <div class="entry">
            <div class="title"><!--{{item.title.text}}--></div>
            <div class="summary">
                <!--{% if item.summary.type == "html" %}-->
                    <!--{% html item.summary.text %}-->
                <!--{% else %}-->
                    <!--{{ item.summary.text }}-->
                <!--{% endif %}-->
            <div>
                <!--{% if item.category %}-->
                    Tags:
                    <!--{% for cat in item.categorys %}-->
                        <a href="{{cat.scheme}}/category/{{cat.term}}"> <!--{{cat.term}}-->  </a>
                    <!--{% endfor %}-->
                <!--{% endif %}-->
            </div>
        </div>
    </div>
<!--{% endfor %}-->

Break it down!

Ok, so let’s have a look at this.

Read the rest of this entry »

Posted in Ajax, Dojo, Feeds, Flickr, Javascript, Technical, dijit, dojox, dojox.data, json, open source | 5 Comments »

Functional programming with Dojo - Quick tips

Posted by Shane O'Sullivan on 15 February, 2008

This post is a summary, and more, of a great blog post by Eugene Lazutkin on the insanely cool new Functional Programming features in the Dojo Ajax toolkit. It gives number of quick examples in the vein of : “How to I do (x) to a data structure of type (y)“. Have a read of Eugene’s post if you want to know the reasoning behind these features, and how they can be used to vastly simplify your own code.

Please feed free to post your own suggestions as comments and I will include them here. Note that some of the examples contain the variable df, this is short for dojox.lang.functional.

1. How do I add a number to every element of an array (creating a new array)?

var list= [10,20,30,50,25,5];
var newList= dojo.map(arr, “return arguments[0]+2″);

2. How do I add a number to every element of an array without creating a new array?

var list= [10,20,30,50,25,5];
dojo.forEach(list, “array[index]+=2″);

3. How do I sum all the values in an array?

var arr = [10,20,30,50,25,5];
var sum = df.reduce(arr, “+”);

4. How do I sum all the values in a JSON array containing objects?

var json = [{value: 1, name:"foo"}, {value:25}, {value:12,name:"bar"}];
var sum = df.reduce(json, “{value:a.value+b.value}”).value;

5. How do I check if a condition is true for all elements of an array?

var arr = [10,20,30,51,25,5];
var isTrue = dojo.every(arr, “return item % 5==0;”);

6. How do I check if a condition is true for at least one element of an array?

var arr = [10,20,30,51,25,5];
var isTrue = dojo.some(arr, “return item % 5==0;”);

7. How do I find the smallest element in an array?

var arr = [10,20,30,51,25,5];
var min = df.reduce(arr, “Math.min(a,b)”);

8.How do I find the largest element in an array?

var arr = [10,20,30,51,25,5];
var min = df.reduce(arr, “Math.max(a,b)”);

9. How to I calculate the percentage each element of an array makes up of the sum of all elements in the array?

var arr = [10,20,30,51,25,5];
var percents = df.map(arr, “/this”, df.reduce(arr, “+”));

10. How do I generate a running total of an array?

var arr = [1,2,3,4,5];
var runningTotal = df.scanl1(arr, “+”);
//Gives runningTotal=[1,3,6,10,15]

11. How do I create an array where each element is the multiplicand of all elements that came before it and itself?

var arr = [1,2,3,4,5];
var result = df.scanl1(arr, “+”);
//Gives result=[1,2,6,24,120]

12. How do I combine multiple arrays into an equal number of arrays, but arranged by index?

var arraysByIndex = df.zip([1,2,3],[11,22,33],[111,222,333]);
//Gives arraysByIndex=[[1,11,111] , [2,22,222], [3,33,333]]

13. How do I search a dojo.data store for the existance of a named attribute?
//Assume a data store exists called 'store' and items have been retrieved
//and placed in an array called 'items'. We will search for an item that has
//an attribute 'country' equal to 'Ireland'
var found = df.some(items, "this.getValue(item, 'country') == 'Ireland'", store);

14. How do I filter an array to just the items that match a boolean condition?
var array = [22,4,66,100,55];
var over30 = dojo.filter(array, “return item > 30″);
//Gives a new array [66,100,55]. The original array is not modified.

15. How do I find an element in an array?

var array = ["this","is","an","array","of","strings"];
var index = dojo.indexOf(array, “an”);
//returns 2

16. How do I apply a Django Template to one or more nodes?

dojo.require(”dojox.dtl.ext-dojo.NodeList”);

var array = ["some", "sample", "template", "input"];

dojo.query(”.someClass”).dtl(”templates/myTemplate.html”, array);

Share this post:digg it|kick it|Email it|bookmark it|reddit|liveIt

Posted in Ajax, Dojo, Javascript, Technical, dojo.data, dojox, json, open source | 2 Comments »

Dojo Demo Engine Update

Posted by Shane O'Sullivan on 7 January, 2008

A short while ago I posted about the demo engine I’m writing for the Dojo Ajax Toolkit. Click here to read that post or go to http://www.skynet.ie/~sos/js/demo/dojo/dojoc/demos/featureexplorer.html to see it in action.

Update: Version 1.0 of the demo engine has been release. See here.

Features

Since that post, quite a lot of work has gone into both the features and the content of the demo engine, and the development process has solidified nicely. Some of the features include:

  • Tree navigation. A dijit.Tree widget, reading from a remote JSON data store is used to navigate the various demos.
  • Search feature. A dijit.form.ComboBox widget, reading from the same JSON data store as the tree, can be used to dynamically search for demos by matching any part of their name.
  • Theme switcher. A dijit.form.ComboBox widget is used to switch between the CSS styles that Dojo provides.
  • URL addressability. Using a hash identifier (e.g. #Dojo_Query_By%20Class) in the URL of the demo engine causes it to open that demo when it has finished loading. For example, if you click this link, it will open the dojo.query demo showing you how to select nodes by class name. Opening any demo changes the URL in the browser to the URL for that demo, for easy bookmarking.
  • Integrated build process. A simple build script is integrated with the Dojo build process. It builds a JSON data file listing all the existing demos and their respective files. It also builds files with URL links for each demo.

Content

To date, a lot of content has been added. Many, many widgets in Dijit and DojoX
have have been added, including the majority of the Form Controls.

The latest, pretty cool additions have been the IO and dojo.query demos. These cover things such as:

  • Performing a XMLHttpRequest request
  • Using an iFrame transport
  • Submitting a form asynchronously
  • Loading remote JavaScript files from another domain
  • Selecting nodes using CSS selectors with dojo.query
  • Performing operations on the NodeList returned from dojo.query
  • Attaching events to the NodeList returned from dojo.query

File Naming Scheme
A simple file naming scheme is used to add content to the demo framework. Each folder beneath the root folder represents a demo. Each file in a folder must be named the same as the folder, with five possible extensions. For example, given a folder with the name ‘Button‘, the possible files are:

  • Button.html - this contains the demo to be displayed. Any JavaScript code inside <script> tags is executed, and any <link type=”text/css”> and <style> tags have their CSS loaded. The executed code is shown in the View tab, and and the source code is shown in the XML tab. The <html>, <head> and <body> tags are not required.
  • Button.js - this contains pure JavaScript code that performs the same operations as Button.html, if applicable. It is not executed however. It is shown in the JS tab.
  • Button.txt - this contains the text description of the demo. It is loaded above the tabs.
  • Button.links - this contains a JSON array of URL links. The build script transforms these links into HTML, and the result is loaded into the Links tab. One neat feature of this is that all links from sub folders are integrated with the parent folder and displayed in a nested structure. Do, for example, clicking on Dijit will show all the links for all widgets in the Dijit project.
  • Button.full.html - this is standalone demo, that is designed to run outside the demo engine. The View tab provides a link to the external file.
  • sort.txt - this contains a comma separated list of the child folders contained in this folder. It specifies the order in which to display the child demos in the tree. If this file is not specified, then an alphabetical ordering is used.

All of these files are optional. If a file in a folder does not match this naming scheme, it is assumed to be some kind of resource that the demo needs, such as an image or a JSON data file. In this case, the file can be named whatever you like.

The tree structure in the demo engine mirrors the folder layout.

Still To Do

There remains quite a lot of work ahead. There are a few bugs remaining, some more cross browser testing is needed, and of course more content is required, particularly the base Dojo package.

In the relatively near future this should be opened up to the public for development. The Dojo folks are setting up a source control server for community additions, and this demo engine should be part of that. Once that is done, people can start adding all sorts of cool stuff!
Share this post:digg it|kick it|Email it|bookmark it|reddit|liveIt

Posted in Ajax, Demo Engine, Dojo, Javascript, demo, dijit, documentation, dojo.query, dojox, json, open source | 6 Comments »