Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes #2321 - Fixes Fx.CSS when a unit is set, but the 'from' value i…
…s not a string, which caused a 'slice is not a method error'
  • Loading branch information
Arian committed Mar 3, 2012
1 parent 160cdb3 commit 1fcdafd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Source/Fx/Fx.CSS.js
Expand Up @@ -28,7 +28,7 @@ Fx.CSS = new Class({
from = element.getStyle(property);
var unit = this.options.unit;
// adapted from: https://github.com/ryanmorr/fx/blob/master/fx.js#L299
if (unit && from.slice(-unit.length) != unit && parseFloat(from) != 0){
if (unit && from && typeof from == 'string' && 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
Expand Down
47 changes: 42 additions & 5 deletions Specs/1.4client/Fx/Fx.Morph.js
Expand Up @@ -29,13 +29,50 @@ describe('Fx.Morph', function(){
});

it('should morph between % units', function(){
var spy = spyOn(this.div, 'setStyle').andCallThrough();
this.div.set('morph', {unit : '%'}).morph({'left': 50});
var spy = spyOn(this.div, 'setStyle').andCallThrough();
this.div.set('morph', {unit : '%'}).morph({'left': 50});

this.clock.tick(1000);
this.clock.tick(1000);

expect(this.div.setStyle).toHaveBeenCalledWith('left', ['10%']);
expect(this.div.setStyle).toHaveBeenCalledWith('left', ['50%']);
});

it('it should morph when the unit option is set, but an empty value', function(){

this.div.set('morph', {
duration: 100,
unit: 'px'
}).morph({
opacity: 1,
top : 100
});

this.clock.tick(150);

expect(this.div.getStyle('top')).toEqual('100px');
expect(this.div.getStyle('opacity')).toEqual(1);

});

it('it should morph when the unit option is set, but the style value is a number', function(){

this.div.setStyles({
top: '50px',
opacity: 0
}).set('morph', {
duration: 100,
unit: 'px'
}).morph({
opacity: 1,
top : 100
});

this.clock.tick(150);

expect(this.div.getStyle('top')).toEqual('100px');
expect(this.div.getStyle('opacity')).toEqual(1);

expect(this.div.setStyle).toHaveBeenCalledWith('left', ['10%']);
expect(this.div.setStyle).toHaveBeenCalledWith('left', ['50%']);
});

});

0 comments on commit 1fcdafd

Please sign in to comment.