planet.jquery.com

RSS Feed
$('.blog[@tag=jquery]').read();

jQuery Conference 2009: Dates and Venue

Posted July 02, 2009 by John Resig

Good news everybody! The dates and venue for this year’s jQuery Conference have been determined.

The conference will be held September 12th and 13th at Microsoft Cambridge in Boston, MA.

This will be a 2 day conference with multiple tracks on each day. We’re in the process of planning out the schedule, talking with speakers, and setting up the conference web site.

Watch the jQuery blog or jQuery Twitter feed for notification when registration opens.

While this venue is larger than those that we’ve had in the past (Harvard Law School in ‘07 and the MIT Stata Center in ‘08) we do expect to sell out all the available seats, as has happened every year so far. That being said, the venue is quite incredible, easily one of the best spaces available for a conference:

A brief synopsis of some of the content that you’ll be able to expect:

The annual conference of jQuery users and developers. There will be talks on jQuery, jQuery UI, plugins, complex application development, and more - all from the top jQuery developers. Case studies from some of the leading users of jQuery will be included along with a 3 hour tutorial for those just getting started.

You can see the schedules from past jQuery conferences here: 2008 , 2007 . There will be a nominal fee (likely around $100-$150) to help us cover to cost of food for both days and shirts.

Looking forward to seeing everyone in Boston this fall!

Note: If you are interested in sponsoring the conference, please contact John Resig .

Update: There have been a lot of questions asking if there will be a conference on the west coast (San Francisco) or in Europe. While we don’t have any immediate plans to hold conferences in those locations, this year, we would like to hold them in the future. In the meantime I recommend checking out Full Frontal (UK, November) and Fronteers (Amsterdam, November) - both of which should shape up to be excellent JavaScript conferences.

Update: Thanks to Jeff for adding the event to Upcoming .

Which Unit Testing Framework?

Posted July 02, 2009 by John Resig

I'm in the process of working on, and improving, test suite support in TestSwarm (an upcoming project of mine). However, there isn't a lot of information on which unit testing frameworks developers actually use to test their code (whereas there is more information on which JavaScript libraries are used).

It will be of great help to me if you could quickly fill out the question below. I will release the results of the survey as soon as possible. Thanks!

» Which JavaScript Unit Testing Frameworks do you use?

Loading...

More information on the frameworks listed above:

JSConf Talk: Games, Performance, TestSwarm

Posted June 30, 2009 by John Resig

The video from my talk at JSConf has been posted . Thanks to Chris for organizing the conference and the excellent quality of the video.

The description from the JSConf site summarizes the talk well:

John Resig presents his mystery topic, which is actually three topics that strike his interest. First up is measuring performance and a quick introduction to benchmarking (and its positives and negatives). This is followed by JavaScript Games which he unveils some super cool hidden functionality (cheat codes++) on the jQuery web site. This is followed up by the introduction of John's distributed continuous test framework platform, Test Swarm . It is jam packed with Nirvana and goodness so be sure to watch both parts.

Part 1: Measuring JavaScript Performance, JavaScript Games



Part 2: Distributed JavaScript Testing, Q&A



Additionally, the slides from the talk are up on Slideshare .



Understanding the Context in jQuery

Posted June 24, 2009 by Brandon Aaron

When selecting elements jQuery has an optional second argument called context. This context provides a means to limit the search within a specific node. This is great when you have a very large DOM tree and need to find, for example, all the <a> tags within a specific part of the DOM tree. I’ve seen various articles, usually performance related, stating that you should be using a context for your selectors. While it is true that using a context for your selectors can potentially boost performance, most of these articles misuse the context.

Finding the Context

As of jQuery 1.3 the context is exposed as a property on the jQuery collection. Here is how you can check to see what the context is.

$('a').context; // => document


Running the above code shows that the context is the document element. In fact, the default context for all jQuery collections is the document in which jQuery was loaded. In other words, selectors are run against the whole document by default.

Changing the Context

The context needs to be a node to work properly. This is the part that is often overlooked. I’ve overlooked it in the past as well. Lots of examples out there tell you to just pass a second selector to jQuery to act as the reference node for the search. While this seems to work, it is still running the search on the whole document.

Here is an example of passing a second selector as the context. By looking at the context property you can see that the context is still the document though.

$('a', '#myContainer').context; // => document


When jQuery encounters another selector for the context it actually converts it to say the following instead.

$('#myContainer').find('a');


This conversion also happens the same way if you pass a jQuery collection as the context.

Now lets actually look at how we can change the context for the jQuery collection.

// get the node for the context
var context = $('#myContainer')[0];

// pass the context as the second argument
$('a', context).context; // => <div id="myContainer">


From this example we can see that passing a node as the second argument actually changes the context for the jQuery collection.

jQuery 1.3.3 and .live()

In jQuery 1.3.x, the .live() method binds its event handlers to the document. In the upcoming jQuery 1.3.3 release the .live() method will bind its events to the context of the jQuery collection. This means your .live() events can be more focused and potentially faster.

Unimpressed by NodeIterator

Posted June 19, 2009 by John Resig

I just posted a run down of some of the new DOM Traversal APIs in Firefox 3.5 . The first half of the post is mostly a recap of my old Element Traversal API post.

The second half of the post is all about the new NodeIterator API that was just implemented. For those that are familiar with some of the DOM TreeWalker APIs this will look quite familiar.

It's my opinion, though, that this API is, at best, bloated, and at worst incredibly misguided and impractical for day-to-day use.

Observe the method signature of createNodeIterator :

var nodeIterator = document.createNodeIterator (

  root, // root node for the traversal

  whatToShow, // a set of constants to filter against

  filter, // an object with a function for advanced filtering

  entityReferenceExpansion // if entity reference children so be expanded

) ;

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

To start, you must create a NodeIterator using the createNodeIterator method. This is fine except this method only exists on the Document node - which is especially strange since the first argument is the node which should be used as the root of the traversal. The first argument shouldn't exist and you should be able to call the method on any DOM element, document, or fragment.

Second, in order to specify which types of nodes you wish to see you need to provide a number (which is the result of the addition of various constants ) that the results will be filtered against. This is pretty insane so let me break this down. The NodeFilter object contains a number of properties representing the different types of nodes that exist. Each property has a number associated with it (which makes sense, this way the method can uniquely identify which type of node to look for). 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:

NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT

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).

Next, the filter argument accepts an object that has a method (called acceptNode) which is capable of further filtering the node results before being returned from the iterator. This means that the function will be called on every applicable node (as specified by the previous whatToShow argument).

Two points to consider:

  • The filter argument must be an object with a property named 'acceptNode' that has a function as a value. It can't just be a function for filtering, it must be enclosed in a wrapper object. Update: Actually, this isn't true - at least with Mozilla's implementation you can pass in just a function. Thanks for the tip, Neil!
  • The argument is required (even though you can pass in null, making it equivalent to accepting all nodes).

The last argument, entityReferenceExpansion, comes in to play when dealing with XML entities that also contain sub-nodes (such as elements). For example, with XML entities, it's perfectly valid to have a declaration like <!ENTITY aname "<elem>test</elem>"> and then later in your document have &aname (which is expanded to represent the element). While this may be useful for XML documents it is way out of the scope of most web content (thus the argument will likely always be false).

So, in summary, createNodeIterator has four arguments:

  • The first of which can be removed (by making the method available on elements, fragments, and documents).
  • The second of which is obtuse and should be optional (especially in the case where all nodes are to be matched.
  • The third which requires a superfluous object wrapping and should be optional.
  • The fourth of which should be optional.

None of this actually takes into account the actual iteration process. If you look at the specification you can see that all the examples are in Java - and when seeing this a lot of the API decisions start to make more sense (not that it really applies to the world of web-based development, though). In JavaScript one doesn't really use iterators, more typically an array is used instead. (In fact a number of helpers have been added in ECMAScript 5 which make the iteration and filtering process that much simpler.)

I'd like to propose the following, new, API that would exist in place of the NodeIterator API (dramatically simplifying most common interactions, especially on the web).

// Get all nodes in the document

document.getNodes ( ) ;

// Get all comment nodes in the document

document.getNodes ( Node.COMMENT_NODE ) ;

// Get all element, comment, and text nodes in the document

document.getNodes ( Node.ELEMENT_NODE , Node.COMMENT_NODE , Node.TEXT_NODE ) ;

I'd also like to propose the following helper methods:

// Get all comment nodes in the document

document.getCommentNodes ( ) ;

// Get all text nodes in a document

document.getTextNodes ( ) ;

Beyond finding elements, finding comments and text nodes are the two most popular queries types that I see requested.

Consider the code that would be required to recreate the above using NodeIterator:

// Get all nodes in the document

document.createNodeIterator ( document, NodeFilter.SHOW_ALL , null , false ) ;

// Get all comment nodes in the document

document.createNodeIterator ( document, NodeFilter.SHOW_COMMENT , null , false ) ;

// Get all element, comment, and text nodes in the document

document.createNodeIterator ( document,

    NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT ,

    null , false

) ;

This proposed API would return an array of DOM nodes as a result (instead of an NodeIterator object). You can compare the difference in results between the two APIs:

NodeIterator API

var nodeIterator = document.createNodeIterator (

    document,

    NodeFilter.SHOW_COMMENT ,

    null ,

    false

) ;

var node;

while ( ( node = nodeIterator.nextNode ( ) ) ) {

    node.parentNode .removeChild ( node ) ;

}

Proposed API

document.getCommentNodes ( ) .forEach ( function ( node) {

    node.parentNode .removeChild ( node ) ;

} ) ;

Another example, if we were to find all elements with a node name of 'A'.

NodeIterator API

var nodeIterator = document.createNodeIterator (

    document,

    NodeFilter.SHOW_ELEMENT ,

    {

        acceptNode: function ( node) {

          return node.nodeName .toUpperCase ( ) === "A" ;

        }

    } ,

    false

) ;

var node;

while ( ( node = nodeIterator.nextNode ( ) ) ) {

    node.className = "found" ;

}

Proposed API

document.getNodes ( Node.ELEMENT_NODE ) .forEach ( function ( node) {

    if ( node.nodeName .toUpperCase ( ) === "A" )

        node.className = "found" ;

} ) ;

Almost always, when finding some of the crazy intricacies of the DOM or CSS, you'll find a legacy of XML documents and Java applications - neither of which have a strong application to the web as we know it or to the web as it's progressing . It's time to divorce ourselves from these decrepit APIs and build ones that are better-suited to web developers.

Update: An even better alternative (rather than using constants representing node types) would be something like the following:

document.getNodes ( Element, Comment, Text ) ;

Just refer back to the back objects representing each of the types that you want.

Release: Message plugin 1.0.0

Posted June 19, 2009 by Jörn

I’m happy to announce the first release of the Message jQuery plugin. The plugin allows you to easily display feedback messages as an unobstrusive overlay. The message fades away automatically after some time, avoiding the need to click an “ok” button or something similar. The user can speed up hiding of the message by moving the mouse or clicking anywhere.

More details can be found on the new plugin page .

Enjoy!

Automating with Special Events

Posted June 17, 2009 by Brandon Aaron

David Walsh had a great idea to coerce an element that is given a click event to have a pointer for its cursor. The pointer is a universal symbol for users to know that something is clickable. Using this technique it would be “automatic” that any element given a click event would have a pointer. David set out to use the Special Event hooks within jQuery to make this work. Unfortunately for David those hooks are not widely documented, so his first attempt was unsuccessful . So, lets see how we can use the Special Event hooks to make this work as desired.

If you haven’t done so, I recommend reading the Special Events blog post which explains what special events are and how to use them. In the upcoming jQuery 1.3.3 there will be two more event hooks .

The Special Event

The code, once you understand the Special Event hooks, is fairly straight forward. When a click event is bound to an element, we want to make sure it has a pointer for its cursor. Here is what the code looks like to make this work.

jQuery.event.special.click = {
    setup: function() {
        jQuery( this ).css( 'cursor', 'pointer' );
        return false;
    },

    teardown: fuction() {
        jQuery( this ).css( 'cursor', '' );
        return false;
    }
};


So lets break this small piece of code down. There are two hooks, setup and teardown , that are called once per an element. In the setup hook we add the CSS rule to make the cursor a pointer and in the teardown hook we revert the change since it is no longer clickable. The teardown hook is only called after the last click event is unbound.

The only difference here from David’s example is the return false statements in both hooks. The return value in Special Event hooks is particularly important (and easy to overlook). Special Events assume that you will most likely handle the actual binding of the event yourself. In other words, when you don’t return false jQuery skips the actual native binding (addEventListner or attachEvent ) of the event to the element. In this particular case we want jQuery to go ahead and run its native binding code so the event is actually registered with the browser. To do this we need to return false from our hooks.

Usage

Using the same example from David’s post, the actual usage stays the same. Just bind a click event handler as you normally would using either .bind() or .click() .

jQuery( document ).ready(function( $ ) {
    $( '#click-me' ).click(function() {
        var red   = Math.floor( Math.random() * 256 ),
            green = Math.floor( Math.random() * 256 ),
            blue  = Math.floor( Math.random() * 256 ),
            color = 'rgb(' + red + ',' + green + ',' + blue + ')';
        $( this ).css( 'background', color );
    });
});


You can see this in action here .

Enhancement

There is one enhancement that I’d like to recommend. Instead of adding the styles via JavaScript, lets just add a class name instead. Maybe the name could be “clickable”. Then we can add a rule in our CSS that says anything with the class of “clickable” should have a pointer. This would make it easier to style specific instances of a clickable element. For example, we could add a three pixel blue border to a clickable image. :) So, the final special event with this enhancement would look like this.

jQuery.event.special.click = {
    setup: function() {
        jQuery( this ).addClass( 'clickable' );
        return false;
    },

    teardown: fuction() {
        jQuery( this ).removeClass( 'clickable' );
        return false;
    }
};


And in our CSS we would need to add a global rule that adds the pointer to .clickable  elements.

.clickable { cursor: pointer; }


Now we can specialize our .clickable class to handle certain elements differently.

img.clickable { border: 3px solid blue; cursor: pointer; }


Last thought…

I had one last thought about this technique. This should not be a replacement for using semantic markup or using progressive enhancement. Most of the time if something should be clickable it should probably be clickable and actually do something when JavaScript is not available.

Quick Tip: Outline Elements on Hover

Posted June 16, 2009 by Karl Swedberg

Someone on the jQuery Google Group yesterday asked about how to display a border around elements on hover. Here is a quick script I wrote to achieve that effect:

[inline][/inline]
JavaScript:
  1. $( document) .ready ( function ( ) {
  2.   $( '.entrytext' )
  3.     .mouseover ( function ( event) {
  4.       $( event.target ) .addClass ( 'outline-element' ) ;
  5.     } )
  6.     .mouseout ( function ( event) {
  7.       $( event.target ) .removeClass ( 'outline-element' ) ;
  8.     } )
  9.     .click ( function ( event) {
  10.       $( event.target ) .toggleClass ( 'outline-element-clicked' ) ;
  11.     } ) ;
  12. } ) ;

The script will respond to mouseover, mouseout, and click within <div class="entrytext"> . I use mouseover/mouseout rather than mouseenter/mouseleave because the script relies on event bubbling. The $(event.target) selector ensures that the class manipulation occurs on the innermost element. You can try it out on this page by hovering over elements within the main content area.

The two classes that are being toggled have the following style rules:

CSS:
  1. .outlineElement {
  2.   outline : 1px solid #c00;
  3. }
  4.  
  5. .outlineElementClicked {
  6.   outline : 1px solid #0c0;
  7. }

The outline property is really handy for this sort of thing because it doesn't affect the element's dimensions or layout. Unfortunately, it isn't supported in Internet Explorer 6 or 7, so if you want to support them, you might want to use border or background-color instead in a separate IE-only stylesheet. Or, maybe IE has some proprietary property? Anyone know?

I'm not sure what the person wanted to do with this script. By itself, it doesn't seem particularly useful to me. Still, I think there are a few concepts in there that can be applied elsewhere, and maybe the script can be expanded to do something interesting.

Update

After thinking about this for a night, I realized that the script could be written more succinctly by combining the mouseover and mouseout event types in a single .bind() method and toggling the class therein …

JavaScript:
  1. $( document) .ready ( function ( ) {
  2.   $( '.entrytext' )
  3.   .bind ( 'mouseover mouseout' , function ( event) {
  4.     var $tgt = $( event.target ) ;
  5.     if ( ! $tgt.closest ( '.syntax_hilite' ) .length ) {
  6.       $tgt.toggleClass ( 'outline-element' ) ;
  7.     }
  8.   } )
  9.   .click ( function ( event) {
  10.     $( event.target ) .toggleClass ( 'outline-element-clicked' ) ;
  11.   } ) ;
  12. } ) ;

Notice that the updated script also takes advantage of the .closest() method, which was introduced in jQuery 1.3. I don't want to apply the outline to any of the syntax-highlighted code in the entry, so I make sure that neither the event target nor any of its ancestors has a class of "syntax_hilite." Remember, to test for the presence (or absence) of a selector, we need to include more than just the selector itself. Here I test for "not a length ." What I'm actually looking for is a length of 0, but since 0 is "falsey" the ! operator works just fine here.

One More Tip

Come to think of it, I can make the script shorter still by including the click event type along with mouseover and mouseout . Then, inside the the handler, the class that is toggled is determined by event.type .

JavaScript:
  1. $( document) .ready ( function ( ) {
  2.   $( '.entrytext' ) .bind ( 'mouseover mouseout click' , function ( event) {
  3.     var $tgt = $( event.target ) ;
  4.     if ( ! $tgt.closest ( '.syntax_hilite' ) .length ) {
  5.       $tgt.toggleClass ( event.type == 'click' ? 'outline-element-clicked' : 'outline-element' ) ;      
  6.     }
  7.   } ) ;
  8. } ) ;

Sometimes when code becomes shorter, it can also get less readable and more difficult to modify later on. I'm not suggesting that the final code snippet is necessarily the best way to achieve the outcome. A lot depends on what else you're planning to do and how a certain piece fits into the project as a whole.

This Week in jQuery, vol. 8

Posted June 15, 2009 by Cody Lindley

Another week, another collection of links to some of the most interesting and exciting new jQuery happenings around the web.

If you have ever used a regular expression tool to highlight character matches in real time, then you’ll jump for joy when I tell you about the Interactive jQuery selector tester written by Samuli Kärkkäinen. You enter a selector expression, and in real time you get to see the elements in the DOM structure that have been selected. I can see this being very handy for complex expressions or for optimizing expressions down to the simplest solution.

Also, in case you didn’t notice, the second maintenance release for jQuery UI 1.7 is out .

Articles this Week

Tutorials this Week

Plugins this Week

  • A new jQuery mp3 player hit the streets, jPlayer ! It’s also Themeroller ready!
  • Need to re-skin the browser default UI forms? Check out the uniform jQuery plugin. It might just help you realize the dream of making web forms look the same across all browsers.
  • If your cup of tea is dealing with mouse gestures, then you’ll be glad to know that there is now a SUPER Gestures plugin . Its SUPER!
  • SWFUpload + jQuery = SWFUpload jQuery Plugin .

Plugin Spotlight/Updates

Pulled from my own personal archives. I bring you $.event.special.hover which is an alternative to Brain Cherne’s popular hoverIntent plugin . You may or may not have missed this plugin, but regardless, it’s certainly worth a first look, or second.

What’s a week of jQuery news without a lightbox thickbox super window modal dialog thingy kabob doodad solution?

SuperBox and jOverlay , welcome to the crowd! Nice to have you.

jQuery Gossip/Rumor Mill

It’s possible that you might be seeing several team members, if not John Resig himself, talking at the up and coming devdays . And the really juicy part is they might be wearing a DEVO red energy dome .

jQuery Quote of the Week

“You can save a tremendous amount of time and effort by using the browser-independent framework that JQuery has spent untold man-hours testing, debugging, and proving in the field. While there’s nothing wrong with writing JavaScript, why not speed your development time by writing to the library instead? As I’ve always said, don’t reinvent the wheel, unless you plan on learning more about wheels. ” - Jeff Atwood

