patching scriptaculous to call effects on DOM NodeElements

14Nov06

By Josh Adams.

I don’t know what was up with me that night, scriptaculous DOES already do this.

so I’m writing a bit of javascript, and I realize that I don’t want to have to have an id on an element just to call a scriptaculous effect on it. I’m sure that other people have solved this, but for me I changed Effect.Fade to the following:


Effect.Fade = function(element) {
try
{
element.parentNode();
}
catch(e)
{
element = $(element);
}
var oldOpacity = element.getInlineOpacity();
var options = Object.extend({
from: element.getOpacity() || 1.0,
to: 0.0,
afterFinishInternal: function(effect) {
if(effect.options.to!=0) return;
effect.element.hide();
effect.element.setStyle({opacity: oldOpacity});
}}, arguments[1] || {});
return new Effect.Opacity(element,options);
}

The actual bit I added is right at the top. It used to just let you pass in text for an ID (the catch part), and I added the ability to avoid doing that if we already have a DOM id.

So now I can add behaviour to elements based on their css classes via a javascript, and I can still get nice scriptaculous effects without overwriting id attributes.

powered by performancing firefox

Advertisements


No Responses Yet to “patching scriptaculous to call effects on DOM NodeElements”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: