Thursday, December 27, 2007

jQuery.Accessible

What is this ?

  • This plugin aims to be a collection of snippets that improve accessibility for websites.
  • It also includes a set of "recommendations" coded as tests to improve accessibilty (even beyond javascript).
  • These recommendations can be tested against a page, and get a summary of the results.

How to use it ?

  • First add a call to jquery.js (duh!).
  • Add jquery.accessible.js. This contains the engine for rules/fixes and a set of predefined ones.
  • Right after this, you are ready to run the fixes by calling jQuery.accessible(). You can pass in a hash to specify, with the id and true or false, which ones to run. IMPORTANT: don't call this function inside document.ready, call it right away instead.
If you want to run the tests in your page:
  • Add jquery.accessible.validator.js after jquery.accessible.js.
  • Call jQuery.accessible.runTests(). (right away too)
  • You can optionally indicate where to output the results, with a selector as first argument.

What else ?

  • This plugin is mostly a proof of concept for now.
  • The author's intention is to get developers to collaborate, in order to consolidate a large number of improvements to websites' accessibility.
  • Allowing any developer to make his/her site, much more accessible, with little effort.
If you have something to say or contribute, please:

Links:

Saturday, December 8, 2007

Javascript Console for Maxthon (JSCM) 2.0

Features

  • Execution of any kind of native javascript.
  • jQuery is integrated, is possible to access the elements in the active tab.
  • It includes an 'inspect' option, similar to Firebug's.
  • Console's results are dumped in a colorful way.
  • Dumped HTML elements, will allow quick inspection of the matched elements.
  • Switching between recently executed scripts, with Page Down and Page Up.
  • Frequently used scripts can be stored, for further use.
  • Functions Window() and Document() to retrieve the document and window objects from the active tab.

FAQ

  • How to access the elements in the active tab
    Using jQuery's selectors with no context, will match the elements in the neighboring page. So $('a') or jQuery('a') will match all the links in the page. For further information about jQuery, visit http://jquery.com.
  • What does inspect mean
    When Inspect is activated, moving the mouse over any element in the active tab, will highlight it. When an element is clicked, the plugin will generate a selector that will match that specific element and it will appear in the console. The same applies to dumped HTML elements.
  • Where can I get more examples
    The pack contains a file called Manual.txt which includes some examples with a short explanation. You can also check http://docs.jquery.com for jQuery related information.

Links

Friday, November 30, 2007

Static methods for Array

I wrote today a small piece of code, to add static methods to Array. These methods allow developers to manipulate arrays, arguments, node collections and array-like hashes in a normalized way. Using the built-in methods that arrays have. The js won't add forEach, map, etc. It will only take, those methods available for arrays, will make them compatible for array-like objects, and will append them to the Array object.

Extending the prototype of native object is a bad practice (for many) and will pollute the global scope (I fully agree with this). The added functions, will be only fulfilling the lack of these methods, in browsers that don't support them( only Firefox supports them, that I know of ).

Array static methods in Firefox, don't support node collections though. So calling this:

Array.pop(document.getElementsByTagName('p'));
Will fail in Firefox. Using:
[].pop.apply(document.getElementsByTagName('p'));
Won't work for nodes, and will throw an error in any browser.

That's why there're two versions of this code. The one called array, and array.lite. The latter won't override existing methods. In consequence, node collections won't be supported. On the contrary, array, will override as much as possible, ensuring support for node collections for those methods found in the prototype.

Here's a small demo to show it's use. It has been tested on Windows XP in IE6, FF 2, Safari 3 and Opera 9.22. I'm not sure, but it seems to be a little buggy in Opera, I still haven't figured out why.

Links Downloads: If this code is added after normalizing the new iteration methods they will also be added to the Array object

Thursday, November 22, 2007

jQuery.Rule 0.9 released

Changes

  • Made the code work faster.
  • Extended $.fn with ownerNode,sheet,cssRules and cssText.
  • Added text and outerText to $.rule and $.rule.fn.
  • Made the example nicer.
  • Removed $.fn.collect.
  • Created an API.
  • Added queue,dequeue,animate and stop to $.rule.fn (non-IE).
  • remove() works in Opera 9 and Safari Win!
  • $.rule.fn.filter now supports a regex as filter.

Links

Downloads:

Saturday, November 17, 2007

jQuery.LocalScroll 1.1.2 released

Changes

  • The defaults have been made public for modification.
  • The anchor filter has been optimized
  • A bug was fixed, clicking an anchor with href=# and then a special link, wasn't scrolling.
  • A trigger event can be specified, if click is not the desired one.
  • If 'cancel' is set to false, the default behaviour of the anchor will occur.

New option 'lazy'

jQuery.LocalScroll counts with a new, and very useful option. If lazy is set to true, then the plugin will react to new links, that are appended to the originally matched elements. jQuery.ScrollTo had some minor releases and is now at 1.2.4. This is not the version included in this release of jQuery.LocalScroll, but they are perfectly compatible. Update:jQuery.LocalScroll 1.1.3 was released, the upgrade is recommended, upgrading to jQuery.ScrollTo 1.3 is also adviced (included in the last release).

Links

Downloads

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

Tuesday, November 6, 2007

jQuery.Rule

This plugin allows quick creation/manipulation of CSS Rules, in a "jQuery-way". It includes features like chaining, iteration using each, selectors with context. Many functions are available, like slice, pushStack, not, add, remove, append, css, and some more. As far as it has been tested, the plugin should perform well in most browsers, some specials methods still need some more testing. Feedback is much appreciated.

Links

Downloads

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

Tuesday, October 30, 2007

jQuery.ScrollShow

I've made a new plugin, that supercedes this one.
Please check jQuery.SerialScroll.
It's very small and offers high customizability, can be used for slideshows, site navigation, news tickers, etc. (These 3 exemplified in the demo).

jQuery.ScrollShow is a very customizable slideshow, that relies on jQuery.ScrollTo, to slide(scroll) the items. Documentation is included in the source file. The plugin is still in beta stage, but will be soon (hopefully) stable. Feedback and bug reports are very welcome.

Links

Monday, October 29, 2007

jQuery.ScrollTo 1.2 released

Changes

  • The option 'onafter' is now called 'onAfter'.
  • The option 'margin' can be setted to true, then the margin of the target element, will be taken into account and will be deducted.
  • Two axis can be scrolled together, this is setted with the option 'axis'.
  • In case 2 axis are chosen, the scrolling can be queued: one scrolls, and then the other.
  • There's an intermediary event, 'onAfterFirst' called in case the axis are queued, after the first ends.
  • If the option 'margin' is set to true, the plugin will take in account, the margin of the target(no use if target is a value).

Notes

  • If queuing is activated, the order of the axes ('xy' or 'yx') will tell the plugin, in what order to scroll the axis.
  • 'margin' will only be valid, if the target is a selector, a DOM element, or a jQuery Object.
  • If the first axis to be scrolled, is already positioned, that animation will be skipped, to avoid a delay in the animation.
Along with this release, jQuery.LocalScroll 1.0.1 is released. Changes:
  • 'onbefore' is now named 'onBefore', to keep jQuery.ScrollTo naming conventions.
  • A filter can be specified, so that only some of the suitable links are bound.

Links

Wednesday, October 24, 2007

jQuery.LocalScroll

Notice

I've pretty much stopped updating this blog, but the plugin development is still on-going. You can find the link to the Github project page at the bottom of the article.

What does this plugin do ?

This plugin will animate a regular anchor navigation [1] [2].
It will allow your visitors to navigate your site with a smooth scrolling effect.

Each time a link is clicked, the element you decide(can be the whole screen), will gradually scroll to the targeted element, instead of "jumping" as it'd normally do.
jQuery.ScrollTo is used for the animation.

How to implement it ?

That's easy! you need to set links and anchors, that means, set an id to all those elements you want to scroll to.
These are the anchors.
Then add links with the respective id in the href, like this:

<a href="#the_id">your_text</a>
Let's call these "local links".
Lastly, you must call jQuery.LocalScroll on elements that contain our local links, you must wait for the document to be ready.

So if (for example) you have a div with id "navigation" and the local links are inside. You add this inside a document.ready:
$('#navigation').localScroll();
If your links are all spread, you can use:
$.localScroll();
That gets all the local links in the page. Both calls to the plugin accept one optional argument, that is, a hash specifying the settings described below. None is required.

Settings

  • target
    What to scroll (selector, DOMElement, or jQuery Object). If none is specified, the whole window will be scrolled.
  • filter
    String or function filter to ignore some of the links.
  • event
    On which event of the link to react (click by default)
  • lazy
    If true, more links can be added to the matched elements ( by AJAX, jQuery, etc ) and the plugin will also react to them.
  • stop
    If true (default), the plugin will stop any previous animations of the target, to avoid queuing.
  • lock
    If true, the plugin will ignore events if already animating (alternative to 'stop').
  • hash
    If true, the hash of the clicked link, will appear on the address bar once the animation ends.
    Note:This option isn't too cool when scrolling overflown elements, it's mostly recommended when scrolling the window.
  • onBefore
    A function to be called before each scrolling. It receives the following arguments: event object, targeted element and target to be scrolled. The 'this' will point to the set of settings.
  • reset
    Only for $.localScroll.hash(), if true (default) elements' scroll is reset before actual scrolling.
In addition to that, you can use jQuery.ScrollTo's settings!
Check its demo to see all of them.

The plugin also adds a function, $.localScroll.hash() , that checks the URL in the address bar, and if there's a hash(#an_id), it will scroll to the element. It accepts a hash of settings, just like $.localScroll. You will likely call it on document ready. Check the regular example to see it in action.

How do I use the settings ?

The most important setting is 'target', you might not want to navigate(scroll) the screen, but only an overflowed element(like the demo).
In that case, you specify the target, with a selector or the element itself.
$('#navigation').localScroll({
   target:'#content'
});
Instead of the window, an element with id 'content' will be scrolled.

Finally, a more complex call to show some customization in action:
Let's say you need to scroll on both axes to uncover all the anchors, then we'll need the option 'axis'.
You want to do an horizontal scroll, and then vertical, the code would be:
$('ul.sections').localScroll({
   target:'#content',
   axis:'xy',
   queue:true //one axis at a time
});
Note that 'axis' and 'queue' actually belong to jQuery.ScrollTo, not to jQuery.LocalScroll.

Dynamic content( AJAX, AHAH, or simply jQuery )

The plugin supports dynamically added/loaded anchors and local links. You need to set the option 'lazy' to true. Note that the matched elements (#navigation in the first example) must be preserved in the DOM. But any content inside it can be modified. You don't have this problem if you use the global call.

Troubleshooting

When using the browser's back button, the scroll isn't reverted

This is a known fact when scrolling overflown elements (as in not the window).

When clicking a link, it jumps directly to the target

That's the browser default behavior (no javascript). You either have a javascript error (check with Firebug) or something's wrong in the call to the plugin.

Strange things happen

Try removing the option 'hash' or set it to false. It can cause problems.

Check ScrollTo's troubleshooting.

Links

jQuery.ScrollTo 1.1 released

Changes

  • Relative animations are now supported.
  • Fixed a bug, the plugin would fail if the 'target' is a selector and it ends with a number.
  • The 'target' selector no longer supports 'em' or '%' as they won't work with animate anyway.
  • The plugin is no longer dependant on jQuery.Dimensions! :)
  • Fixed a bug, any-number + 'px' or relative animations, combined with no speed or speed 0 would fail. This no longer happens.

Links

Friday, October 19, 2007

jQuery.Bubble

