Activate your free membership today | Log-in

Friday, January 9th, 2009

Beautiful Code Documentation

Category: Library, jQuery

Atul Varma (who I have the absolute pleasure to work with now) has created code documentation that actually looks beautiful. Typography matters.

You can check it out via his Ubiquity documentation example that shows you side by side documentation with the actual source code itself. This context is terrific. He does this all dynamically, and uses border padding to align the documentation with the code itself.

Here is what he has to say about how it is done:

The raw source code for the file being documented above just has chunks of comments that are marked-up in WikiCreole; when the parser runs into such a chunk, it renders it alongside the code it annotates using Ivan Fomichev and Chris Purcell’s JavaScript Creole 1.0 Parser.

The idea of using the documentation to annotate the code—or the code to annotate the documentation, depending on how you look at it—was inspired in part by some of the typography presented in Ellen Lupton’s excellent Thinking with Type, which I recommend to anyone interested in the field.

It’s nice not having a separate documentation build step: aside from making the process of writing and editing documentation quicker, it also lowers the barrier for entry to contributors since they don’t need to setup a toolchain. It also means that we get versioned documentation in every commit for free.

Right now there isn’t much else to the system; the only other feature I added is the auto-generation of quasimodal popup menus that link the names of XPCOM interfaces to their entries on XUL Planet and MDC. It’d be nice to have more features like this; other niceties would be an automatically-generated table of contents, JavaScript Doctests, search functionality, cross references to other code, and even the ability to fix code formatting errors in-page. For now, though, I need to focus on actually using this tool to document more code.

As soon as Ben and I saw this our minds started to race. What if you could navigate the code via hyperlinks too? Or have groups comment inline? Many exciting ideas.

It is fun to see the 80 character column limit in place (and seeing where that is ignored). 80 character limits with wide screen displays? I never get that :)

Posted by Dion Almaer at 9:11 am
1 Comment

+++--
3.4 rating from 16 votes

Thursday, January 8th, 2009

jQuery pageSlide: throwing content around

Category: Component, Examples, jQuery

Scott Robbin (Songza co-founder) has created a very cool jQuery plugin for pageSlide, an interaction based off of Aza's prototypes for Firefox Mobile and Ubiquity mouse gestures. The plugin wraps body content into a container and shifts it off of the page whenever a click event is fired, revealing a secondary interaction pane.

This plugin allows any developer to recreate a similar interaction on their own website using a few simple lines of Javascript. By attaching the method to an anchor tag, pageSlide wraps the original body content into a wrapper and creates an additional block for the secondary content load. The slide is animated whenever the click event is invoked.

HTML:
  1.  
  2. <script type="text/javascript">
  3.     $(document).ready(function() {
  4.         $('a.pageslide').pageSlide({
  5.             width: "300px"
  6.         });
  7.     });
  8. </script>
  9.  

For some reason I enjoy thinking of my desktop as a virtual area that I can shift around.... so this can suite me well.

Posted by Dion Almaer at 9:10 am
4 Comments

+++--
3.6 rating from 42 votes

Monday, December 22nd, 2008

jQuery 1.3 beta: Sizzling and feature testing

Category: jQuery

jQuery 1.3 beta 1 has been released with John and the team asking for testing help.

This is a big release as a lot has been changed:

  • Sizzle has been integrated
  • No more browser testing: For example, no more if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) { which is replaced with if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
  • Live event delegration: Reglib's claim to fame was how event delegation was "live" meaning that if you added elements later on, they would also fall into the same delegations. With $("#foo > div").live("click", someFn); you get the same in jQuery
  • $(this).closest("div");: Returns this or closest ancestor that matches selector
  • .offset() rewrite - significantly faster, uses no browser sniffing.
  • .hide()/.show() rewrite - 50% - 200% faster.
  • .append/prepend/before/after rewrite - 10-15x faster.

Posted by Dion Almaer at 1:39 pm
27 Comments

+++--
3.9 rating from 53 votes

jQuery Gestures

Category: JavaScript, Library, jQuery

Adrien Friggeri has taken the music player ui and spent some time to create a really nice gestures library that allows you to add mouse gestures to a web page, supports complex (i.e. sequences of) gestures and provides visual feedback through the use of a canvas element.

Example code looks like this:

JAVASCRIPT:
  1.  
  2. // initialize the engine, inactive by default and set the trace color to red
  3. $.gestures.init({active:false,color:'#ff0000'});
  4.  
  5. // adds a new gesture : Down
  6. $.gestures.register('D', function() {
  7.   alert('down !');
  8.   });
  9.  
  10. // a more complex gesture : Down, Left, Up, Right
  11. $.gestures.register('DLUR', function() {
  12.   alert('this is a rectangle, no ?');
  13.   });
  14.  
  15. // you can log unknown gestures :
  16. $.gestures.error(function(gesture) {
  17.   alert("oops, I don't understand what \""+gesture+"\" means");
  18. });
  19.  
  20. // useful keyboard tricks :
  21. $(window).keydown(function(e) {
  22.   if ($.gestures.active() && e.which==27) {
  23.     // disable capture when user presses ESC
  24.     $.gestures.disable();
  25.   } else if (!$.gestures.active() && e.which==17) {
  26.     // enable capture when CTRL is pressed
  27.     $.gestures.enable();
  28.   }
  29. });
  30. $(window).keyup(function(e) {
  31.   // disable capture when CTRL is not pressed
  32.   if ($.gestures.active() && e.which==17) {
  33.   $.gestures.disable();
  34.   }
  35. });
  36.  

Posted by Dion Almaer at 8:28 am
10 Comments

++++-
4 rating from 31 votes

Wednesday, December 17th, 2008

Music Player UI

Category: Showcase, UI, jQuery

Yensdesign has a nice little example of a music player UI that uses mouse gestures and key handling to give a clean experience.

Songza did a great job here, and I still use it to find songs for the kids.

Posted by Dion Almaer at 6:31 am
3 Comments

+++--
3.3 rating from 21 votes

Monday, December 15th, 2008

The Cloud Player: Web-based iTunes using jQuery

Category: Examples, Sound, jQuery

Eric Wahlforss, the founder of SoundCloud, wrote in to tell us about "The Cloud Player", a iTunes / Songbird clone written entirely in Ajax:

we just released an open-source itunes-clone built in jquery (and app engine, soundmanager 2, soundcloud api), complete with smart playlists, drag'n'drop, keyboard shortcuts, load-as-you-scroll playlists, playlist sharing, waveform display of tracks, etc. we've extended jquery ui a bit for this to happen.

It's using soundcloud.com as the primary music source, and the SoundCloud JSONP API to access the track metadata, available at http://soundcloud.com/api.

I like how it shows the waveform of the entire track at the bottom of the screen. Unfortunately, it's limited to the rather tiny music selection on soundcloud's service, but since it's open-source, the future is interesting indeed.

Eric sent along a playlist with some of his electronic playlists: http://www.thecloudplayer.com/share/3e718.

Nice work!

Posted by Ben Galbraith at 1:11 pm
10 Comments

+++--
3.4 rating from 34 votes

Extending jQuery selectors with JavaScript

Category: jQuery

JAVASCRIPT:
  1.  
  2. // Flag images upon load:
  3. $('img').load(function(){
  4.     $(this).data('loaded',true);
  5. });
  6.  
  7. // Extend expr:
  8. $.extend($.expr[':'],{
  9.     loaded: function(a) {
  10.         return $(a).data('loaded');
  11.     }
  12. });
  13.  
  14. // Example of usage:
  15. alert( 'Images loaded so far: ' + $('img:loaded').size() );
  16.  

This code is one example of how you can extend the selector experience in jQuery with simple JavaScript code.

James Padolsey takes us through this in a lot of detail, showing other examples including a simple "if the element is inline" selector, as well as well as tying into jQuery's "data" functionality.

Posted by Dion Almaer at 6:15 am
2 Comments

+++--
3.8 rating from 42 votes

Friday, December 5th, 2008

JSOS: jQuery based desktop

Category: Showcase, jQuery

There have been plenty of JavaScript desktop in the browsers of the years (ah WebOS!).

James Luterek has posted about the latest jQuery based desktop environment.

I started creating an operating system like user interface in JavaScript. I had intended to use it for the admin sections of my content management system(that runs this website), but through developing it I started to question it's usability and decided to discontinue development.

Features in it's current state:

  • Start Button
  • Task Bar - view open windows and set focus/minimize
  • Windows (Create, move, maximize, minimize, resize, etc.)
  • Show Desktop on right click
  • Properties (Theme Color, Text Color, Background Color, Background Image)
  • Properties saved in cookies for next visit

Still don't know how to create a new window other than a Google one, and I am never quite sure when people will use these (even fully baked). I am sure it will happen, but not until the browser platform has gotten to a point where it actually can. Calling this an "OS" is funny too ;)

Happy Friday!

Posted by Dion Almaer at 2:16 pm
15 Comments

++---
2 rating from 74 votes

Wednesday, December 3rd, 2008

A great example of sharing; Sizzle Engine in Dojo Foundation

Category: CSS, Dojo, JavaScript, Library, Prototype, jQuery

Voting has started in Dojo land to take in John Resig's Sizzle next-gem CSS selector engine.

This is incredibly exciting, as it shows how Ajax libraries are working together more and more. Instead of reinventing the wheel in different ways for each project, is it possible to find some core pieces that can be nicely shared? Of course, if our world was nicer and we could share code by linking in a nice way maybe this would happen more.

As I mentioned in my thanksgiving note, the work that the Ajax library developers do is hugely important and impactful, and having them work together can only be great news.

Take a look at this public email to the Dojo Foundation on the vote:

Overview

The Sizzle project is a JavaScript library for performing selections
across a DOM tree using CSS selectors. The library is designed to be
standalone (have no external dependencies), lightweight, fast, and
extensible. This culminates in a library that is perfectly suited for
integration into other libraries. While it's feasible that a developer
may use Sizzle directly the target audience for it is other library
authors.

The code for Sizzle can be found in the following Git repository:
http://github.com/jeresig/sizzle/tree/master

All of the code for the project has been written by John Resig and is
released under an MIT license. There are some patches pending from
some other contributors (namely Prototype).

Right now the following libraries are adopting or are looking to adopt
Sizzle as their primary CSS selector engine:

It's likely that Sizzle will become the unified engine behind a
majority of the JavaScript libraries on the market (if not in numbers
then certainly in market share).

The project is owned by John Resig who will serve as BDFL/Project lead
if the project is accepted. There is no formal voting process, as of
yet, but it's likely that one will come about, considering the number of
projects using the codebase.

If the project is accepted to the foundation then all contributors to
the project will be required to have a CLA and follow the policies of
the Dojo foundation.

It's very likely that Sizzle will eventually expand into other areas
of JavaScript libraries (such as DOM manipulation and event binding).

That last line excites me too! It is interesting to see this happen in the Dojo Foundation. Remember, Dojo was founded out of toolkits coming together to aggregate forces. Kudos to everyone involved, and good luck!

Posted by Dion Almaer at 12:58 am
12 Comments

++++-
4.5 rating from 52 votes

Friday, November 28th, 2008

s3slider: fading gracefully

Category: jQuery

s3slider is a simple jQuery plugin that smoothly lets you fade through a set of images.

You include the script and then:

HTML:
  1.  
  2. // setup the images
  3. <div id="s3slider">
  4.    <ul id="s3sliderContent">
  5.       <li class="s3sliderImage">
  6.           <img src="#" />
  7.           <span>Your text comes here</span>
  8.       </li>
  9.       <li class="s3sliderImage">
  10.           <img src="#" />
  11.           <span>Your text comes here</span>
  12.       </li>
  13.       <div class="clear s3sliderImage"></div>
  14.    </ul>
  15. </div>
  16.  

Setup the CSS, and finally the JS

JAVASCRIPT:
  1.  
  2. $(document).ready(function() {
  3.    $('#s3slider').s3Slider({
  4.       timeOut: 4000
  5.    });
  6. });
  7.  

Posted by Dion Almaer at 4:15 am
4 Comments

+++--
3.3 rating from 19 votes

Thursday, November 20th, 2008

CDNs Gaining Broader Use with JavaScript Libraries

Category: Ajax, Cloud, Ext, Yahoo!, jQuery

YUI and Google

Most everyone knows that Google has really stepped up to the plate by helping many JavaScript library projects host their builds on the Google AJAX Libraries API. Apart from providing a central distribution point for these libraries, the bandwidth cost savings alone go a long way in helping frameworks service their users in a sustainable manner.

Google continues it's commitment to helping out by adding the Yahoo UI to the growing list of supported JavaScript libraries.

Thanks to Vadim Spivak at Google and Dion Almaer (now at Mozilla) for helping to make this additional option available to the YUI developer community. We love that Google is supporting web developers in this way — grabbing YUI files from Google’s global infrastructure is a fantastic option to have.

This is great news for YUI developers who now have a choice of linking directly to YUI via yui.yahooapis.com and ajax.googleapis.com. YUI team lead, Eric Miraglia, has a great write-up on the YUI blog about this and goes into detail on how the framework's users can take advantage of this new hosting option.

jQuery and Amazon CloudFront

With nearly 2.5 million requests per day to the jQuery website, the jQuery project team is constantly on the look out for ways to decrease hosting costs while still managing the growing number of requests for the site's resources. Originally leveraging Amazon S3 for many of their static pages, the project has now turned to Amazon's new CloudFront CDN. The change has allowed for jQuery pages to be globally hosted as opposed to being centrally located in Amazon's Seattle-based S3 hosting center.

In tests, John Resig, team lead for the jQuery project, noticed substantial performance gains based on the switch:

I ran a similar test here in Boston and even managed to see a large improvement. I was seeing latency of anywhere from 50-200ms on Amazon S3, but only a latency of 17-19ms with CloudFront.

What does all of this mean? It means that the jQuery site is going to load even faster than it does now. We already receive some excellent hosting from Media Temple but being able to off-load these static files to the fast-loading servers will only make for a better browsing experience.

In less than 24 hours the project had received almost 2.5 million requests for over 50GB of data. The only drawback is an increase in bandwidth costs but still substantially less than that of a traditional hosting plan. The jQuery project makes use of the Google AJAX API as well and recommends it as choice for linking to the jQuery and jQuery UI libraries.

Ext JS and CacheFly

The team at Ext JS has taken an interesting approach to CDN usage by extending their library build manager to allow users to host their own custom build on the CacheFly CDN.

The hosting is free and what makes it unique to something like the Google CDN is that it allows Ext developers a central access point for their own custom builds.

We are pleased to announce that Ext has partnered with CacheFly, a global content network, to provide free CDN hosting for the Ext JS framework. Cachefly’s globally distributed network and aggressive caching accelerate the delivery of web content like JavaScript and CSS, making for an even faster Ext experience.

Posted by Rey Bango at 11:16 am
17 Comments

++++-
4 rating from 26 votes

Liquid Canvas: Draw inside canvas with a DSL

Category: Canvas, jQuery

JAVASCRIPT:
  1.  
  2. $(window).load(function() {
  3.   $("#example").liquidCanvas(
  4.     "[shadow border gradient] => roundedRect{radius:50}");
  5. });
  6.  

This is an example of Liquid Canvas, a new library from Steffen Rusitschka who created ShadedBorder and RUZEE.Borders.

Liquid Canvas is a JavaScript library which allows you to draw inside an HTML canvas element with an easy yet powerful description language.

  • Automatic generation of HTML canvas elements which scale with their HTML container, e.g. a floating DIV
  • Abstraction of canvas - each HTML element gets a "paint" method
  • Works with plugins for rendering
  • Loads of plugins already exist
  • Own plugins are possible
  • Simplified render language for plugin-based rendering
  • Rendering language uses a CSS-like syntax for plugin styles
  • Based on HTML Canvas, jQuery, ExplorerCanvas
  • Tested on Firefox, Internet Explorer, Safari, Chrome

Posted by Dion Almaer at 8:11 am
4 Comments

+++-