Fix 2280 Fx Units #2282

Merged
merged 7 commits into from Feb 9, 2012

Projects

None yet

3 participants

@arian
MooTools member

No description provided.

@arian
MooTools member

Fixes #2280.

Tested: IE6, IE8, IE9, Firefox, Chrome.

@arian
MooTools member

Doesn't work in Opera yet..

@arian arian * Fixes Fx unit option support for margins and Opera
* Removes opera hack in Element.Style, apparently it isn't necessary anymore. All specs pass.
63d61b6
@arian
MooTools member

Fixed opera issues and Fx for margins.

@arian arian commented on the diff Feb 9, 2012
Source/Fx/Fx.CSS.js
// adapted from: https://github.com/ryanmorr/fx/blob/master/fx.js#L299
- if (this.options.unit != 'px'){
- element.setStyle(property, values[1] + this.options.unit);
- values[0] = (values[1] || 1) / parseFloat(element.getComputedStyle(property)) * (parseFloat(values[0]) || 0);
- element.setStyle(property, values[0] + this.options.unit);
+ if (unit && from.slice(-unit.length) != unit && parseFloat(from) != 0){
+ element.setStyle(property, to + unit);
+ var value = element.getComputedStyle(property);
+ // IE and Opera support pixelLeft or pixelWidth
+ if (!(/px$/.test(value))){
+ value = element.style[('pixel-' + property).camelCase()];
+ if (value == null){
+ // adapted from Dean Edwards' http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
+ var left = element.style.left;
@arian
arian Feb 9, 2012

I removed some stuff, like runtimeStyle which is IE only, because this fix is for Opera as well. Not sure how important that is for IE. The test seems to work :D

@ibolmo
MooTools member

👍

@ibolmo ibolmo merged commit e65e04b into mootools:master Feb 9, 2012
@fbender fbender commented on the diff Feb 20, 2012
Source/Fx/Fx.CSS.js
@@ -22,18 +22,31 @@ Fx.CSS = new Class({
prepare: function(element, property, values){
values = Array.from(values);
- if (values[1] == null){
- values[1] = values[0];
- values[0] = element.getStyle(property);
+ var from = values[0], to = values[1];
+ if (to == null){
+ to = from;
+ from = element.getStyle(property);
+ var unit = this.options.unit;
// adapted from: https://github.com/ryanmorr/fx/blob/master/fx.js#L299
@fbender
fbender Feb 20, 2012

This line should reference a commit, too. L299 can change easily ;-). Or remove the comment altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment