Permalink
Browse files

Merge pull request #2263 from ibolmo/fix-2160-fx.morph-percent-unit

Fixes #2160.
  • Loading branch information...
ibolmotest committed Feb 5, 2012
2 parents 0664977 + 955eb53 commit 7c26dd386478f040100b9058667605e52c36f803
Showing with 49 additions and 1 deletion.
  1. +6 −0 Source/Fx/Fx.CSS.js
  2. +41 −0 Specs/1.4client/Fx/Fx.Morph.js
  3. +2 −1 Specs/Configuration.js
View
@@ -25,6 +25,12 @@ Fx.CSS = new Class({
if (values[1] == null){
values[1] = values[0];
values[0] = element.getStyle(property);
+ // 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);
+ }
}
var parsed = values.map(this.parse);
return {from: parsed[0], to: parsed[1]};
@@ -0,0 +1,41 @@
+
+describe('Fx.Morph', function(){
+
+ beforeEach(function(){
+ this.clock = sinon.useFakeTimers();
+
+ this.div = new Element('div', {'class': 'pos-abs-left'});
+ this.style = new Element('style');
+ var definition = [
+ '.pos-abs-left {',
+ 'position: absolute;',
+ 'width: 200px;',
+ 'height: 200px;',
+ 'left: 10%;',
+ 'background: red',
+ '}'
+ ].join('');
+
+ [this.style, this.div].invoke('inject', document.body);
+
+ if (this.style.styleSheet) this.style.styleSheet.cssText = definition;
+ else this.style.set('text', definition);
+ });
+
+ afterEach(function(){
+ this.clock.reset();
+ this.clock.restore();
+ [this.div, this.style].invoke('destroy');
+ });
+
+ it('should morph between % units', function(){
+ var spy = spyOn(this.div, 'setStyle').andCallThrough();
+ this.div.set('morph', {unit : '%'}).morph({'left': 50});
+
+ this.clock.tick(1000);
+
+ expect(this.div.setStyle).toHaveBeenCalledWith('left', ['10%']);
+ expect(this.div.setStyle).toHaveBeenCalledWith('left', ['50%']);
+ });
+
+});
View
@@ -110,7 +110,8 @@ Configuration.sets = {
'Element/Element',
'Element/Element.Event',
'Element/Element.Delegation',
- 'Fx/Fx.Tween'
+ 'Fx/Fx.Tween',
+ 'Fx/Fx.Morph'
]
},

0 comments on commit 7c26dd3

Please sign in to comment.