...

View Full Version : MooTools: Chaining Events



wildreason
08-14-2010, 10:23 PM
I wrote a small script to "Add to favorites" with AJAX & MooTools and came up with the following:


function addFavorite(id) {
url = '/includes/add_favorite.php?r='+id;
new Request({
url: url,
method: 'get',
onSuccess: function(responseText) {
var myFx = new Fx.Tween('favorite');
myFx.start('opacity', 0).chain(function(){
$('favorite').set('html', '<a><img src="/images/heart.png" width=24 alt="save"> saved!</a>');
this.callChain();
}).chain(function(){
this.set('opacity', 1);
});
}
}).send();
}


Which fades the element out, replaces the text and link, then fades it back in.

Is there a better way to write this without having to call the callChain() method? I want to be sure I'm properly chaining methods.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum