PDA

View Full Version : Highlight effect should be "standardized"



brian.moeskau
21 Nov 2006, 4:44 PM
Hey Jack,

The Actor.highlight() effect currently fades the highlight color in and then changes back to the original color immediately. This is reversed from the de facto standard for highlight, which is to change to the highlight color immediately, then fade back out to the original color. See the script.aculo.us highlight effect to confirm this (which was based on the original "yellow fade" technique made popular several years ago). So I propose the following patch:


YAHOO.ext.Actor.prototype.highlight = function(highlightColor, originalColor, duration, attribute){
attribute = attribute || 'background-color';
highlightColor = highlightColor || '#FFFF99';
var original = this.getStyle(attribute);
originalColor = originalColor || ((original && original != '' && original != 'transparent') ? original : '#FFFFFF');
var cfg = {};
cfg[attribute] = {to: originalColor, from: highlightColor};
this.setVisible(true);
this.animate(cfg, duration || 1.5, null, YAHOO.util.Easing.easeOut, YAHOO.util.ColorAnim);
};
- I renamed the color params to make it more clear (and because I had to reverse them in the YAHOO attribute list, which made no sense the way they were named before)
- Defaulted the highlight color to #FFFF99 (yellow) if not specified
- Changed the easing method from bounceOut to easeOut
- Changed the default duration to be 1.5 seconds instead of .5 as that appears more natural (and closely matches the script.aculo.us version)
- Removed the last line (that resets the color) as it's no longer needed

I would also (personally) vote for one more change: moving 'duration' to be the first parameter. I would think that overriding the default duration would be more commonly needed than setting specific colors, and so it would make some calls slightly simpler. Of course, that's a breaking change for not that much benefit, so I leave it up to you :D