Archive for March, 2006
AJAXing with Dojo, Part One
Introduction
Over the past few months, I’ve been reading up a lot on “AJAX“, Asynchronous JavaScript And XML, which initially I just thought was the latest buzzword for the egregious use of JavaScript. Well, it is and it isn’t. I ordered the O’Reilly JavaScript book, read a good deal of it, and started adding cool client-side JS tricks to my web apps. Unfortunately the book doesn’t touch on XMLHttpRequest() at all, which is really the crux of AJAX.
There is a lot of information on XMLHttpRequest() and AJAX out there on the ‘net, so I wasn’t that concerned about its lack of coverage in O’Reilly’s so-called Definitive Guide. I needed a book about the JavaScript fundamentals, and that was my main reason for buying it.
My first real-world use of AJAX-like techniques was in an application where I used a lot of tags, with onclick="doThis(bar)" JavaScript event thingies. (Yes, thingies is a technical term). The event handlers that I set up used the innerHTML property to dynamically change the content of the page in the browser. It worked, its really neat, and its heading in the right direction — but its not really what AJAX is all about.
The XML in AJAX is really very important to the system. Its use, together with the DOM, allows you to leave the onclick thingies out of your HTML and the innerHTML properties out of your JavaScript. You assign custom event handlers to the nodes of your DOM, and send XML-formatted replies back from your server-side script in order to affect real-time changes to the document loaded in your browser. It sounds complicated, and it is a bit, but the good news is that there are a lot of very clever people who have created tools to simplify the process.
One of those tools, or toolkits, is called Dojo. While Dojo is an ingenious toolkit, the documentation is sparse and highly technical, and it seems to assume a lot of prior knowledge. So while I try to hunt down the information that I need to get started with using Dojo, I’ll chart my progress here on my blog, in the hopes that others will find it useful.
Down to Business
At the top of my HTML, I include what I hope is the necessary Dojo files, plus my own js file, “mycode.js”:
...
I don’t have good reasons for choosing the dojo.require() bits that I did – I’m just hoping that it adds the very basic functions that need for now, and I’ll learn as I go about what modules contain which parts and functions that will be useful for me.
I’m going to start with something extremely basic: executing a function when a user clicks on a checkbox. Here’s the part of my HTML to which I’ll be assigning a JavaScript function:
Look Mom! No “onclick()”!
Now for my JavaScript code in the included “mycode.js” file. I really struggled with an error that I kept getting:
Error: bad srcObj for srcFunc: onclick
Dojo even spit this error out, prefixed with the word FATAL. I couldn’t see why, and going back to my old “onclick(myfunction())” in the tag fixed the problem. The solution was given to me by some kind folks in #dojo on IRC.
The problem was that the global javascript code was being loaded by the browser before the HTML, and it referenced objects that the browser didn’t yet know about. One solution — for now — is to use another javascript function, onLoad(), to load my code after the page is done loading. So here is the working code with Dojo’s built-in onLoad function:
dojo.addOnLoad( function() {
/* When user clicks the "register"
* checkbox, do something, anything!
*/
dojo.event.connect( dojo.byId("register_checkbox"),
"onclick",
function() {
var O = dojo.byId("register_checkbox");
alert("Have an object:" + O + "!");
});
});
Not a very useful set of anonymous functions! It is however my first baby steps towards working with Dojo to assign JavaScript functions to HTML elements. When I click on the checkbox identified by the id=”register_checkbox”, I get a pop-up message that says:
Have an object:[object HTMLInputElement]!
The thing to note here is the 3 arguments passed to dojo.event.connect() – one an HTML element, the second the javascript event, and the last is an anonymous function which could actually be the name of a separate function. If you do use a separate, named function, be sure to put it in double quotes, and do not use (). So for example, another way of writing it would be:
function Bar() {
var O = dojo.byId("register_checkbox");
alert("Have an object:" + O + "!");
}
dojo.event.connect( dojo.byId("register_checkbox"),
"onclick', "Bar" );
Part 2, coming soon.
Want on board the iPhone Gold Rush?
Click Here.
How Yahoo! Can Monetize Flickr
One of the podcasts that I listen to on a regular basis is This Week in Tech. In this week’s edition, they covered the issue of Yahoo! loosing a lot of money on their recent Web 2.0 acquisition, the photo hosting/sharing site, Flickr. Flickr uses a lot of resources, and presently their only way of making money from it is to charge for prints and DVDs of their photos. About 80 people per week, out of about 10 million subscribers, actually use these services. I believe that they also charge for other things too, like more disk space and such, but anyways the issue is that they are loosing a lot of cash on it.
John Dvorak claimed on the program that Flickr is not a monetizable system, then turned around and suggested that they could take advantage of their advertising program by putting ads on the site in conjunction with their Tags — it is the tags that make Flickr unique, it would be simple to integrate tag searches with their “adsense-like” Yahoo! Ads.
I think that they could take that a step further, and integrate tagged Flickr photos into their advertising program via search results, in conjunction with a better print ordering system that would reward the photographers with a revenue stream.

Here’s what I have in mind. When people type in a search term on Yahoo!’s search, a few Flickr photos would appear in the side bar of the search results, photos that have tags which match the search keywords. This would draw traffic to Flickr. It might be relevant traffic too: if I’m searching for “lamas”, I might be interested in seeing a picture of one. The hosted Flickr image might also have ways of contacting the photo’s author so that I could ask questions, etc..
When the search user clicks on one of the thumbnails in the search results, they would go to a larger version of the image on the Flickr site, which would have Yahoo! ads for more advertising exposure. If the user clicks on those ads, the ones around the photo, the “author” of the photo, the photographer, would get a cut of the ad revenue. Also, the search user would have the option of ordering a high-quality copy of the image, and of course the photographer would also get a cut of that revenue. This way advertisers get exposure to the 10 million Flickr users, and the Flickr users (who sign up for the program) have a chance to make a bit of money from their photography skills, at the same time expanding Yahoo!’s advertising empire.
This scheme has the added benefit of proliferating the relevance of tags on the ‘net, which is said to be one of the main features of the next generation of the web, “2.0″. The downside would be the risk of the business community flooding Flickr with stupid product pictures — there would have to be some policing for that.
5 commentsSunshine’s Massive Terrain
Its amazing how much terrain that you can cover in a morning at Sunshine. We started off yesterday by skinning out to Wawa Ridge. The travel conditions were good, but the snow at the ridge was very skied out from the past few days, with a mixed condition sun crust that was quite difficult to ski.
Back to the subject of massive terrain, from wawa I took a photo of the Delirium Dive area, and then from Delirium Dive took a photo of Wawa, to illustrate how much area we covered in only 3 hours. The red squares in the photos indicate the locations from which I took the shots. Here is Delirium Dive, shot from Wawa Ridge:
The conditions in the Dive were pretty good in general, considering the lack of snow over the past few days. There was about 15cm of loose snow at the very top, then some difficult crust closer to the first set of rock-bands, followed by packed powder that made for some nice turns. We took a skier’s right at the bottom and skied Fat Boy, where there was about 20cm of nice loose snow on top of a soft crust; IMO the best skiing in the whole area.
Here is Wawa Ridge, as seen from the top of Galaxy 1 chute in Delirium Dive; the red square indicates the area that the above shot was taken from:
The Wawa-Delirium circuit provides a nice little mini-adventure that, with the appropriate gear, can be easily covered in a morning.
1 commentGreat Conditions at Lake Louise
It was a particularly gorgeous morning at Lake Louise yesterday. With clouds flowing low through the Bow Valley like a river, the upper elevations at the resort had breath-taking views:
There was 5-10cm of new snow, which had formed a surface hoar that made for fantastic skiing. The places to be, IMO, were in the back-bowls, A-H gullies. However, even the often-icey front-side offered packed powder and pockets of loose snow, so it was generally good all-around.
No commentsHot Peppers Kill Prostate Cancer Cells?
News headlines today are burning up with the release of new research from the University of California that shows that capsaicin, the active ingredient in hot peppers, kills human prostate cancer cells. Unfortunately, thats not what the researchers actually said. At least, not according to New Scientist:
But Koeffler says that men concerned about prostate cancer should not interpret these findings as a reason to up their consumption of hot peppers. He stresses that the compound has not been shown to prevent prostate cancer but instead simply slows its growth. And he adds that he hopes to see human trials in the next two years assessing capsaicin’s effect on prostate cancer.
I love spicy food, but on the other hand, even the most extreme hot pepper nuts that I know couldn’t ingest the kind of heat that Koeffler’s mice were subjected to. According to New Scientist, a 200lb person would need to consume ten fresh habañera peppers per week, which is roughly the heat-equivalent of eating eighty jalapeños in order to attain the cancer-slowing effect that was observed by Koeffler and his colleagues. I find that one jalapeño per meal is spicy enough; hard to imagine over eleven per day. Imagine how the mice felt!





