Activate your free membership today | Log-in

Friday, January 29th, 2010

Addmap.js – automatically analyse a text for geo locations and add a map

Category: Examples, Geo, Google, JavaScript, Mapping, Yahoo!

As part of an upcoming article on geo location I am putting together a few Geo Toys for myself and here is the first one. Addmap.js is a JavaScript that analyses an elements text content, finds geographical locations and links them to Google Maps. It also adds a map preview and a list of the found locations to the element.

See addmap.js in action below - all the content in the green box is generated from the paragraph of text above it. You can try it out for yourself by clicking the screenshot.

Demonstration screenshot of addmap.js

Using addmap.js is easy - sign up for a Google Maps Key and provide it as a configuration parameter. Then call the analyse function with the ID of the element to analyse as the parameter:

XML:
  1. <script src="http://github.com/codepo8/geotoys/raw/master/addmap.js"></script>
  2. <script>
  3. addmap.config.mapkey = 'YOUR_API_KEY';
  4. addmap.analyse('content');
  5. </script>

The script uses YQL and Yahoo PlaceMaker under the hood, for more info and updates on this, check the blog.

Posted by Chris Heilmann at 10:17 am
3 Comments

+++--
3.1 rating from 17 votes

Monday, January 11th, 2010

Using YQL as a proxy for cross-domain Ajax

Category: JSON, JavaScript, XmlHttpRequest, Yahoo!, jQuery

OK, this is nothing shockingly new, but I found it pretty useful. Using jQuery, Ajax has become more or less a one-liner:

JAVASCRIPT:
  1. $(document).ready(function(){
  2.   $('.ajaxtrigger').click(function(){
  3.     $('#target').load($(this).attr('href'));
  4.     return false;
  5.   });
  6. });

This loads the document any link with a class of "ajaxtrigger" points to and updates the content of the element with the ID "target". If the link is a third party link on another domain it fails though - and silently at that. Normally you'd work around that with a server-side proxy, but you can actually do without it.

YQL is a hosted web service that can scrape HTML for you. It also runs the HTML through HTML Tidy and caches it for you. For example to load http://bbc.co.uk you'd use the following statement:

CODE:
  1. select * from html where url='http://bbc.co.uk'

As a URL this turns into:

CODE:
  1. http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D'http%3A%2F%2Fbbc.co.uk'%0A&format=xml
  2.  

You could request JSON-P by setting the output format to json and define a callback, but that would give the HTML back as a massive object which is not nice. YQL also offers JSON-P-X as an alternative which is a JSON object with a callback and the HTML as a string inside a simple Array. See it by clicking the following URL:

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%27http%3A%2F%2Fbbc.co.uk%27%0A&format=xml&diagnostics=false&callback=foo

Now, using jQuery's getJSON() we can load this even without a named callback function. That way we can use one method for content that is third party and simply use load() for the other:

JAVASCRIPT:
  1. $(document).ready(function(){
  2.   var container = $('#target');
  3.   $('.ajaxtrigger').click(function(){
  4.     doAjax($(this).attr('href'));
  5.     return false;
  6.   });
  7.   function doAjax(url){
  8.     if(url.match('^http')){
  9.       $.getJSON("http://query.yahooapis.com/v1/public/yql?"+
  10.                 "q=select%20*%20from%20html%20where%20url%3D%22"+
  11.                 encodeURIComponent(url)+
  12.                 "%22&format=xml'&callback=?",
  13.         function(data){
  14.           if(data.results[0]){
  15.             container.html(data.results[0]);
  16.           } else {
  17.             var errormsg = '<p>Error: could not load the page.</p>';
  18.             container.html(errormsg);
  19.           }
  20.         }
  21.       );
  22.     } else {
  23.       $('#target').load(url);
  24.     }
  25.   }
  26. });

You can see the demo in action here, more details are available on my blog and the source is available on GitHub.

Posted by Chris Heilmann at 7:42 pm
9 Comments

+++--
3.5 rating from 29 votes

Tuesday, January 5th, 2010

Crockford on JavaScript: A Public Lecture Series at Yahoo!

Category: Presentation, Yahoo!

crockford_on_jsDouglas Crockford showed us how JavaScript (or parts of it) could be used to do real software engineering. Now Crockford and Yahoo! are hosting a cool series of public lectures on the language we all love:

Douglas Crockford is Yahoo!'s JavaScript architect and a member of the committee designing future versions of the world's most popular programming language. In the first three months of 2010, Douglas will be delivering his acclaimed series of lectures on the history of JavaScript, its features, and its use.

  1. Monday, January 25: History of JavaScript (RSVP)
  2. Friday, February 5: Survey of the JavaScript Language (RSVP)
  3. Wednesday, February 17: Functions and Inheritance in JavaScript (RSVP)
  4. Wednesday, March 3: JavaScript and the DOM (RSVP)
  5. Wednesday, March 31: Style and Performance in JavaScript (RSVP)

Lectures will be held in URLs Café, Building C, on Yahoo's main campus in Sunnyvale, CA. Doors open at 5:30 p.m.; lectures begin at 6 p.m. Pizza and refreshments will be served. Attendance is free, but seating is limited; RSVP is required for admittance.

I can't wait!

Posted by Brad Neuberg at 6:45 am
9 Comments

++++-
4.3 rating from 23 votes

Wednesday, December 9th, 2009

Three search engines, one interface – 25 minutes live code

Category: Screencast, Tutorial, YUI, Yahoo!

It is amazing how much easier it is these days to build pretty sweet mashups by using hosted services. Here's a screencast of using Yahoo, Bing and Google to build a search interface in under 25 minutes without having to read any API docs or installing SDKs by using YQL:

Building a search mashup with YQL using Google, Yahoo and Bing - live :) from Christian Heilmann on Vimeo.

Give it a lick of paint and you have a pretty sweet little tool:

GooHooBi - search Google, Yahoo and Bing in one go!

All the source code is available on GitHub.

Posted by Chris Heilmann at 12:44 pm
15 Comments

+++--
3.3 rating from 19 votes

Wednesday, September 30th, 2009

YUI 3 Is Out!

Category: Library, Toolkit, Yahoo!

yui_snippet

The YUI team has put out YUI 3.0:

We’re pleased to announce today the general-availability release of YUI 3.0.0. YUI 3’s core infrastructure (YUI, Node and Event) and its utility suite (including Animation, IO, Drag & Drop and more) are all considered production-ready with today’s release.

This is a ground-up redesign of YUI:

  1. Selector-driven: YUI 3 is built around one of the lightest, fastest selector engines available, bringing the expressive power of the CSS selector specification into actions that target DOM nodes.
  2. Syntactically terse: Without polluting the global namespace, YUI 3 supports a more terse coding style in which more can be accomplished with less code.
  3. Self-completing: YUI 3’s light (6.2KB gzipped) seed file can serve as the starting point for any implementation. As long as this seed file is present on the page, you can load any module in the library on the fly. And all modules brought into the page via the built-in loader are done so via combo-handled, non-blocking HTTP requests. This makes loading the library safe, easy and fast.
  4. Sandboxed: YUI modules are bound to YUI instances when you use() them; this protects you against changes that might happen later in the page’s lifecycle. (In other words, if someone blows away a module you’re using after you’ve created your YUI instance, your code won’t be affected.)

It's especially nice to see the new terse YUI namespacing, so you can just type YUI() instead of the older longer syntax.

The cool thing about YUI (and this release) is that it is literally driving the Yahoo! Home Page. That's pretty awesome of Yahoo! to release this code and make it generally available to the wider community. Congrats to the whole YUI team on the new release.

See the original announcement blog post on getting started with YUI 3.0 in 3 easy steps.

Posted by Brad Neuberg at 6:30 am
19 Comments

++++-
4.4 rating from 44 votes

Thursday, September 17th, 2009

