Home arrow Ruby-on-Rails arrow Page 4 - Introducing script.aculo.us
RUBY-ON-RAILS

Introducing script.aculo.us


Rails can be used with more than Ruby. In this three-part series, you'll find out about the visual effects you can do with script.aculo.us on Rails. It is excerpted from chapter four of the book Ajax on Rails, written by Scott Raymond (O'Reilly, 2007; ISBN: 0596527446).

Author Info:
By: O'Reilly Media
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
November 08, 2007
TABLE OF CONTENTS:
  1. · Introducing script.aculo.us
  2. · Visual Effects
  3. · Toggling
  4. · Queues

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Introducing script.aculo.us - Queues
(Page 4 of 4 )

 

In some circumstances, you may want to chain effects, so that they occur sequentially. As a first attempt, you might simply call one effect after the other:

  <%= link_to_function "Blind Up/Down",
        "new Effect.BlindUp('target');
         new Effect.BlindDown('target')" %>

Unfortunately, this won’t have the desired result. As new effects are created, script.aculo.us adds them to a global queue. By default, these effects are executed in parallel—which means these two effects will collide with each other. To specify an effect’s position in the queue, use thequeueoption:

  <%= link_to_function "Blind Up/Down",
        "new Effect.BlindUp('target');
         new Effect.BlindDown('target', { queue: 'end' })" %>

Now the two effects will execute sequentially, rather than at once. If you want more than two effects sequentially, just keep adding them with aqueue ofend. Thequeue option can also take a value offront, which causes the effect to be executed before anything else in the queue.

script.aculo.us also supports multiple queues, so that you can create named scopes for effects queues that run independently. For more information on creating queue scopes, see Chapter 11.

Callbacks

The options hash can also take parameters for callbacks that are executed through the effect’s life cycle. beforeStart is called before the main effects rendering loop is started.beforeUpdateis called on each iteration of the effects rendering loop, before the redraw takes places.afterUpdateis called on each iteration of the effects rendering loop, after the redraw takes places.afterFinishis called after the last redraw of the effect was made. Callbacks are passed one argument, a reference to the effect object. For example:

  <%= link_to_function "Fade with callback",
       
"new Effect.Fade('target', { afterUpdate: function(effect) {
          effect.element.innerHTML = effect.currentFrame;
        }
})" %>

Chapter 11 coversEffectcallbacks in more detail.

Transitions

The transition option determines the pattern of change—a constant linear rate of change, gradual speed up, or anything else. There are eight standard transitions, and you can easily define new ones. To override the default transition for an effect, use thetransitionoption like this:

  <%= link_to_function "Fade with wobble",
        "new Effect.Fade('target',
           { transition: Effect.Transitions.wobble })" %>

The available transitions are:linear,reverse,none,full,sinoidal,pulse,wobble, andflicker. Chapter 11 describes them in detail and explains how to create custom transitions. To get a feel for the possibilities, create a demo for yourself of each transition:

  <% %w( linear reverse none full sinoidal pulse
        wobble flicker ).each do |name| %> 
   <%= link_to_function "Fade with #{name}",
         "new Effect.Fade('target',
           { transition: Effect.Transitions.#{name} })" %>
  <% end %>

Please check back next week for the continuation of this article.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form
- Ruby on Rails Templates and Layouts
- Action Pack Controller Creation
- Writing an Action Pack Controller

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials