Skip to content

Commit

Permalink
Added :highlight effect to do YFT automatically
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1004 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Mar 26, 2005
1 parent 9ca9f95 commit ae5f3c7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion actionpack/lib/action_view/helpers/javascript_helper.rb
Expand Up @@ -159,7 +159,8 @@ def options_for_ajax(options)

js_options['asynchronous'] = options[:type] != :synchronous
js_options['method'] = options[:method] if options[:method]

js_options['effect'] = ("\'"+options[:effect].to_s+"\'") if options[:effect]

if options[:form]
js_options['parameters'] = 'Form.serialize(this)'
elsif options[:with]
Expand Down
27 changes: 27 additions & 0 deletions actionpack/lib/action_view/helpers/javascripts/prototype.js
Expand Up @@ -203,6 +203,9 @@ Ajax.Updater.prototype = (new Ajax.Base()).extend({

updateContent: function() {
this.container.innerHTML = this.request.transport.responseText;
switch(this.options.effect) {
case 'highlight': new YellowFader(this.container); break;
}
if (this.onComplete) this.onComplete(this.request);
}
});
Expand Down Expand Up @@ -346,3 +349,27 @@ Form.Observer.prototype = (new Abstract.TimedObserver()).extend({
}
});

/*--------------------------------------------------------------------------*/

var YellowFader = Class.create();
YellowFader.prototype = {
initialize: function(element) {
if (typeof element == 'string') element = $(element);
if (!element) return;
this.element = element;
this.start = 153;
this.finish = 255;
this.current = this.start;
this.fade();
},
fade: function() {
if (this.isFinished()) return;
if (this.timer) clearTimeout(this.timer); // prevent flicker
highlight_yellow(this.element, this.current);
this.current += 17;
this.timer = setTimeout(this.fade.bind(this), 250);
},
isFinished: function() {
return this.current > this.finish;
}
}

0 comments on commit ae5f3c7

Please sign in to comment.