forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore($$forceReflow): create service for issuing reflows in animations
- Loading branch information
Showing
5 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
var $$ForceReflowProvider = function() { | ||
this.$get = ['$document', function($document) { | ||
return function(domNode) { | ||
//the line below will force the browser to perform a repaint so | ||
//that all the animated elements within the animation frame will | ||
//be properly updated and drawn on screen. This is required to | ||
//ensure that the preparation animation is properly flushed so that | ||
//the active state picks up from there. DO NOT REMOVE THIS LINE. | ||
//DO NOT OPTIMIZE THIS LINE. THE MINIFIER WILL REMOVE IT OTHERWISE WHICH | ||
//WILL RESULT IN AN UNPREDICTABLE BUG THAT IS VERY HARD TO TRACK DOWN AND | ||
//WILL TAKE YEARS AWAY FROM YOUR LIFE. | ||
if (domNode) { | ||
if (!domNode.nodeType && domNode instanceof jqLite) { | ||
domNode = domNode[0]; | ||
} | ||
} else { | ||
domNode = $document[0].body; | ||
} | ||
return domNode.offsetWidth + 1; | ||
}; | ||
}]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
describe('$$forceReflow', function() { | ||
it('should issue a reflow by touching the `document.body.client` when no param is provided', function() { | ||
module(function($provide) { | ||
var doc = jqLite('<div></div>'); | ||
doc[0].body = {}; | ||
doc[0].body.offsetWidth = 10; | ||
$provide.value('$document', doc); | ||
}); | ||
inject(function($$forceReflow) { | ||
var value = $$forceReflow(); | ||
expect(value).toBe(11); | ||
}); | ||
}); | ||
|
||
it('should issue a reflow by touching the `domNode.offsetWidth` when a domNode param is provided', | ||
inject(function($$forceReflow) { | ||
|
||
var elm = {}; | ||
elm.offsetWidth = 100; | ||
expect($$forceReflow(elm)).toBe(101); | ||
})); | ||
|
||
it('should issue a reflow by touching the `jqLiteNode[0].offsetWidth` when a jqLite node param is provided', | ||
inject(function($$forceReflow) { | ||
|
||
var elm = {}; | ||
elm.offsetWidth = 200; | ||
elm = jqLite(elm); | ||
expect($$forceReflow(elm)).toBe(201); | ||
})); | ||
|
||
describe('$animate with ngAnimateMock', function() { | ||
beforeEach(module('ngAnimateMock')); | ||
|
||
it('should keep track of how many reflows have been issued', | ||
inject(function($$forceReflow, $animate) { | ||
|
||
var elm = {}; | ||
elm.offsetWidth = 10; | ||
|
||
expect($animate.reflows).toBe(0); | ||
|
||
$$forceReflow(elm); | ||
$$forceReflow(elm); | ||
$$forceReflow(elm); | ||
|
||
expect($animate.reflows).toBe(3); | ||
})); | ||
}); | ||
}); |