Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3454 (closed defect: duplicate)

Opened 3 years ago

Last modified 3 years ago

Effect.Highlight leaves backgroundColor set when it wasn't set to begin with

Reported by: Andrew@Divix.biz Assigned to: Rails
Priority: normal Milestone:
Component: script.aculo.us Version: 1.0.0
Severity: normal Keywords: v1.5.1
Cc:

Description

In Effect.js: On Line 484 it has:

if(!this.options.restorecolor)

This should be:

if(this.options.restorecolor == undefined)

Problem is this: when the style.backgroundColor is *set* by the "restorecolor" option, it overrides any backgroundColor that might have been set by a CSS class that has been applied to that element. The only way around this is to set the backgroundColor = , unfortunately, if you set option.restorecolor = it considers that as (!this.option.restorecolor) so sets the restorecolor = <current-color> which then doesn't give the results desired. Changing the above allows a person to set option.restorecolor = to indicate to *remove* the background color once the effect has completed and allows the CSS style to indicate the backgroundColor.

Change History

01/13/06 09:52:44 changed by madrobby

  • status changed from new to closed.
  • resolution set to worksforme.

By default Effect.Highlight uses the background-color definition from the .style attribute, or if that is not set from the corresponding CSS rule (see Element.getStyle for this).

So, if you don't set the restorecolor option, all will be fine.

01/24/06 17:09:18 changed by Andrew@Divix.biz

  • keywords set to v1.5.1.
  • status changed from closed to reopened.
  • resolution deleted.

Check the code, but your assessment is incorrect: Here is the code:

if(!this.options.restorecolor)
      this.options.restorecolor = Element.getStyle(this.element, 'background-color');

Here are the possible outcomes from that line:

  • (this.options.restorecolor == null) => this.options.restorecolor gets set to whaterver the backgroundColor of the Element is.
  • (this.options.restorecolor == <somevalue>) => assignment line is skipped, but that is only because this.options.restorecolor *already* has a value in it, so that is no solution either.
  • (this.options.restorecolor == ) => this.options.restorecolor gets set to whatever the backgroundColor of the Element is.
  • (this.options.restorecolor == undefined) => this.options.restorecolor gets set to whatever the backgroundColor of the Element is.

So where is the option for me to *ensure* that this.options.restorecolor is set to or null so it *doesn't* set it later? Answer: nowhere - that is not a possible outcome from that line.

No matter how you slice it, that line is *going* to set "this.options.restorecolor" to a value *other* than "null" (unless your style.backgroundColor = null, then it might work - but that is silly and not functionalith)

Then later, when this code gets executed:

finish: function() {
    Element.setStyle(this.element, Object.extend(this.oldStyle, {
     backgroundColor: this.options.restorecolor

You are *going* to get a value placed *in-line* on the object directly - overriding anything the CSS has set.

Trust me, I've tried it. Run it through the debugger and you will see that it *does* get changed. What this does, is prevent *any* code from setting the backgroundColor in a style and having that propigate to the HtlmElement that just got it's backgroundColor set *explicitly*.

With my code change, it works as you indicate; without it, it works as I have indicated above.

Perhaps you have a different set of code, or perhaps your code already looks like mine...all I know is the code I downloaded is broken in that area.

08/17/06 17:13:41 changed by tomg@byu.net

  • status changed from reopened to closed.
  • resolution set to fixed.

See also #3738. (duplicate)

08/30/06 03:17:40 changed by anonymous

  • status changed from closed to reopened.
  • resolution deleted.

In total agreement with Andrew on this, I've been bitten by the same bug and looking at the source in the trunk, it hasn't been fixed.

The css :hover function breaks, and if the css class is changed after a highlight, no change will be observed. The inline style overrides the css in both of these situations.

The hack to fix it:

this.oldStyle = { backgroundImage: this.element.getStyle('background-image') };

becomes

this.oldStyle = { backgroundImage: (this.element.style.backgroundImage ? this.element.getStyle('background-image') : null) };

and

if (!this.options.restorecolor) {
  this.options.restorecolor = this.element.getStyle('background-color');
}

becomes

if (!this.options.restorecolor) {
  this.options.restorecolor = (this.element.style.backgroundColor ? this.element.getStyle('background-color') : null);
}

09/13/06 00:53:16 changed by bitsweat

  • status changed from reopened to closed.
  • resolution set to duplicate.