Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-14-2010, 10:23 PM   PM User | #1
wildreason
Regular Coder

 
Join Date: Jul 2010
Location: St George, UT
Posts: 139
Thanks: 6
Thanked 17 Times in 17 Posts
wildreason is on a distinguished road
MooTools: Chaining Events

I wrote a small script to "Add to favorites" with AJAX & MooTools and came up with the following:

Code:
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.
__________________
Freelance Website Design

:)
wildreason is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, chaining, mootools, sexy effects

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:48 AM.


Advertisement
Log in to turn off these ads.