Activate your free membership today | Log-in

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
2 Comments

++++-
4 rating from 6 votes

Wednesday, July 1st, 2009

A whole lot of testing for JavaScript implementations

Category: JavaScript, Standards

A couple of releases related to unit testing and JavaScript came out on the same day.

First, the JScript team posted a set of ECMAScript 5 tests.... 900 to be exact, and the focus on features that are new to ECMAScript 5.

All of the tests are released under New BSD.

Then, the V8 team announced Sputnik, a series of of 5000 tests, also under BSD. These tests aren't for the shiny ECMAScript 5 world, but are for ECMA 262, or edition 3.

Nice to see a lot of tests out there, all under liberal open source licensing.

Posted by Dion Almaer at 7:42 am
Comment here

++++-
4.1 rating from 17 votes

Tuesday, June 30th, 2009

LABjs: Simple abstraction for loading dependencies correctly

Category: JavaScript, Performance

Kyle Simpson has developed LABjs, a library that lets you define your JavaScript file dependencies, and then loads them as efficiently as possible.

Kyle told us:

This project is a simple little tool (1.6k compressed!) for being able to load javascript files dynamically. It's like a lot of similar projects where the goal is to improve the speed of page load by allowing scripts to load in parallel. The thing it does slightly differently than most others like it is it allows you to "block", which is to say, load one or more scripts in parallel, then wait for them to finish, before going on to something else, like loading more scripts.

What I wanted was a pattern where I could load scripts in parallel, just like with script tags, but also block and wait if there was an explicit ordering dependency that required it.

What most loaders fail to do well is let you define "dependencies" simply based on loading order. With regular script tags, the browser blocks for you, so you can make sure for instance that jquery.js loads before jqueryui.js. But imagine you've got 3 scripts that can download in parallel (not dependent on each other), and then two more that need to wait for those 3 to load. You can't do that with script tags, and you also can't do that very easily with a lot of the script loaders/frameworks that I've found.

Most of them rely on intrusive concepts to do "dependency" management. For instance, each child script has to "signal" (callback) that it's done loading, to the parent page. Or the parent script and child scripts have to explicitly declare dependencies using some framework or conventions. Also, some other loader libraries rely on attaching a single load callback handler for EACH script. This makes it awkward or difficult to wait for several to load at a time, before proceeding, since you as the author have to keep track of what has loaded yourself.

jsLAB lets you load pretty much any script file, whether you control it or not, with no intrusion or convention for dependencies, other than the order and blocking that you define. It keeps track of what you've asked for and what has downloaded, only loads a unique script filename once, and lets you only define your handler once for a set of scripts that will load together in parallel. The API style (with chaining) makes is very easy to convert a set of script tags in your page into code to load them, without having to worry that race conditions will cause issues for scripts loading in the wrong order if there are implicit dependencies involved.

Example

Old:

HTML:
  1.  
  2. <script src="jquery.js"></script>
  3. <script src="jquery.ui.js"></script>
  4. <script src="myplugin.jquery.js"></script>
  5. <script src="initpage.js"></script>
  6.  

New:

JAVASCRIPT:
  1.  
  2. $LAB
  3. .script("jquery.js")
  4. .block(function(){
  5.       $LAB
  6.       .script("jquery.ui.js")
  7.       .script("myplugin.jquery.js")
  8.       .block(function(){
  9.             $LAB.script("initpage.js");
  10.       });
  11. });
  12.  

In the above example, "jquery.ui.js" and "myplugin.jquery.js" can load in parallel because there's no dependencies, but they will wait for "jquery.js" to load first, since they depend on it, and then "initpage.js" will wait for all of them to load before it runs, to it makes sure all code it will call is in place, similar to a $document.ready(...) concept.

The page link above also shows a few other variations on the .script(...) signature. For instance, you don't have to do a single script() call for each file (though I think it makes thing more readable). You can pass as many scripts singularly as parameters to one script() call. You can also pass an array of scripts, and it will loop through them and load them in the same way. Lastly, you can pass in an object instead of string, and the object literal can contain "src", "type", and "language" specifications, if you want to override the defaults of "text/javascript" and "Javascript", for some reason.

Posted by Dion Almaer at 6:16 am
23 Comments

+++--
3.8 rating from 21 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

JavaScript sandbox using Web Workers

Category: JavaScript, Library

We have been sandboxing JavaScript in iframes for a long time. The Web Worker API has the nice property that it doesn't have access to objects like document and the like, and just runs code that you can pass over to it.

With this, Elijah Grey has created an experimental jsandbox API that gives you an eval function that you pass in some code, and optionally input data, callback for results, and an onerror callback.

Code looks like this:

JAVASCRIPT:
  1.  
  2. jsandbox
  3.     .eval({
  4.       code    : "x=1;Math.round(Math.pow(input, ++x))",
  5.       input   : 36.565010597564445,
  6.       callback: function(n) {
  7.           console.log("number: ", n); // number: 1337
  8.       }
  9.   }).eval({
  10.       code   : "][];.]\\ (*# ($(! ~",
  11.       onerror: function(ex) {
  12.           console.log("syntax error: ", ex); // syntax error: [error object]
  13.       }
  14.   }).eval({
  15.       code    : '"foo"+input',
  16.       input   : "bar",
  17.       callback: function(str) {
  18.           console.log("string: ", str); // string: foobar
  19.       }
  20.   }).eval({
  21.       code    : "({q:1, w:2})",
  22.       callback: function(obj) {
  23.           console.log("object: ", obj); // object: object q=1 w=2
  24.       }
  25.   }).eval({
  26.       code    : "[1, 2, 3].concat(input)",
  27.       input   : [4, 5, 6],
  28.       callback: function(arr) {
  29.           console.log("array: ", arr); // array: [1, 2, 3, 4, 5, 6]
  30.       }
  31.   }).eval({
  32.       code    : "function x(z){this.y=z;};new x(input)",
  33.       input   : 4,
  34.       callback: function(x) {
  35.           console.log("new x: ", x); // new x: object y=4
  36.       }
  37.   });
  38.  

Posted by Dion Almaer at 6:17 am
2 Comments

+++--
3 rating from 14 votes

Wednesday, June 24th, 2009

MooTools: Saving the dollars, replacing document.write

Category: JavaScript

The religion behind a simple $ has been fierce in the Web world. MooTools has decided to make the Dollar Safe Mode which is similar to cousins such as jQuery.noConflict (in MooTools case it just looks for the $ function). Now you can just use document.id if you want to play in the wild, or wrap up in a closure to be nice:

JAVASCRIPT:
  1.  
  2. (function(){
  3.     var $ = document.id;
  4.  
  5.     this.X = new Class({
  6.         initialize: function(element){
  7.             this.element = $(element);
  8.         }
  9.     });
  10. })();
  11.  

Please note that MooTools will probably remain incompatible with other frameworks that modify native prototypes, as there will probably be more name clashes. This isn’t a cross-framework compatible MooTools version by any means, nor does it want to be. The whole point is not to “steal” the dollar function from other libraries.

In other MooTools news, MooTools Core Dev Thomas Aylott (subtleGradient) shows another example of overriding document.write():

I created a replacement for document.write that saves the arguments and then injects them into the page after the dom is ready. This is useful for embedding gists on your page since you can use the additional filter option to reject stuff from being written to your page. This would also be really handy for sites that include JavaFX or certain ads or anything that requires the use of document.write on your page. By deferring the injection of that stuff until after the dom is ready your visitors see the page content before any of the extras like Java applets or ads begin to load.

Posted by Dion Almaer at 6:28 am
5 Comments

+++--
3.6 rating from 28 votes

Friday, June 19th, 2009

NodeIterator.areYou(IMPRESSED | WHOCARES | WHA?)

Category: JavaScript

John Resig has posted on the DOM traversal methods now in Firefox 3.5 and then a spin out post on the merits of the NodeIterator API. He isn't impressed:

This API is, at best, bloated, and at worst incredibly misguided and impractical for day-to-day use.

Observe the method signature of createNodeIterator:

JAVASCRIPT:
  1.  
  2. var nodeIterator = document.createNodeIterator(
  3.   root, // root node for the traversal
  4.   whatToShow, // a set of constants to filter against
  5.   filter, // an object with a function for advanced filtering
  6.   entityReferenceExpansion // if entity reference children so be expanded
  7. );
  8.  

This is excessive for what should be, at most, a simple way to traverse DOM nodes.

One part of the critique involves the common pattern of bitwise operators that are common in C, C++, and a bit of Java (and elsewhere too). When space is at a premium, these are a good choice. There are also some nice side effects when you use them (building up the flags, munging them later, etc).

However, as John points out, these are more for CSci students than for the average Web developer.

But then the crazy comes in: In order to select multiple, different, types of nodes you must OR together the properties to creating a resulting number that'll be passed in.

For example if you wanted to find all elements, comments, and text nodes you would do:

JAVASCRIPT:
  1.  
  2. NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT
  3.  
I'm not sure if you can get a much more counter-intuitive JavaScript API than that (you can certainly expect little, to no, common developer adoption, that's for sure).

He goes on to propose some more Webby APIs such as:

JAVASCRIPT:
  1.  
  2. document.getNodes( Element, Comment, Text );
  3.  

Posted by Dion Almaer at 2:09 pm
14 Comments

+++--
3.4 rating from 23 votes

Serial Asynchronous XmlHttpRequests

Category: Dojo, JavaScript

By default we should always favour asynchronous XHR to help the responsiveness of our Web applications. However, have you ever wanted a way to serialize your XHR calls because you needed to do things in sequence as B relied on what came back from A?

You could call a synchronous Ajax call, but that locks up the browser. Thibaud Lopez Schneider has written up his thoughts here showing the difference between synchronous Ajax:

and async calls with magic to serialize them:

He then went and created a simple example code generator at asynchronous.me. It is interesting to look at the code of the serialized version, and see that it doesn't do anything complex.... just passes in the next function to run as a callback:

JAVASCRIPT:
  1.  
  2. function run() { 
  3.     request1(function () { 
  4.         request2(function () { 
  5.             request3(function () { 
  6.                 done()
  7.             })
  8.         })
  9.     })
  10. } 
  11. function request1(callback1) { 
  12.     // request 1 
  13.     print("request1")
  14.     var xmlHttpRequest1 = new XMLHttpRequest()
  15.     xmlHttpRequest1.open("GET", "something1?hello1", true)
  16.     xmlHttpRequest1.onreadystatechange = function () { 
  17.         if (this.readyState == 4 && this.status == 200) { 
  18.             // response 1 
  19.             print("response1=" + this.responseText)
  20.             // continue execution in the callback 
  21.             if (callback1) { 
  22.                 callback1()
  23.             } 
  24.         } 
  25.     }
  26.     xmlHttpRequest1.send()
  27. } 
  28. function request2(callback2) { 
  29.     // request 2 
  30.     print("request2")
  31.     var xmlHttpRequest2 = new XMLHttpRequest()
  32.     xmlHttpRequest2.open("GET", "something2?hello2", true)
  33.     xmlHttpRequest2.onreadystatechange = function () { 
  34.         if (this.readyState == 4 && this.status == 200) { 
  35.             // response 2 
  36.             print("response2=" + this.responseText)
  37.             // continue execution in the callback 
  38.             if (callback2) { 
  39.                 callback2()
  40.             } 
  41.         } 
  42.     }
  43.     xmlHttpRequest2.send()
  44. } 
  45. function request3(callback3) { 
  46.     // request 3 
  47.     print("request3")
  48.     var xmlHttpRequest3 = new XMLHttpRequest()
  49.     xmlHttpRequest3.open("GET", "something3?hello3", true)
  50.     xmlHttpRequest3.onreadystatechange = function () { 
  51.         if (this.readyState == 4 && this.status == 200) { 
  52.             // response 3 
  53.             print("response3=" + this.responseText)
  54.             // continue execution in the callback 
  55.             if (callback3) { 
  56.                 callback3()
  57.             } 
  58.         } 
  59.     }
  60.     xmlHttpRequest3.send()
  61. } 
  62. function done() { 
  63.     // end 
  64.     print("done")
  65. }
  66.  

You can compare that approach to Dojo Deferred:

JAVASCRIPT:
  1.  
  2.     function run() { 
  3.         request1().addCallback(request2).addCallback(request3).addCallback(done)
  4.     } 
  5.     function request1() { 
  6.         // request 1 
  7.         print("request1")
  8.         var deferred = dojo.xhrGet({ 
  9.             url: "something1?hello1"
  10.             load: function (response) { 
  11.                 // response 1 
  12.                 print("response1=" + response);           
  13.             } 
  14.         })
  15.         return deferred; 
  16.     } 
  17.     function request2() { 
  18.         // request 2 
  19.         print("request2")
  20.         var deferred = dojo.xhrGet({ 
  21.             url: "something2?hello2"
  22.             load: function (response) { 
  23.                 // response 2 
  24.                 print("response2=" + response)
  25.             } 
  26.         })
  27.         return deferred; 
  28.     } 
  29.     function request3() { 
  30.         // request 3 
  31.         print("request3")
  32.         var deferred = dojo.xhrGet({ 
  33.             url: "something3?hello3"
  34.             load: function (response) { 
  35.                 // response 3 
  36.                 print("response3=" + response)
  37.             } 
  38.         })
  39.         return deferred; 
  40.     } 
  41.     function done() { 
  42.         // end 
  43.         print("done")
  44.     } 
  45.  

Posted by Dion Almaer at 6:45 am
12 Comments

++---
2.6 rating from 30 votes

Thursday, June 18th, 2009

JavaScript Compatibility Tests

Category: JSON, JavaScript

Robert Nyman has setup a really nice test suite for JavaScript 1.6, 1.7, and 1.8+ features such as getters/setters, Object.defineProperty, Object.getPrototypeOf, new String extras, and JSON.

It includes compatibility tables, and will try to run the tests on your browser to give you feedback. It also includes sample code to check web browser support that you can use in your own projects.

Nice job Robert!

Posted by Dion Almaer at 10:25 am
2 Comments

++++-
4.5 rating from 19 votes

Named function expressions in incredible detail

Category: Articles, JavaScript

The intrepid JS hacker Juriy "kangax" Zaytsev has an incredibly detailed post on demystifying named function expressions:

Surprisingly, a topic of named function expressions doesn’t seem to be covered well enough on the web. This is probably why there are so many misconceptions floating around. In this article, I’ll try to summarize both - theoretical and practical aspects of these wonderful Javascript constructs; the good, bad and ugly parts of them.

In a nutshell, named function expressions are useful for one thing only - descriptive function names in debuggers and profilers. Well, there is also a possibility of using function names for recursion, but you will soon see that this is often impractical nowadays. If you don’t care about debugging experience, you have nothing to worry about. Otherwise, read on to see some of the cross-browser glitches you would have to deal with and tips on how work around them.

He then goes into a ton of examples of weirdness in different browsers, and fun code like this:

JAVASCRIPT:
  1.  
  2.     var f = function g() {
  3.         return 1;
  4.     };
  5.     if (false) {
  6.         f = function g(){
  7.             return 2;
  8.         }
  9.     };
  10.     g(); // 2
  11.  

and

JAVASCRIPT:
  1.  
  2.   var f = function g(){
  3.     return [
  4.       arguments.callee == f,
  5.       arguments.callee == g
  6.     ];
  7.   };
  8.   f(); // [true, false]
  9.  

Finally, he shows a couple of techniques for using these correctly in the real world need of shimming:

JAVASCRIPT:
  1.  
  2. // 1) enclose declaration with a separate scope
  3.   var addEvent = (function(){
  4.  
  5.     var docEl = document.documentElement;
  6.  
  7.     // 2) declare a variable to assign function to
  8.     var fn;
  9.  
  10.     if (docEl.addEventListener) {
  11.  
  12.       // 3) make sure to give function a descriptive identifier
  13.       fn = function addEvent(element, eventName, callback) {
  14.         element.addEventListener(eventName, callback, false);
  15.       }
  16.     }
  17.     else if (docEl.attachEvent) {
  18.       fn = function addEvent(element, eventName, callback) {
  19.         element.attachEvent('on' + eventName, callback);
  20.       }
  21.     }
  22.     else {
  23.       fn = function addEvent(element, eventName, callback) {
  24.         element['on' + eventName] = callback;
  25.       }
  26.     }
  27.  
  28.     // 4) clean up `addEvent` function created by JScript
  29.     //    make sure to either prepend assignment with `var`,
  30.     //    or declare `addEvent` at the top of the function
  31.     var addEvent = null;
  32.  
  33.     // 5) finally return function referenced by `fn`
  34.     return fn;
  35.   })();
  36.  

Posted by Dion Almaer at 6:22 am
10 Comments

++++-
4.4 rating from 33 votes

Monday, June 15th, 2009

Bing API does callback checking for JSON-P

Category: JSON, JavaScript, Library

I just looked through the API of Microsoft's new Bing search and found an interesting step in protecting code from throwing errors.

When you provide a JSON output for developers it does make sense to also allow for a callback parameter. That way your code can be used in script nodes without having to use any backend at all. Commonly this is called JSON-P and has been covered here in the long long ago. One of the issues with JSON-P is that when the callback method is not defined it throws an error.

The Bing API is the first instance where I have seen that they worked around that as the output is this:

JAVASCRIPT:
  1. if(typeof callback == 'function') callback(
  2. {
  3.   "SearchResponse":
  4.   {
  5.     "Version":"2.2",
  6.     "Query":
  7.       {
  8.         "SearchTerms":"a hard day's night"
  9.       },
  10.     "Translation":
  11.       {
  12.         "Results":
  13.           [
  14.             {"TranslatedTerm":"einem harten Tag-Nacht "}
  15.           ]
  16.       }
  17.     }
  18. } /* pageview_candidate */);

I have no clue what the /* pageview_candidate */ is about and frown upon omitting the {} of the if statement, but I must say I do like this. One issue is that while end users don't get annoyed with errors, developers don't have a clue what happened either as the error is silent. One proposal would be to use a console.log() when there is an error:

JAVASCRIPT:
  1. if(typeof callback === 'function') {
  2.   callback(... data ... );
  3. } else {
  4.   if (typeof console!=='undefined' &&
  5.    typeof console.log !== 'undefined'){
  6.     console.log('Error: Callback method not defined');
  7.   }
  8. }

More details about other ideas to improve this are here.

Posted by Chris Heilmann at 6:32 am
19 Comments

++---
2.3 rating from 31 votes

Friday, June 12th, 2009

JS.Class 2.1 released

Category: JavaScript, Ruby

James Coglan has updated JS.Class, his implementation of Ruby's object system in JavaScript.

This release includes a Hash implementation, HashSet, an updated Ruby 1.9 Enumerable module with enumerators and Symbol#to_proc functionality, and an improved package loader that supports parallel downloads and runs on SpiderMonkey, Rhino and V8.

Detailed Changes

  • New libraries: ConstantScope, Hash and HashSet, a much faster Set implementation.
  • The package manager has been improved with a new API, parallel downloading of files, and support for server-side environments such as SpiderMonkey, Rhino and V8. It also supports user-defined loader functions for transparent integration with Google and Yahoo!’s packaging systems.
  • The Enumerable module has been updated with plenty of methods from Ruby 1.9, and now supports enumerators, and Symbol#to_proc-like functionality whereby a string, MethodChain or any object that implements toFunction() can be used as an iterator.
  • The core object methods now live in Kernel, and we’ve added new methods: tap(), equals(), hash() and enumFor().
  • The double inclusion problem is now fixed; no current Ruby implementation seems to support this properly.
  • Ancestor and method lookups are now cached so callSuper runs about twice as fast.
  • Classes can be named to generate displayName on methods for
    use with the WebKit debugger.

Posted by Dion Almaer at 6:37 am
9 Comments

+++--
3.1 rating from 20 votes

InfoVis Toolkit 1.1

Category: JavaScript, Library

Nicolas Garcia Belmonte has updated InfoViz with version 1.1.

The JavaScript InfoVis Toolkit provides tools for creating Interactive Data Visualizations for the Web. The code has been updated:

  • The library has been split into modules for code reuse.
  • All visualizations are packaged in the same file. You can create multiple instances of any visualization. Moreover, you can combine and compose visualizations. If you want to know more take a look at the Advanced Demos.
  • This Toolkit is library agnostic. This means that you can combine this toolkit with your favorite DOM/Events/Ajax framework such as Prototype, MooTools, ExtJS, YUI, JQuery, etc.
  • You can extend this library in many ways by adding or overriding class methods. The JavaScript InfoVis Toolkit has a robust (and private) class system, heavily inspired by MooTools’, that allows you to implement new methods in the same class without having to define any new Class extension. By creating mutable classes you can add new custom Node and Edge rendering functions pretty easily.
  • Custom visualizations are created by adding or changing Node/Edge colors, shapes, rendering functions, etc. You can also implement many controller methods that are triggered at different stages of the animation, like onBefore/AfterPlotLine, onBefore/AfterCompute, onBefore/AfterPlotNode, request, etc.
    You can also add new Animation transitions like Elastic or Back with easeIn/Out transitions.
    If you want to know more about these features please take a look at the Demos code.
  • A complete API documentation generated with Natural Docs, with some Narrative Documentation and Syntax Highlighted Code Examples.

Posted by Dion Almaer at 5:34 am
3 Comments

++++-
4.5 rating from 26 votes

Thursday, June 11th, 2009

jQuery Tools

Category: JavaScript, jQuery

Tero Piirainen has created a new package of jQuery Tools.

This library contains six of the most useful JavaScript tools available for today's website. The beauty of this library is that all of these tools can be used together, extended, configured and styled. In the end, you can have hundreds of different widgets and new personal ways of using the library.

This library is open source and dual licensed under MIT and GPL 2+ licenses.

The package contains a slew of demos including:

  • Tabs
  • Tooltips
  • Expose
  • Overlay
  • Scrollable
  • Flashembed

Posted by Dion Almaer at 6:27 am
20 Comments

+++--
3.7 rating from 56 votes

Wednesday, June 10th, 2009

Ample SDK: Browser-in-a-Browser

Category: Framework, JavaScript

Sergey Ilinsky, formerly of Ajax pioneer Backbase, has created a new Ajax toolkit called Ample SDK. The best way to describe Ample SDK is that it's a browser-within-a-browser, but not in the visual sense. Rather, it aims to implement in JavaScript the stack of rendering technologies typically delegated to the browser. For example, Ample currently lets you use Mozilla's XUL to create cross-browser applications.

Here's an example of how you could use Ample SDK to render a XUL interface in the browser:

<body>
    <!-- other HTML code -->
    <script type="text/javascript">ample.open()</script>
<xul:menulist xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    <xul:menupopup id="items-popup">
        <xul:menuitem label="Item 0" value="0"/>
        <xul:menuitem label="Item 1" value="1"/>
        <xul:menuitem label="Item 2" value="2"/>
    </xul:menupopup>
</xul:menulist>
    <script type="text/javascript">ample.close()</script>
    <!-- other HTML code -->
</body>

(Sorry for the old-school, ugly <pre> above--our code formatter chokes on XML namespaces, used in the XUL elements above.)

The Ample SDK compatibility table, shown above, gives you a sense of the scope of the project: to implement technologies like XUL, SVG, HTML 5, XHTML, and so forth, all in JavaScript--and render them across modern and legacy browsers like IE 5.5.

Ample even takes over CSS parsing:

HTML:
  1. <style type="text/ample+css">
  2.     @namespace "http://www.w3.org/1999/xhtml";
  3.     b {
  4.         color: red;
  5.     }
  6. </style>

Check out the examples and documentation at the site. Note that Ample is not (yet) open-source but is free for non-commercial projects.

When Brendan Eich first hinted several years ago that the browsers would get fast, it spurred a lot of folks to wondering whether the future of feature innovation would be primarily in the JavaScript library space, and the browsers would focus on being JavaScript run-times and graphics abstract layers.

Ample SDK raises the question anew. Should we push the rendering layer to JavaScript libraries? What do you think?

And, what do you think of Ample?

Posted by Ben Galbraith at 6:00 am
27 Comments

++++-
4.1 rating from 29 votes

Friday, June 5th, 2009

Moousture: mouse gesture library

Category: JavaScript, Library, MooTools

Zohaib Sibt-e-Hassan has created a Mootools based mouse gesture library Moousture that is based on simplicity:

  • A probe, which probes the pointing device. Currently there
    is a Moousture.MouseProbe (P.S. I am planning to test it on iPhone and
    build any seprate probe for that).
  • A monitor, which tests the stability of probed
    device on given intervals and accordingly notifies Moousture events
    (onStable, onUnstable, onMove).
  • A Moousture recorder class that records the mouse
    movements and invoke the guesture object passed to it.

You can easily work with gestures:

JAVASCRIPT:
  1.  
  2. // Create a guesture matcher, currently there are only two gesture objects Moousture.LevenMatcher, and Moousture.ReducedLevenMatcher.
  3.  
  4. gstr = new Moousture.ReducedLevenMatcher();
  5.  
  6. // Add gesture vectors to matcher object, (see details below in Create your own gestures).
  7.  
  8. gstr.addGesture([3,2,1,0,7,6,5,4], ccwCircle);
  9.  
  10. // Guesture callback function takes one parameter error recieved from matching algorithm. Threshold that value (if required) to make your gestures more sleek.
  11.  
  12. function ccwCircle(error) {
  13.     if(error>= 0.6) return;
  14.     ...
  15. }
  16.  
  17. // Create a probe object that will probe the pointing device. Currently there is a mouse probe that take the $(element) to probe for. So passing a div id will cause the probe to trigger events only when they occur on the passed DOM element.
  18. probe = new Moousture.MouseProbe($(document));
  19.  
  20. // Create a recoder object to record the movement , maxSteps and minSteps in options object will specify the maximum and minimum number of steps to be recorded, and macher is required matcher object to trigger the appropriate gesture.
  21. recorder = new Moousture.Recorder({maxSteps: 20, minSteps: 8, matcher: gstr});
  22.  
  23. // Create a monitor specifying the interval to poll and the amount of error allowed for gesture in pixels.
  24. monitor = new Moousture.Monitor(30, 2);
  25.  
  26. // Finally start the monitor.
  27. monitor.start(probe, recorder);
  28.  
  29. // You can stop the gesture triggering any time by calling .stop() of monitor object.
  30. monitor.stop();
  31.  

Posted by Dion Almaer at 6:56 am
10 Comments

++++-
4 rating from 22 votes

Next Page »