Release: Validation Plugin 1.5.3

Posted June 15, 2009 by Jörn

An update for the jQuery validation plugin is available. Among various bugfixes there are two new localizations (Taiwan and Kazakhstan), an enhancement to $.validator.addMethod that allows you to specify (localized) messages first, the actual method later; the submitHandler-option now keeps a submit-button “alive”, that is, won’t get lost when using the option.

Probably most notable: The remote method now allows you to specify custom messages! Return JSON “true” for a valid field, false/null/undefined for an invalid field and the default message, or any other value to use as the message.

The full changelog:

  • Fixed a bug related to the wrapper-option, where all ancestor-elements that matched the wrapper-option where selected (http://plugins.jquery.com/node/7624 )
  • Updated multipart demo to use latest jQuery UI accordion
  • Added dateNL and time methods to additionalMethods.js
  • Added Traditional Chinese (Taiwan, tw) and Kazakhstan (KK) localization
  • Moved jQuery.format (fomerly String.format) to jQuery.validator.format, jQuery.format is deprecated and will be removed in 1.6 (see http://code.google.com/p/jquery-utils/issues/detail?id=15 for details)
  • Cleaned up messages_pl.js and messages_ptbr.js (still defined messages for max/min/rangeValue, which were removed in 1.4)
  • Fixed flawed boolean logic in valid-plugin-method for multiple elements; now all elements need to be valid for a boolean-true result (http://plugins.jquery.com/node/8481 )
  • Enhancement $.validator.addMethod: An undefined third message-argument won’t overwrite an existing message (http://plugins.jquery.com/node/8443 )
  • Enhancement to submitHandler option: When used, click events on submit buttons are captured and the submitting button is inserted into the form before calling submitHandler, and removed afterwards; keeps submit buttons intact (http://plugins.jquery.com/node/7183 )
  • Added option validClass, default “valid”, which adds that class to all valid elements, after validation (http://dev.jquery.com/ticket/2205 )
  • Added creditcardtypes method to additionalMethods.js, including tests (via http://dev.jquery.com/ticket/3635 )
  • Improved remote method to allow serverside message as a string, or true for valid, or false for invalid using the clientside defined message (http://dev.jquery.com/ticket/3807 )
  • Improved accept method to also accept a Drupal-style comma-seperated list of values (http://plugins.jquery.com/node/8580 )

As usual, support is available via:

  • Please post questions to the jQuery discussion list , putting “(validate)” into the subject of your post, making it easier to spot it and respond quickly. Keep your question short and succinct and provide code when possible; a testpage makes it much more likely that you get an useful answer in no time.
  • Please post bug reports and other contributions (enhancements, features, eg. new validation methods) to the plugins.jQuery.com bug tracker (requires registration ).

Enjoy!

Update:

Just uploaded a hotfix 1.5.4 release, with a fix for the remote method .

Update II:

Uploaded another release, now at 1.5.5, hopefully the final fix for the remote method: http://plugins.jquery.com/node/8659

jQuery.SerialScroll

Posted June 14, 2009 by Ariel Flesler

Introduction

This plugin allows you to easily animate any series of elements, by sequentially scrolling them. It uses jQuery.ScrollTo to achieve the scrolling animation. It is a very unrestricted plugin, that lets you customize pretty much everything from outside. You can use horizontal or vertical scroll, also combined.



What's it for ?

jQuery.SerialScroll doesn't have one definite purpose. It's generic and adaptable. You can certainly use it as a screen slider . That is, to sequentially navigate a group of screens.

This plugin can also animate a text scroller in no time.

It can definitely handle slideshows , the high customizability of the scrolling effect lets you create beautiful animations.

You can even build an automatic news ticker !

Three of these uses are exemplified in the demo.

Remember, it's not restricted to these situations. It will take care of any collection of html elements that you want to scroll consecutively.



Settings and customization

jQuery.SerialScroll gives you access to a lot of options.

These are:
  • target
    The element to scroll, it's relative to the matched element.

    If you don't specify this option, the scrolled element is the one you called serialScroll on.
  • event
    on which event to react (click by default).
  • start
    first element of the series (zero-based index, 0 by default).
  • step
    how many elements to scroll each time. Use a negative number to go on the other way.
  • lock
    if true(default), the plugin will ignore events if already animating. Then animations can't be queued.
  • cycle
    if true, the first element will be shown after going over the last, and the other way around.
  • stop
    if true, the plugin will stop any previous animations of the element, to avoid queuing.
  • force
    if true, an initial scroll will be forced on start.
  • jump
    if true, the specified event can be triggered on the items, and the container will scroll to them.
  • items
    selector to the items(relative to the scrolled element).
  • prev
    (optional)selector to the 'previous' button.
  • next
    (optional)selector to the 'next' button.
  • lazy
    if true, the items are collected each time, allowing dynamic content(AJAX, AHAH, jQuery manipulation, etc).
  • interval
    If you specify a number, the plugin will add auto scrolling with that interval.
  • constant
    Should the speed remain constant, no matter how many items we scroll at once ? (true by default).
  • navigation
    Optionally, a selector to a group of elements, that allow scrolling to specific elements by index. Can be less than the amount of items.
  • excludenew
    If you want the plugin, to stop scrolling before the actual last element, set this to a number, and that amount of items is ignored counting from the end.

    This is useful if you show many items simultaneously, in that case, you probably want to set this option to the amount of visible items - 1.
  • onBefore
    A function to be called before each scrolling. It receives the following arguments: event object, targeted element, element to be scrolled, collection of items and position of the targeted element in the collection.

    The scope(this) will point to the element that got the event. If the function returns false, the event is ignored.
Also, you can use jQuery.ScrollTo's settings!

Check its demo to see all of them.



The option 'target'
This option is a new addition, included since 1.2.0.

Before, you needed to call the plugin once for each scrolled element.

When this option is specified, the matched elements are no longer the scrolled elements, but a container.

In this case, the selectors of prev, next, navigation and target will be relative to this container, allowing you to call SerialScroll on many elements at once.



External manipulation, event triggering

jQuery.SerialScroll automatically binds 3 events to the containers.

These are:
  • prev.serialScroll
    Scrolls to the previous element.
  • next.serialScroll
    Scrolls to the next element.
  • goto.serialScroll
    Scrolls to the specified index, starts with 0.
  • start.serialScroll
    (Re)starts autoscrolling.
  • stop.serialScroll
    Stops the autoscrolling.
  • notify.serialScroll
    Updates the active item.
This looks confusing, but it's not. You use it like this:
$
(container).trigger( 'prev'
 );
$
(container).trigger( 'next'
 );
$
(container).trigger( 'goto'
, [
 3
 ]
 );
$
(container).trigger( 'start'
 );
$
(container).trigger( 'stop'
 );
$
(container).trigger( 'notify'
, [
 4
 ]
 );
'notify' also accepts a DOM element(item), or any of its descendants.

$(container) is the element that gets scrolled each time. If you specified a 'target', then that element, else, the element you called the plugin on.

Note that to use 'start' and 'stop' you need to use the option 'interval' first.

If your container element already has any of these event names bound(odd!), then just add the namespace when you trigger.

You probably won't need to deal with these events, but if so, this is how.



What makes jQuery.SerialScroll so special ?

This plugin has many positive features, of course, it won't fit everyone's needs. That's impossible.
  • Small Footprint
    This plugin is tiny, as said before, it requires jQuery.ScrollTo. Both plugins together, take less than 3.5kb minified .

    If by chance, you decide to include jQuery.LocalScroll , the 3 of them require less than 5kb . Including this plugin is not a bad idea, it can be used, instead of the option 'navigation' to build a widget with sequential and random scrolling.
  • Highly customizable
    This plugin has many settings to customize, in addition, it can use jQuery.ScrollTo's settings. That makes 27 different options!

    If you take a while to analyze them all, you can make your work really unique.
  • Accessible, degrades gracefully
    Probably many will automatically skip this part, shame on you!

    If you make sure non-javascript users will see the scrollbars, then they can perfectly navigate your content. You can show the scrollbars only for these few users, easily, using css/js.

    This is one of the main differences with many similar scripts, they generate the content and the styling using javascript.
  • Adaptable
    jQuery.SerialScroll won't alter the html or styles at all .

    You are in control of the styles and content of your collections. You don't need the plugin to decide what html to use, or how many items to show simultaneously, and you can safely change that yourself, the plugin will always work.

    The items don't need to have fixed size, nor to be aligned . SerialScroll will scroll from one to the other, no matter what.

    If you want a plugin with premade styles or automatic generation of html, then you should consider any of jQuery carousels.
  • Generic and reusable
    Finally, as mentioned before, this plugin can be used for many different situations and doesn't have one specific application.

Links

Downloads

I really advice using the minified versions. The code is optimized to those releases. Source versions should only serve to learn.



3/07/08
Added 1.1.2, start and stop events. Allows negative step.

3/10/08
Added 1.2.0, major release, updated everything.

3/20/08
Added 1.2.1, added 'exclude' and enhancements.

4/28/08
Added a link to "Doctorate on jQuery.SerialScroll".

jQuery.SerialScroll 1.1 released

Posted June 14, 2009 by Ariel Flesler
I added a major release of jQuery.SerialScroll. It doesn't have that many changes, but I really feel it made one step ahead.

Optimizations

  • The animation is skipped if a bad position was received or it's the same as the actual. Saving some overhead.

Changes

  • Changed the licensing from GPL to GPL+MIT.

Features

  • The plugin binds 3 events to the container to allow external manipulation. They are clearly explained in the main post, please check it.
  • Added 2 more arguments to the onBefore callback: actual item collection, index of the actual item in the collection.
  • Added option 'interval', can be a number specifying the amount of milliseconds for autoscrolling.
I upgraded the main post and it has extensive and detailed documentation. Also added some more text and options to the demo.

Links

Downloads

I really advice using the minified versions. The code is optimized for those releases. Source versions should only serve to learn.

jQuery.SerialScroll 1.2.2 released

Posted June 14, 2009 by Ariel Flesler

Enhancements

  • Removed the check that avoids re-scrolling to the same index, this might be desirable sometimes.
  • The settings object is exposed in the onBefore as the this.

Links

Downloads

jQuery Infinite Carousel

Posted June 11, 2009 by Remy
With jQuery for Designer’s redesign I decided to add a scrolling carousel that worked in the same way the carousel worked on the Apple Mac ads page. This tutorial will walk through the fundamentals of the effect and how to recreate it. Watch Watch jQuery Infinite Carousel screencast (Alternative flash version) QuickTime version is approximately 70Mb, flash version [...]

jQuery for Designers: In Live Action

Posted June 11, 2009 by Remy
This September dConstruct will return the UK again, running 2 days of workshops and one full day of talks. One of those workshops will be a full day jQuery for Designers workshop run by your very own Remy Sharp. I’ve attended dConstruct a couple of times now and it’s a superb event that always leaves me [...]

This Week in jQuery, vol. 7

Posted June 08, 2009 by Karl Swedberg

After a long hiatus, I’m happy to present another roundup of jQuery happenings. Keep in mind that this is just a small, fairly random sampling of what has been going on. For more frequent news and announcements, be sure to follow @jquery on Twitter.

jQuery Updates

Brandon Aaron has been writing a series called “jQuery Edge” on his blog, detailing some of the cool enhancements in store for the next version of jQuery. His most recent, New Special Event Hooks , describes the four “hooks” that make up the new custom event API: setup, teardown, add, and remove. It’s a must-read for anyone working with event-driven jQuery scripts.

Plugins

Ben Alman describes his jQuery iff plugin: a chainable “if” statement .

Pete Higgins of Dojo fame has written a jQuery pub/sub plugin , “loosely based on the Dojo publish/subscribe API.” His plugin joins other publish/subscribe plugins such as Fling and jQuery Subscribe/Publish .

Paul Irish has ported a YUI3 script to jQuery for his idleTimer plugin . The plugin detects when a user has become idle.

Jonathan Sharp released an XMLDom plugin , which “takes a string of XML and converts it into an XML DOM object for use with jQuery.”

Tutorials

Janko Jovanovic explains his proof-of-concept for Advanced docking using jQuery

Azam Sharp examines Unit Testing JavaScript Using JQuery QUnit .

Andy Matthews begins a screencast series on jQuery and Air. His first post explores creating a new AIR project in Aptana .

Interviews

In an audio interview, Nathan Smith and Matt Vasquez discuss their use of jQuery.

Drew Douglass interviewed me recently for Nettuts .

Miscellaneous

A new site, jQuery List assembles a list of links to an enormous number of jQuery plugins and code examples on a single page.

Moving my plugins to Google Code

Posted June 07, 2009 by Ariel Flesler

Google Code

I decided to move my plugins from my private svn to Google Code . This means the code being developed is now public and can be viewed and reviewed by anyone.

I'm also trying to automate the building process with a makefile in order to make deploys less tedious (thus more frequent :)).

Everyone's invited to check the code, review it, comment and report bugs. The repository has a few plugins that I actually never released. It doesn't contain non-jQuery scripts yet. I haven't moved them yet and won't do yet.



Links

jQuery Tools vs jQuery UI

Posted June 05, 2009 by Marc Grabanski

  VS

A new library has come out called, "jQuery Tools " that is packed with some visually appealing plugins built on top of jQuery. Here is their opening line to grab your interest:

Let's face it: do you really need drag-and-drop, resizables, selectables or sortable tables in your web applications? Websites are not desktop applications. They are different.

This is obviously a jab at jQuery UI , but before we dismiss what they have to say let's read on...

What you really need are tabs, tooltips, accordions, overlays, smooth navigation, great visual effects and all those "web 2.0" goodies that you have seen on your favourite websites.

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.

While there is some truth to the fact that you don't need each component that jQuery UI provides in most websites. You still have to keep in mind that jQuery UI's focus is to bring a set of components to the table that you can pick and chose from.

I agree with what the jQuery Tools author in saying that everybody needs overlays and visual effects that this library provides. I just don't understand the arrogance of attacking jQuery UI right off the bat, instead of augmenting the library and working together with them. 

Note: the author says he isn't attacking the jQuery UI library (in comments). But I think he should still be looking for ways to add the good parts of his plugins onto jQuery UI.

From an outside perspective, this library shines and has great potential. However as I dig deeper into the API and intensions it just looks bad.

Note: Tero from jQuery Tools has updated the API to fix this issue I'm pointing out here. You can see the result of the update in the jQuery Tools release notes . This type of thing should be sorted out behind the scenes from now on, but it was a good learning experience for me personally about where the public / private line should be.

Tooltip

Demo (hover over box):

Definition of Pride

/* tooltip styling. uses a background image (a black box with an arrow) */ #pride { width: 100px; text-transform:uppercase; font-size:16px; height: 50px; background:#333; padding:20px; color:#fff; } div.tooltip { background:#000; font-size:14px; height:153px; padding:30px; width:310px; font-size:14px; display:none; color:#fff; } /* tooltip title element (h3) */ div.tooltip h3 { margin:0; font-size:18px; color:#fff; }

Tooltip Implimentation

<!-- trigger element --> 
<a href="#" id="trigger"> 
    Move the mouse over this box to see the tooltip in action. 
</a> 
 
<!-- tooltip element --> 
<div class="tooltip"> 
    <h3>The Tooltip</h3> 
 
    <p> 
        <strong>A great tool for designing better layouts and more intuitive user-interfaces.</strong> 
    </p> 
 
    <p> 
        Tooltips can contain any HTML such as links, images, forms and tables. 
        This tooltip is vertically centered on the top edge of the trigger element. 
    </p> 
</div>
$('#tooltip').tooltip();

It doesn't make sense within the context of jQuery.

So apparently, you have to grab the tooltip div, then turn it into a tooltip? Um... what? How do I get multiple tooltips on the page?

Quick, here is the philosophy behind jQuery:

  1. Find element(s) on the page
  2. Do something to them

Is the tooltip on the page? nope, not yet. Ok, failed #1. Where do we go from here? Typically you would grab elements on the page and then attach the tooltips to them. This is just common jQuery sense.

Note: After reading this article, the author of jQuery Tools updated his tooltip API.

As I dive into more examples of the tooltip, it continues to make no sense. The form example have no way to target inputs that you desire with custom classes or ids. You have to modify the markup before page load to change tooltips. After you load up the tooltips, you are stuck and cannot ditch tooltips, or make new ones from within the JavaScript.

Please, just use the jQuery Tooltip plugin or ClueTip .

Non-jQuery API

So now look at the API where it talks about returning the API instead of a jQuery object by passing api: true .... WHAT?! We are now forced to exit out of jQuery into a seperate jQuery Tools API by passing a variable?

var api = $("#myDiv").scrollable({size: 3, api: true});
api.onClick = function(){ ...

Contrast this to using jQuery UI, you can stay within' jQuery and modify all settings.

var $myDiv = $("#myDiv").accordion({ 'header': 'h3' });

Then if later we want to change an option we can use that same div jQuery object.

$myDiv.accordion('option', 'changestart', function(){ ... });

With jQuery UI, all the plugins work with jQuery and it's philosophy. Working with John Resig's supervision and incite. Working together. Returning a seperate API has some potential, but not the way it is implimented here.

jQuery Tools flying solo

All this means (from what I've seen) is that the author did not take the time to learn the why behind jQuery and decided to go his own route, then flame jQuery UI and give you some shiny effects. The effects have potential, but the author needs to open up the code and start collaborating instead of going it solo.

Note: discussion has been opened up between jQuery UI and jQuery Tools teams.

Keep it real, y'all

jQuery Edge: New Special Event Hooks

Posted June 04, 2009 by Brandon Aaron

In jQuery 1.3.3 there are two new special event hooks: add and remove . These two hooks, unlike setup and teardown , are called for each event being bound. The add hook receives the handler, data, and namespaces as arguments. The remove hook receives the data and namespaces as arguments. The add and remove hooks enable the creation of more complex, even customizable, events.

If you haven’t done so, I recommend reading the Special Events blog post which explains what special events are and how to use them. For the following example I assume you already understand the concept of special events in jQuery.

As an example I’m going to build a new special event called “multiclick”. This event tracks clicks on an element and fires at a given threshold or number of clicks. The required number of clicks will be customizable per a handler.

First, here is how you’d use the multiclick event.

$('div')
    .bind("multiclick", { threshold: 5 }, function( event ) {
        alert( "Clicked 5 times" );
    })
    .bind("multiclick", { threshold: 3 }, function( event ) {
        alert( "Clicked 3 times" );
    });


Now lets build it. The skeleton of the multiclick special event looks like this.

jQuery.event.special.multiclick = {
    add: function( handler, data, namespaces ) {
        // called for each bound handler
    },

    setup: function( data, namespaces ) {
        // called once per an element
    },

    remove: function( namespaces ) {
        // called for each bound handler
    },

    teardown: function( namespaces ) {
        // called once per an element
    },

    handler: function( event ) {

    }
};


Behind the scenes we’ll need to use a normal click event. We’ll use the setup hook to bind the initial click event to track the actual clicks. The handler method will be used to properly trigger the multiclick events. Once all the multiclick events are removed, the teardown hook will be triggered. We’ll need to unbind the the click event we used to track the clicks in the setup hook. Here is the updated multiclick event.

jQuery.event.special.multiclick = {
    add: function( handler, data, namespaces ) {
        // called for each bound handler
    },

    setup: function( data, namespaces ) {
        jQuery( this ).bind( "click", jQuery.event.special.multiclick.handler );
    },

    remove: function( namespaces ) {
        // called for each bound handler
    },

    teardown: function( namespaces ) {
        jQuery( this ).unbind( "click", jQuery.event.special.multiclick.handler );
    },

    handler: function( event ) {
        // set correct event type
        event.type = "multiclick";
        // trigger multiclick handlers
        jQuery.event.handle.apply( this, arguments );
    }
};


Next we need to make sure the bound function to a multiclick event isn’t fired until it reaches the number of clicks specified. We’ll utilize the add hook for this. The add hook has the ability to return a function which will take the place of the provided handler. This is a powerful feature and allows us to do all sorts of fun things with special events. In the case of the multiclick event we are going to return a new function that calls the given handler after the specified number of clicks. Here is the add  hook.

jQuery.event.special.multiclick = {
    add: function( handler, data, namespaces ) {
        // get the required number of clicks from data
        var threshold = data && data.threshold || 1,
            // number of clicks
            clicks = 0;

        // return a new function that will become the handler
        return function( event ) {
            // increase number of clicks
            clicks += 1;
            if ( clicks === threshold ) {
                // required number of clicks reached, reset
                clicks = 0;
                // call the actual supplied handler
                handler.apply( this, arguments );
            }
        }
    },

    ...
};


The add hook makes use of closures to keep track of the required number of clicks (threshold), the actual number of clicks, and the handler to be called once the required number of clicks is reached. The jQuery event system keeps everything in tact so that when you call unbind with the same named function that you supplied to bind, it still unbinds it as expected.

It ends up that we don’t actually need to use the remove hook for this special event, so we’ll just remove it. Thats it. The multiclick special event is done. You can see it in action here and the complete code follows.

jQuery.event.special.multiclick = {
    add: function( handler, data, namespaces ) {
        // get the required number of clicks from data
        var threshold = data && data.threshold || 1,
            // number of clicks
            clicks = 0;

        // return a new function that will become the handler
        return function( event ) {
            // increase number of clicks
            clicks += 1;
            if ( clicks === threshold ) {
                // required number of clicks reached, reset
                clicks = 0;
                // call the actual supplied handler
                handler.apply( this, arguments );
            }
        }
    },

    setup: function( data, namespaces ) {
        jQuery( this ).bind( "click", jQuery.event.special.multiclick.handler );
    },

    teardown: function( namespaces ) {
        jQuery( this ).unbind( "click", jQuery.event.special.multiclick.handler );
    },

    handler: function( event ) {
        // set correct event type
        event.type = "multiclick";
        // trigger multiclick handlers
        jQuery.event.handle.apply( this, arguments );
    }
};


Thanks

Thanks to Mike Helgeson who helped evolve the special events API to include these two hooks. He also has a handful of special events that he has created: drag , drop , hover , and wheel .

If you knew about the specialAll event hook, it has been removed in favor of using these two extra hooks.

Labs Preview: jQuery UI Photoviewer

Posted June 02, 2009 by Jörn

Fresh from the jQuery UI Lab comes the Photoviewer widget. As described on its planning wiki page :

An alternative to Lightbox and its various clones, with the sole purpose of displaying images: One or more thumbnails point at the full resolution image, and instead of displaying that image on a new page, its displayed, above an overlay, on the current page.

When a group of anchors with thumbnails is selected, the user can navigate with mouse and keyboard to rotate through the images.

The result is this:

Demo

There’s another demo showing how the widget can resize images that don’t fit into the browser window, as well as customizing animations.

Worth mentioning about the current implementation:

  • A “canvas” element is used to render the shadow. This allows a lot of flexibility in terms of positioning, color and size of the shadow; if a browser doesn’t support canvas (IE without excanvas ) the shadow simply isn’t rendered
  • You can click anywhere to close the viewer, or press Escape
  • Cursor keys, mousewheel as well as mouse navigation buttons (previous/next buttons on some models) can be used to rotate through an image gallery
  • By using the mousewheel to rotate images, there is no need to emulate fixed positioning or similar hacks, though you need to include the mousewheel plugin
  • When the last image is reached, the first is displayed, and the other way round; that way its more obvious that you reached the end of a gallery (”I’ve seen that one already” instead of “Why isn’t anything happening?”)
  • A loading indicator is displayed when loading takes more then 250ms. That way you won’t see it most of the time, just in those cases where you’d otherwise wonder if anything is happening at all
  • The jQuery UI “drop’” effect is used by default to rotate images in a gallery, giving the slight illusion of a slide-projector, therefore giving the viewer a more natural/human feel
  • Images that are too big are resized to fit into the browser window; that also happens when the browser window is resized while the viewer is open
  • The markup is very simply, therefore easy to style: There is one element for the overlay (currently buggy in IE6), one container element containing the canvas-shadow element as well as the actual image (by default styled with 15px rounded white borders)

I’d like to hear your feedback! Post a comment here, send me an email , or participate on the planning wiki page .

Return to normal scheduling

Posted June 02, 2009 by Remy
It has to be said that it’s been a little quiet around the jQuery for Designers web site for the last month. That’s not because I’ve wanted to neglect you, but because I’ve been away during May on holidays and work (travelling around Peru with my wife and Sweden for the SWDC2009 and again [...]

2 Ajax plugins for jQuery +1.3

Posted May 30, 2009 by Ariel Flesler

Introduction

I never actually posted about 2 tiny plugins I made, once jQuery 1.3 was nearing.

Both are somehow related, they are related to Ajax (jQuery.ajax) and they provide sort of a manager to allow multiple implementations of the same feature.

Needless to say, both plugins only work under jQuery 1.3 or higher. The packages(zips) include jQuery 1.2.7pre because that's the version I used to test them when I made them. You obviously don't need to use that version.



XHR

Since jQuery 1.3. The default XHR "factory" function can be overriden by passing an 'xhr' setting to jQuery.ajax with a new function

This tiny plugin provides a simple registry for different xhr implementations to co-exist.

To provide a new implementation, you need to do something like this:

jQuery.xhr.register( 'my_xhr'
, function
( settings ){
  return new
 MyXhrImplementation( settings );
});

The argument settings is the object passed to jQuery.ajax.

To use it, you do:

jQuery.ajax({
    url:'...'
,
    transport:'my_xhr'
,
    // ...

});

The built-in implementation is used by default (unless it's overriden with jQuery.ajaxSetup) and it's called 'xhr'.

Links & Downloads


AjaxFilter

This plugin lets you store multiple functions to sanitize ajax responses.

If you want to provide a new implementation, you need to do something like this:

jQuery.ajaxFilter.register('js_in_href'
,'html'
,
 function
( data ){
  return
 data.replace(/href="javascript:[^"]+"/g
, ''
);
});

or

jQuery.ajaxFilter.register('eval'
,'script html json'
,
 function
( data ){
   return
 data.replace(/eval\(.+?\);?/g
, ''
);
});

Arguments for jQuery.ajaxFilter.register() are:

  1. Name for the filter, used as 'filter' when calling jQuery.ajax.
  2. One or more dataTypes to handle. Can be any combination of ajax, html, json and xml separated by spaces.
  3. The filter function. Will receive 2 arguments: the data and the type. The 'this' will reference the settings object.

To use it, you do:

jQuery.ajax({
    url:'foo.html'
,
    filter:'js_in_href'
,
    // ...

});

The filter can also parse the response.

That means it can (for example) provide an alternative way of eval'ing json. This is specially useful for Adobe AIR apps. If the filter returns something else than a string, it's assumed to be the final response.

Links & Downloads

jQuery Edge: Simplified .hover()

Posted May 28, 2009 by Brandon Aaron

In jQuery 1.3.3 the .hover() method will optionally accept a single method instead of always requiring two methods. This allows you to contain your logic within one method instead of duplicating it among two. I don’t know about you but I’ve avoided using the .hover() method in favor of just manually binding the mouseenter and mouseleave events so that I could use a single function to handle both events. So, lets look at a typical use-case for hover.

$('li')
    .hover(function(event) {
        $(this).addClass('test');
    }, function(event) {
        $(this).removeClass('test');
    });


Now, this is how I’d typically handle this without the use of .hover() .

$('li')
    .bind('mouseenter mouseleave', function(event) {
        $(this).toggleClass('test');
    });


Now lets use the new functionality of .hover() instead of manually binding the events.

$('li')
    .hover(function(event) {
        $(this).toggleClass('test');
    });


Sweet!

Sometimes though you’ll need to do more complex interactions than just toggling a class. In these cases you can simply check the event type that is passed to your handler. When the user mouses over, the event type sent to the hover function will be mouseenter. When the user mouses out, the event type sent to the hover function will be mouseleave. Here is an example checking the event type.

$('li')
    .hover(function(event) {
        $(this)[ (event.type == 'mouseenter') ? 'add' : 'remove') + 'Class' ]('test');
    });


In the above example I’m still just toggling the class on the element that was hovered over/out but doing so in a more verbose way to illustrate how you can check the event type.

Release: Prettydate plugin 1.0.0

Posted May 28, 2009 by Jörn

I’m happy to announce the first release of the Prettydate jQuery plugin. The plugin is based on the plugin originally written by John Resig and provides clientside date formatting in the style of Twitter’s timeline: “just now”, “5 minutes ago”, “yesterday”, “2 weeks ago”. This release extends John’s original release, providing support for internationalization and improving the API a bit: You can specify the source of the ISO-date, while not having to manually set up an interval to update the date formatting over time.

More details can be found on the new plugin page .

Enjoy!

jQuery.ScrollTo 1.4.2 released

Posted May 26, 2009 by Ariel Flesler

Fixes

  • Fixing max calculations for regular DOM elements.

Features

  • The plugin support percentages as target ('50%' or {top:'50%', left:'45%'}).
  • Exposed the max() calculation as $.scrollTo.max.

Enhancements

  • Renamed $.fn.scrollable to $.fn._scrollable to avoid conflicts with other plugins.

Links

Downloads

jQuery.LocalScroll 1.2 released

Posted May 26, 2009 by Ariel Flesler
A new major update of jQuery.LocalScroll has seen the light.

Two minor releases were added after it and is now at 1.2.2 . I'll detail them all together:

Optimizations

  • Replaced a $('[name='+name+']') for a document.getElementsByName(name) to critically improve perfomance.
  • Small improvements to make the code shorter.

Fixes

  • The last argument received by onBefore when scrolling the window, is no more $(window) but the real element being scrolled.

Changes

  • Renamed the option 'persistent' to 'lazy', the latter seemed more adequate. Using 'persistent' will still work (backwards compatibilty)

Features

  • Added the option 'stop', if true (default), each event will stop any previous animations of the target.
  • Added the option 'lock', if true, the plugin will ignore events if already animating.
  • Added $.localScroll.hash( settings ); which will scroll to the given element if the URL contains a valid hash.
  • Removed the option 'cancel' that wasn't working well, and added the option 'hash'. It does what 'cancel' was meant to do, but in a different way.

    After a scroll, the hash( #some_id ) of the link is added to the URL.

    Note: This setting is not compatible with options like offset and margin, as the browser will natively scroll in the end.

    If you use the option 'target'(to scroll an overflowed element) and the window has overflow, setting the hash will scroll the window as well. So my advice is:

    only use 'hash' when scrolling the window.
jQuery.ScrollTo is now at 1.3.2 , it has a new option called 'over', check its demo to see it in action.

jQuery.LocalScroll 1.2.x requires jQuery.ScrollTo 1.3.1 or higher.



Links

Downloads

I really advice using the minified versions. The code is optimized for those releases. Source versions should only be used to learn.

jQuery.LocalScroll 1.2.7 released

Posted May 26, 2009 by Ariel Flesler
In this release I cleaned up the code a little and added some features. Also removed a few old (aka deprecated) stuff that were still hanging around.

Enhancements

  • Added some misc enhancements and cleanup the code.
  • Updated the plugin to take advantage of recent scrollTo additions.

Changes

  • The element that triggered the scroll cannot be accessed anymore from within the onBefore, you can bind your own click (or w/e) to them in order to add a class or things like that.
  • settings.persistent is no longer supported (was deprecated).

Features

  • The set of settings can be accessed from within the onBefore as the 'this'.
  • The hash (#foo) is set to the URL before scrolling, so the back button works accurately (when scrolling the window).
  • The option 'hash' doesn't make the window jump when scrolling overflown elements
  • $.localScroll.hash now resets the element scroll to (0,0) by default. You can set the setting 'reset' to false to avoid this.
Enjoy!

Links

Downloads

jQuery.ScrollTo 1.4.1 released

Posted May 25, 2009 by Ariel Flesler

Fixes

  • The plugin accepts floating numbers.
  • Using jQuery.nodeName where neccessary so that this works on xml+xhtml.
  • The max() internal function wasn't completely accurrate, now it is 98% (except for IE on quirks mode but it's not too noticeable).

Features

  • The target can be 'max' to scroll to the end while keeping it elegant.
  • The plugin works on quirks mode.

Enhancements

  • Default duration is 0 for jquery +1.3. Means sync animations.
  • Rewrote $.fn.scrollable() again. The plugin works on all major browsers (FF, IE, Safari, Opera, Chrome), on all versions, compat & quirks modes, even for iframes.
  • In addition to window/document, if html or body are received, the plugin will choose the right one.

Links

Downloads

jQuery.ScrollTo 1.4 released!

Posted May 25, 2009 by Ariel Flesler

Fixes

  • Fixed the problem when scrolling the window to absolute positioned elements on Safari.
  • Fixed the problem on Opera 9.5 when scrolling the window. That it always scrolls to 0.

Features

  • Added the settings object as 2nd argument to the onAfter callback.
  • The 3rd argument of scrollTo can be just a function and it's used as the onAfter.
  • Added full support for iframes (even max scroll calculation).
  • Instead of $.scrollTo, $(window).scrollTo() and $(document).scrollTo() can be used(even for iframes).
  • Added $().scrollable() that returns the real element t