YUI 2.8.0 – Local Storage wrapper, better Flash interaction, crossdomain connections and progress bars

Category: Flash, JavaScript, Storage, YUI, Yahoo!

Yahoo this week announced the new release of the Yahooo User Interface library. This is great because it answers the question if the 2.x library is still being maintained whilst 3.0 is out and buzzing. The detailed release notes for YUI 2.8.0 show that there is indeed a lot of maintenance and improvement still being done.

Some of the highlights of the new release are four new components - the Storage Utility, SWFStore Utility, SWF Utility, and the ProgressBar Control.

The Storage Utility is a wrapper for local storage supporting Google Gears, Flash or HTML5 and was submitted by Matt Snider who works for Mint.com.

The SWFStore utility, written by Alaric Cole provides a predictable API for interaction of Flash and JavaScript whilst Allen Rabinovic's SWF Utility is a more granular way of embedding Flash in web sites than SWFobject.

The ProgressBar control by Daniel Barreiro aka Satyam is another example of just how detailed YUI controls are when it comes to exposing custom events. This allows you to either use it out of the box or extend it by overwriting only what you need rather than messing around with the main code of the control.

Other noteworthy changes in YUI with the 2.8.0 release are an extension to the event handling component to support event delegation without having to write it in detail, the connection manager supporting crossdomain requests and getting cut up into smaller on-demand components, and the Carousel control getting a "gallery style".

Check out the more in-depth overview on the YUI blog.

Posted by Chris Heilmann at 5:49 pm
1 Comment

++++-
4.5 rating from 21 votes

Thursday, July 9th, 2009

Pimping JSON – YQL now offers JSONP-X!

Category: JSON, JavaScript, Yahoo!

Yesterday's announcement of Yahoo's YQL now supporting insert, update and delete overshadowed another interesting new feature: JSONP-X output.

Here's what it is and why it is useful: YQL data can be returned in XML which is annoying to use in JavaScript (for starters because of crossdomain issues in Ajax). JSON is much easier as it is native to JavaScript. JSON-P makes it even more easy for us to use as JSON data wrapped in a function call allows us to get the data by creating script nodes dynamically.

Where it falls apart is when you want to get back HTML from some system (not on your own server) and use it in JavaScript. You either need to convert the XML to JavaScript and create HTML elements from it or you need to loop through a JSON construct and assemble HTML from it. JSONP-X works around that step for you. In essence it is XML as a string returned inside a JSON object.

XML:

XML:
  1. <results>
  2.   <div id="following">
  3.     <span>
  4.       <a href="http://twitter.com/codepo8">Codepo8</a>
  5.     </span>
  6.   </div>
  7. </results>

JSON:

JAVASCRIPT:
  1. {"results":[
  2.   "div":{
  3.     "id":"following",
  4.    "span":{
  5.      "a":{
  6.        "href":"http://twitter.com/codepo8",
  7.        "text":"Codepo8"
  8.      }
  9.    }
  10.  }
  11. ]}

JSON-P:

JAVASCRIPT:
  1. foo({"results":[
  2.   "div":{
  3.     "id":"following",
  4.    "span":{
  5.      "a":{
  6.        "href":"http://twitter.com/codepo8",
  7.        "text":"Codepo8"
  8.      }
  9.    }
  10.  }
  11. ]})

JSONP-X:

JAVASCRIPT:
  1. foo({"results":[
  2. "<div id=\"following\"><span><a href=\"http://twitter.com/codepo8\">Codepo8</a></span></div>"
  3. ]})

The way to invoke the JSONP-X output is to provide a format parameter of xml and a callback parameter.

This allows me for example to get the list of people I follow on twitter from my twitter homepage and display it in another document with a few lines of JavaScript without any need of using the API or having a local proxy:

HTML:
  1. <script type="text/javascript" charset="utf-8">
  2. function foo(o){
  3.   var out = document.getElementById('container');
  4.   var content = o.results[0]
  5.   out.innerHTML = content.replace(/href="\//g,'href="http://twitter.com/');
  6. }
  7. </script>   
  8. <script type="text/javascript" src="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Ftwitter.com%2Fcodepo8%22%20and%20xpath%20%3D%20%22%2F%2Fdiv[%40id%3D%27following_list%27]%22&format=xml&callback=foo">
  9. </script>

More details on this are available in this blog post.

Posted by Chris Heilmann at 10:48 am
7 Comments

++---
2.3 rating from 39 votes

Friday, July 3rd, 2009

Machsend: P2P file sharing via Browser Plus

Category: Component, Yahoo!

Alex MacCaw has released Machsend, a Yahoo! Browser Plus plugin that enables P2P file transfers from inside the browser.

It showcases what can be done with a BP plugin, leaving you wish cross browser functionality.

I guess it is kinda fun to hack the browser :)

Posted by Dion Almaer at 5:52 am
5 Comments

+++--
3.2 rating from 13 votes

Thursday, July 2nd, 2009

GeoMaker – geo locations as microformats or a map from texts or URLs

Category: JSON, JavaScript, Yahoo!

As preparation for an upcoming tech talk about Placemaker I thought it would be good to take a bit of the pain out of the geolocation service by making an interface for it. Placemaker works the following way: you post some content or a URL to it, it goes through the content or gets the content from the URL and analyzes it. It then finds geographical locations in the text and disambiguates them (for example to skip names like "Jack London" and not consider it the city London). Finally you get it back as XML.

The annoying thing is that Placemaker only support POST request and does not have a JSON output - for now. GeoMaker allows non-developers to enter some text or a URL, filter the results (using YUI datatable) to remove false positives (no system is perfect) and get the embed code for a Yahoo Map or a list of microformatted locations as copy+paste. See the screencast to get the end user experience:

Of course, every time you build something like that, red-blooded developers will ask for an API to do the same thing (and pointing them to Placemaker wasn't enough). So here it is:

http://icant.co.uk/geomaker/api.php takes two parameters: url of the web document to load and output which could be map, kml, microformats, csv, or json (with callback for JSON-P). Using this you can analyze a url in JavaScript and get the data back as an array:

HTML:
  1. <script>function geomaker(o){
  2.   for(var i=0,j=o.length;i<j ;i++){
  3.     // o[i] will have lat, lon, title and match
  4.   }
  5. }</script>
  6. <script src="http://icant.co.uk/geomaker/api.php?url=http://ajaxian.com&output=json&callback=geomaker"></script>

The Ajaxian.com output right now would be:

JAVASCRIPT:
  1. geomaker(
  2.   [
  3.     {"lat":"42.3586","lon":"-71.0567",
  4.      "title":"Boston, MA, US","match":"Boston"},
  5.     {"lat":"42.3586","lon":"-71.0567",
  6.      "title":"Boston, MA, US","match":"Boston, MA"},
  7.     {"lat":"40.7075","lon":"-106.918","title":"Clark, CO, US",
  8.      "match":"Clark, Co"},
  9.     {"lat":"42.3115","lon":"43.3658","title":"Georgia",
  10.      "match":"Geo"},
  11.     {"lat":"44.9601","lon":"7.16229",
  12.      "title":"Rey, Piedmont, IT","match":"Rey"}
  13.   ])
  14.  

Posted by Chris Heilmann at 3:02 am
9 Comments

+++--
3.7 rating from 12 votes

Thursday, June 25th, 2009

First beta of YUI 3.0 released

Category: JavaScript, Library, Yahoo!

Congrats to the YUI team for releasing their first beta of YUI 3:

We’ve spent a lot of time in this release cycle refining the core elements of YUI 3 — YUI, Node, and Event — to ensure that we have the right API going forward. Performance is improved, and we’ve refined our module/submodule structure. In some cases we’ve added significant new features, including intrinsic support for event delegation in the Event package; however, the focus is on moving the base library to production quality.

Several YUI 2.x components make their YUI 3 debut in this release:

  1. DataSource: YUI’s data abstraction layer provides a standard interface into data sets, regardless of the data’s origin (local, XHR, XSS, etc.) and format (JSON, XML, CSV, etc.);
  2. ImageLoader: ImageLoader allows you to defer the loading of images that aren’t in the viewport when the page paints, throttling bandwidth usage and improving performance;
  3. History: The History component gives you control of the brower’s back button within the context of a single-page web application;
  4. StyleSheet: StyleSheet makes it easy to create and modify CSS rules on the fly, allowing you to dynamically style page elements with fewer repaints.

As part of the more granular packaging in the new codeline, we’ve created separate YUI 3 modules to house functionality that in YUI 2 was bundled with other components. Cache, DataType and DataSchema debut in this release; each of these used to be a part of DataSource.

To keep up to date, check out the roadmap and dashboard that the team keeps up to date.

Posted by Dion Almaer at 6:52 am
Comment here

++++-
4.2 rating from 31 votes

Monday, June 8th, 2009

GeoFill – find users by IP or lookup and prefill forms for them

Category: Library, Yahoo!

One thing that annoys me is that in the days of geolocation and location recognition I still have to enter my country and city in forms over and over again. This is especially annoying when you like in the UK which could be anywhere in these wonderful large dropdowns (UK, England, Great Britain, United Kingdom, Blighty...).

There are many geo lookup tools and a lot of (at least UK) web sites started doing post code lookup tools. This is cool, but as annoying when I spent another reload of a full large form for a postcode lookup that went wrong. With the UK being quite a mess when it comes to post codes this is not uncommon.

Now, to work around these issues I've put together a small JavaScript wrapper library called GeoFill (also available on GitHub). This one makes it easy to provide a "is this your location" functionality in JavaScript:

GeoFill - automatically filling form data with geo information by  you.

GeoFill has two different methods to automatically fill forms with geo information:

  • geofill.find(properties) does an IP lookup of the current user and tries to get the geographical data from that one.
  • geofill.lookup(properties,postcode) tries to get the geographical data from the postcode provided in your form.

Both methods can either automatically fill a form when you provide them with an object telling it which info should go into the form with a given ID, but also have a callback property that allows you to use the data immediately

JAVASCRIPT:
  1. geofill.lookup(
  2.   {
  3.     callback:function(o){
  4.       console.log(o);
  5.   }
  6. },'wc2h8ad');

The returned object is:

JAVASCRIPT:
  1. {
  2.   city:"London",
  3.   country:"United Kingdom",
  4.   latitude:"51.51384",
  5.   longitude:"-0.12857",
  6.   postcode:"WC2H 8AD"
  7. }

The find method uses the GeoIP lookup:

JAVASCRIPT:
  1. geofill.find({
  2.   callback:function(o){
  3.     console.log(o);
  4.   }
  5. });

And returns (in my case):

JAVASCRIPT:
  1. {
  2.   city:"London",
  3.   country:"United Kingdom",
  4.   latitude:"51.5",
  5.   longitude:"-0.11670000106096",
  6.   postcode:"WC2H 8AD"
  7. }

Posted by Chris Heilmann at 5:03 am
1 Comment

+++--
3.6 rating from 18 votes

Friday, May 15th, 2009

A peek under the hood of YUI3 – Satyen Desai on library architecture

Category: Framework, Library, Yahoo!

Talks about JavaScript are not a rare occasion any more, everybody has something to say about this wonderfully versatile language. Douglas Crockford taught us a lot about the language itself, John Resig and Peter Paul Koch taught us how browsers deal (and fail dealing) with it and there are dozens of screencasts of how to use this or that language.

What most of these talks and videos have in common is application of JavaScript and how to deal with issues that will occur. Information about designing and architecting large JavaScript solutions on the other hand are rare. Satyen Desai now broke the silence and gave a great talk on the architecture and design decisions of the the third generation of the Yahoo User Interface library:


Satyen Desai: "YUI 3: Design Goals and Architecture" @ Yahoo! Video

Posted by Chris Heilmann at 5:41 pm
5 Comments

++++-
4.5 rating from 40 votes

Thursday, April 30th, 2009

YQL execute now allows you to convert scraped data with server side JavaScript

Category: Examples, JavaScript, Yahoo!

I am a big fan of YQL, a terribly easy and fuss-free way to access APIs and mix data retrieved from them in a simple, SQL style language. Say for example you want photos of Paris,France from Flickr that are licensed with Creative Commons attribution, you can do this with a single command:

CODE:
  1. select * from flickr.photos.info where photo_id in (select id from flickr.photos.search where woe_id in (select woeid from geo.places where text='paris,france') and license=4)

Try it out here and you see what I mean.

The next step of this interface was to open it out to the public. You can define an "Open Table" as a simple XML schema and bring your own API into this interface with that.

One thing that's been burning on my tongue to tell the world about has been finally released now: YQL execute. Instead of making the YQL language itself much more complex (and thus running in circles) we now allow you to embed JavaScript in the Open Table XML that will run on the YQL server and allow you to access other web services, authenticate and scrape HTML with JavaScript and E4X. As Simon Willison put it:

This is nuts (in a good way). Yahoo!’s intriguing universal SQL-style XML/JSONP web service interface now supports JavaScript as a kind of stored procedure language, meaning you can use JavaScript and E4X to screen-scrape web pages, then query the results with YQL.

Using this, you can augment the original functionality of YQL to whatever you need. For example, you can scrape HTML with YQL using XPATH, but there was no way to use CSS selectors. Using an open table that invokes James Padolsey's css2xpath JavaScript on the server side, this is now possible.

CODE:
  1. use 'http://yqlblog.net/samples/data.html.cssselect.xml' as data.html.cssselect; select * from data.html.cssselect where url="www.yahoo.com" and css="#news a"

Run this query in YQL

The data table is pretty easy:

XML:
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
  3.   <meta>
  4.     <samplequery>select * from {table} where url="www.yahoo.com" and css="#news a"</samplequery>
  5.   </meta>
  6.   <bindings>
  7.   <select itemPath="" produces="XML">
  8.     <urls>
  9.       <url></url>
  10.  
  11.     </urls>
  12.     <inputs>
  13.       <key id="url" type="xs:string" paramType="variable" required="true" />
  14.       <key id="css" type="xs:string" paramType="variable" />
  15.     </inputs>
  16.       <execute><![CDATA[
  17.    //include css to xpath convert function
  18.    y.include("http://james.padolsey.com/scripts/javascript/css2xpath.js");
  19.    var query = null;
  20.    if (css) {
  21.       var xpath = CSS2XPATH(css);
  22.       y.log("xpath "+xpath);
  23.       query = y.query("select * from html where url=@url and xpath=\""+xpath+"\"",{url:url});
  24.    } else {
  25.       query = y.query("select * from html where url=@url",{url:url});
  26.    }
  27.    response.object = query.results;
  28.       ]]></execute>
  29.     </select>
  30.   </bindings>
  31. </table>

Check the official Yahoo Developer Network blog post on YQL execute for more examples, including authentication examples for flickr and netflix.

Posted by Chris Heilmann at 9:28 am
15 Comments

+++--
3.9 rating from 27 votes

Friday, April 3rd, 2009

Poller: YUI3 Small Polling Component

Category: JavaScript, Yahoo!

Eric Ferraiuolo has created a YUI3 component for smart polling which means:

  • Use conditional GET requests
  • Retain the most recent Etag and Last-Modified date of the polled resource
  • Disable polling when the browser window is inactive

Implementing a smart polling process in our application’s rich UI gives us some desired benefits:

  • Removal of the refresh button
  • Automatic updating of the UI when the resource on the server has changed
  • Less repainting of the page since the DOM is touched only when the data has changed
  • Changes to the UI only happen when the window is active (the user sees them) as polling is paused while the user is doing something else

The component that Eric wrote means that you can set of a poller like this:

JAVASCRIPT:
  1.  
  2. var poller = new Y.Poller({
  3.     url : 'data.json',
  4.     headers : {"foo":"bar"},
  5.     interval : 7000,
  6.     pauseInactive : true
  7. });
  8. poller.on( 'request', logRequestData );
  9. poller.on( 'response', logResponseData );
  10. poller.on( 'modified', updateUI );
  11. poller.start();
  12.  

Posted by Dion Almaer at 6:05 am
1 Comment

+++--
3.7 rating from 29 votes

Wednesday, March 18th, 2009

Super fast client side searches – the Flickr way

Category: Examples, JSON, Performance, XmlHttpRequest, Yahoo!

Over at the Flickr development blog, Ross Harmes, one of those lesser sung JavaScript heroes explains in detail how Flickr creates really fast client side searches and one of the implementations of these findings is the newly released find people faster feature:

find people faster feature on flickr

The main findings of the team were that eval() is not only evil but also very slow whereas dynamic script nodes are fast but insecure. The solution was to do a custom evaluation of string data rather than using JSON:

Having set the performance bar pretty high with the last approach, we dove into custom data formats. The challenge would be to create a format that we could parse ourselves, using JavaScript’s String and RegExp methods, that would also match the speed of JSON executed natively. This would allow us to use Ajax again, but keep the data restricted to our domain.

Since we had already discovered that some methods of string manipulation didn’t perform well on large strings, we restricted ourselves to a method that we knew to be fast: split(). We used control characters to delimit each contact, and a different control character to delimit the fields within each contact. This allowed us to parse the string into contact objects with one split, then loop through that array and split again on each string.

JAVASCRIPT:
  1. that.contacts = o.responseText.split("\\c");
  2.  
  3. for (var n = 0, len = that.contacts.length, contactSplit; n &lt;len; n++) {
  4.  
  5.         contactSplit = that.contacts[n].split("\\a");
  6.  
  7.         that.contacts[n] = {};
  8.         that.contacts[n].n = contactSplit[0];
  9.         that.contacts[n].e = contactSplit[1];
  10.         that.contacts[n].u = contactSplit[2];
  11.         that.contacts[n].r = contactSplit[3];
  12.         that.contacts[n].s = contactSplit[4];
  13.         that.contacts[n].f = contactSplit[5];
  14.         that.contacts[n].a = contactSplit[6];
  15.         that.contacts[n].d = contactSplit[7];
  16.         that.contacts[n].y = contactSplit[8];
  17. }

Once this had been speeded up, all they needed to use was the YUI AutoComplete control and voilà - fast client side searches even with massive datasets.

Posted by Chris Heilmann at 2:38 pm
9 Comments

+++--
3.7 rating from 17 votes

Sizzlin’ YUI

Category: CSS, Yahoo!

Eric Ferraiuolo has picked up on the work that Matt Sweeney has done integrating Sizzle with YUI3:

Great news for YUI3: Matt Sweeney, a YUI Developer, has integrated the Sizzle JavaScript Selector Library in a branch of the YUI3 code-base on GitHub. There has been interest from the community about this integration for quite some time. I personally was hoping for Sizzle adoption into YUI3; this now appears to be the case.

Using the Selector utility in YUI2 I would find myself hitting bugs and roadblocks where my expectations weren’t matching the outcomes. I’ve felt since first using the selector engine in YUI that it didn’t compare in speed, robustness, or completeness to jQuery’s. With the Sizzle project, there’s a narrow focus and distinct vision: To make the best damn selector engine. Since a selector engine is an essential component to any modern JavaScript library, why not make one really good one for all libraries to use? That’s the route the Sizzle project has taken.

Once Sweeney’s branch is merged into the YUI3 Master Head, I’ll be doing a git pull and give it some exercise.

Posted by Dion Almaer at 5:52 am
Comment here

+++--
3.5 rating from 2 votes

Next Page »