Skip to content

only try to normalize the units to px on IE if it's not set on style attribute#2417

Closed
gonchuki wants to merge 1 commit intomootools:masterfrom
gonchuki:fix_getStyle_IE_units
Closed

only try to normalize the units to px on IE if it's not set on style attribute#2417
gonchuki wants to merge 1 commit intomootools:masterfrom
gonchuki:fix_getStyle_IE_units

Conversation

@gonchuki
Copy link
Member

After reading this StackOverflow question I noticed the IE normalization code on getStyle was also overriding a style that was directly set on the element, so if for example you set a style on a non-px based unit, a later getStyle would mangle that unit back into px.
This patch simply avoids running the normalization if the return value was directly set on the element, so that IE can behave just like any other browser.

I know @ibolmo is running a drive to refactor this on #2414 but this is just another thing he will need to take into account when refactoring (adds 2 tests) and improves our robustness right now.

@ibolmo
Copy link
Member

ibolmo commented Aug 27, 2012

Right, but this issue is what was brought up in: #2337 (comment)

To reiterate.. should getStyle return the css definition?

Here's a thought:

var CSSStyle = function(element, value){
  this.element = element;
  this.value = value;
};

CSSStyle.prototype.toString = CSSStyle.prototype.valueOf = function(){
  return this.value;
};

CSSStyle.prototype.toInt = function(){
  // if not in px form, then some how compute the value
};

Trying to keep compat with this toValue and toString magic, but I'm sure it's not 100%.

@gonchuki
Copy link
Member Author

The CSS definition as in what the CSS stylesheet has instead of the manually set style attribute? If that's the question, the answer is a plain no, as we need to return what is currently applied to the element, and you can't always query the CSS stylesheet to check a definition (stylesheets loaded cross-domain can't be read by js for example).

That being said, if you inspect this patch it is to actually do less mangling on IE as we were doing too much. The code in that block normalizes cases where IE returns the value on the stylesheet on a getComputedStyle call whereas other browsers return the applied pixel value.

@kguelzau
Copy link

+1 for doing less -> see #2328

@arian
Copy link
Member

arian commented Jan 27, 2014

It has already been changed: https://github.com/mootools/mootools-core/blob/master/Source/Element/Element.Style.js#L169

I'll merge the test.

@arian
Copy link
Member

arian commented Jan 27, 2014

Scratch that...

@arian arian closed this in cc5e5ed Jan 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants