Archive for February, 2006

AJAX Amazon Music Search

Sunday, February 26th, 2006

Put together an AJAX demo using Amazon’s webservice API. Basically type in an artist name or song title and it’ll return the first 10 hits from Amazon’s music search. It’s using script.aculo.us for the ‘Grow’ effect when the results return. the search itself is triggered via java script, and parsed locally. The result also triggers a contextual AdSense ad. Tried a few different ideas and seems an embedded iframe worked best. My goal was to make it work without a page reload. So to get an AdSense ad that is contextual to the search I needed to generate a url and title string from the query itself. Anything else seemed to lead to generic ads. I’m sure there are ways to improve on it. If you’ve got an idea leave a comment!


AJAX Amazon Music Search

YubNub Suggest – Reloaded (Dojo)

Saturday, February 25th, 2006

First YubNub Suggest example used script.aculo.us. This time tried Dojo’s autocomplete code. Smoother auto complete, including support for arrow keys, but has a harder time selecting an option. Doesn’t seem to like space as a keystroke selector. You can try it out for yourself.

YubNub Suggest (Dojo)

Firefox Array.toString() is very slow

Thursday, February 23rd, 2006

Ran into an interesting problem with JavaScript’s Array.toString() in Firefox.  It’s extremely slow even for a very small array.  Take an array with a single object and you’d like to call toString() to get the type of the contained object.  There are better approaches but for simple uses this might be applied.  In this case toString() of the underlying object simple returns the object’s name.  This is a very common use of toString() on custom objects. In Firefox calling toString() on the Array is nearly ten times slower than calling toString() on the object itself.  In Internet Explorer it’s about three times slower.  Needless to say be very careful with JavaScript’s Array.toString(), as it’s not a transparent call into the underlying objects performance wise.

Internet Explorer 6
anArray.toString() – 1829
anObect.toString() – 625

Firefox 1.5.0.1
anArray.toString() – 3093
anObect.toString() – 375

The full test script is posted below.


var anArray = [];
var anObject = {};
anObject.toString = function() {return “anObject”;};
anArray.push(anObject);

var startTime,endTime,i;
var repeat = 250000;

startTime=new Date().getTime();
for(i = 0; i < repeat; i++) {
anArray.toString();
}
endTime=new Date().getTime();
var arrayToStringResult = endTime - startTime;

startTime=new Date().getTime();
for(i = 0; i < repeat; i++) {
anObject.toString();
}
endTime=new Date().getTime();
var objectToStringResult = endTime - startTime;

document.write("anArray.toString() - " + arrayToStringResult);
document.write("<br/>");
document.write("anObect.toString() - " + objectToStringResult);

AJAX Auto Complete

Monday, February 20th, 2006

Few sites these days are using AJAX Auto Complete to help users filter known choices or reduce typing.  As more AJAX libraries are released this practice should appear more frequently. Autocomplete generally comes in two flavors; Local Auto Complete and remote or server based auto complete.  Local auto complete loads all the data locally into memory and then parses/pages through the data entirely in JavaScript.  Server based auto complete like Google Suggest send async queries to a server as the user types.  Local autocomplete works well when the entire data set is small enough to process at once think hundred’s or thousand’s or items.  Ten’s of thousands may be possible depending on how complex the data and what type of matching is used.  Prefix matching requires less processing that a full search for prefix, sufix, and contains matches.  The Yahoo UI Team has posted a design pattern on Auto Complete and plan to release code as part of their UI Library. script.aculo.us includes support for both Local and Server autocomplete.  They have a few demos posted that you can try yourself.

UPDATE: A couple demo’s of my own:

YubNub Suggest
Dojo Autocomplete

YubNub Suggest

Monday, February 20th, 2006

YubNub has been around for sometime. I went looking for a Suggest version that would autocomplete common commands. I did a few searches and all I came up with was DashNub which is an OSX Widget.  Using script.aculo.us’s autocomplete code and the XML feed for the YubNub Golden Eggs. My YubNub example now has basic autocomplete.  Any YubNub command can be used but autocomplete only works for the 400-500 Golden Eggs.

YubNub Suggest

Note:
 - It’s only been tested in Firefox 1.5.01

TODO:
 - Test in other browsers
 - Add descriptions to each command
 - Allow selecting with arrow keys