This plugin adds bubbling functionality to jQuery. The code is similar to jQuery.fn.trigger's because it's meant to extend it. It also generates it's own event object, that will remain untouched through the bubbling, meaning it's safe to attach attributes to it and grab them with the ancestors while the event bubbles up. I tried to use jQuery's core functions as much as possible, but most functions I needed were not compatible, and would destroy the custom event object, still the code remains short. NOTES:

  • jQuery.Bubble 1.0 was tested with jQuery 1.3.1 and it's compatible with it's event system.
  • jQuery.Bubble 1.2 and further versions will stick to the new system(1.2 's).
  • There're two versions, the regular (async) and the synchronic version. I'm not sure which one works better, I suppose the asynchronic one resembles more to the browser's native (bubbling) behavior, so I'd use that one. Please let me know if you test them.
Links: Related Links:

Thursday, October 18, 2007

jQuery.ScrollTo

Notice

I've pretty much stopped updating this blog, but the plugin development is still on-going. You can find the link to the Github project page at the bottom of the article.

Introduction

An article about animated scrolling with jQuery inspired me to make a small, customizable plugin for scrolling elements, or the window itself.

How to specify what to scroll ?

Simple, all the matched elements will be scrolled, for example:
$('div.pane').scrollTo(...);//all divs w/class pane
If you need to scroll the window (screen), then use:
$.scrollTo(...);//the plugin will take care of this

How to specify where ?

There are many different ways to specify the target position.
These are:
  • A raw number
  • A string('44', '100px', '+=30px', etc )
  • A DOM element (logically, child of the scrollable element)
  • A selector, that will be relative to the scrollable element
  • The string 'max' to scroll to the end.
  • A string specifying a percentage to scroll to that part of the container (f.e: 50% goes to to the middle).
  • A hash { top:x, left:y }, x and y can be any kind of number/string like above.
Note that you only need to use the hash form, if you are scrolling on both axes, and they have different positions.
Don't use the hash to scroll on both axes. Instead, keep reading :)

Settings

The plugin offers you many options to customize the animation and also the final position.
The settings are:
  • axis: Axes to be scrolled, 'x', 'y', 'xy' or 'yx'. 'xy' is the default.
  • duration: Length of the animation, none (sync) by default.
  • easing: Name of the easing equation.
  • margin: If true, target's border and margin are deducted.
  • offset: Number or hash {left: x, top:y }. This will be added to the final position(can be negative).
  • over: Add a fraction of the element's height/width (can also be negative).
  • queue: If true and both axes are scrolled, it will animate on one axis, and then on the other. Note that 'axis' being 'xy' or 'yx', concludes the order
  • onAfterFirst: If queing, a function to be called after scrolling the first axis.
  • onAfter: A function to be called after the whole animation ended.
  • You can use any other setting accepted by $().animate()
These settings are very well explained in the demo. Make sure to check it to understand them all.

Manually finding the scrolling limit

$.scrollTo always had an internal function that calculates the scrolling limit for both axes. Since 1.4.2, this function is exposed as $.scrollTo.max.

It's not too nice to use yet but it's probably not something you'll need, you must pass two arguments: a DOM element and an axis string ('x' or 'y') and it will return the max number.


Overloading

This plugin accepts the arguments in two ways, like $.animate().
$(...).scrollTo( target, duration, settings );
$(...).scrollTo( target, settings );
In this second case, you can specify the duration in the hash. You don't need to include any setting, not even the duration, everything has defaults.
The hash of defaults can be accessed at: $.scrollTo.defaults.

jQuery.scrollTo's sons

Indeed, jQuery.scrollTo has offspring :)
  • jQuery.localScroll: Will add a scroll effect, to any anchor navigation. Ideal for slides, table of contents, etc. It's small, and incredibly easy to implement.
  • jQuery.serialScroll: It's a multi-purpose plugin to animate any kind of sequential navigation(prev/next). It's also small and highly customizable.
These plugins require jQuery.scrollTo and can use its settings!.
That makes around 20 options to fully customize each of them.
They are wrappers for common situations where you might need this plugin.
Using them will save you a lot of time and will give you even more customization.
They can be safely used simultaneously and the 3 of them minified, take merely 3.5kb altogether!

Troubleshooting

Doesn't scroll on IE
Sometimes, you need to set a position (relative or absolute) to the container and give it fixed dimensions, in order to hide the overflow.
If this doesn't work, try giving the container fixed dimensions (height & width).

Links

Tuesday, October 16, 2007

jQuery.Listen

This plugin brings a clean, light solution, to websites with dynamic loaded content, or full of event bindings.
Intead of bound, handlers for events, are registered along with matching selectors. And they'll still work for new added content.
This is achieved, using Event delegation, so the plugin will only work for events that bubble.

The plugin supports these kind of selectors:

  • #id
  • tag
  • .cssClass
  • tag.cssClass
The plugin now supports comma-separated selectors
I'd like to add more support in the future, but perfomance and scalability are more important. These simple selectors give enough functionality for many cases. If, for example, you want ULs, to react to clicks on its LIs, then you can do this:
$('ul').listen('click','li',function(){
    alert('you clicked an item!!');
});
No matter how many times you add/remove items, they'll still be clickable. You can also do this:
$.listen('click','li',function(){
    alert('you clicked an item!!');
});
This time, the listener will be the document. So now you can add/remove ULs as well, clicking the items will still trigger the handler.

Links

Downloads

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

Update 2/20/08:
jQuery.Listen can now handle both focus and blur events thanks to the focusin/focusout workaround.
Many thanks to Jörn Zaefferer for lending me the code!
Update 3/7/08:
Added 1.0.3, it can handle comma-separated selectors, and there's a new experimental option. You can call:
  $.listen.cache(true);
Only after you finished with ALL the bindings, it will then start caching some things. Again, this is experimental.