File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change
1
+ describe ( 'PosAnimation' , function ( ) {
2
+ var el ;
3
+
4
+ beforeEach ( function ( ) {
5
+ el = document . createElement ( 'div' ) ;
6
+ this . subject = new L . PosAnimation ( ) ;
7
+ this . subject . _el = el ;
8
+ } ) ;
9
+
10
+ describe ( '#_onStep' , function ( ) {
11
+ it ( "sets element position and fires step event if it is able to get current position" , function ( ) {
12
+ var point = new L . Point ( 5 , 5 , true ) ;
13
+ sinon . stub ( this . subject , '_getPos' ) . returns ( point ) ;
14
+ this . subject . fire = sinon . stub ( ) ;
15
+ this . subject . _onStep ( ) ;
16
+ expect ( this . subject . fire . withArgs ( 'step' ) . calledOnce ) . to . be ( true ) ;
17
+ expect ( this . subject . _el . _leaflet_pos ) . to . be ( point ) ;
18
+ } ) ;
19
+
20
+ it ( 'stops transition if a position returned' , function ( ) {
21
+ sinon . stub ( this . subject , '_onTransitionEnd' ) ;
22
+ sinon . stub ( this . subject , '_getPos' ) . returns ( undefined ) ;
23
+ this . subject . _onStep ( ) ;
24
+ expect ( this . subject . _onTransitionEnd . calledOnce ) . to . be ( true ) ;
25
+ } ) ;
26
+ } ) ;
27
+ } ) ;
Original file line number Diff line number Diff line change @@ -39,9 +39,14 @@ L.PosAnimation = L.Class.extend({
39
39
} ,
40
40
41
41
_onStep : function ( ) {
42
+ var stepPos = this . _getPos ( ) ;
43
+ if ( ! stepPos ) {
44
+ this . _onTransitionEnd ( ) ;
45
+ return ;
46
+ }
42
47
// jshint camelcase: false
43
48
// make L.DomUtil.getPosition return intermediate position value during animation
44
- this . _el . _leaflet_pos = this . _getPos ( ) ;
49
+ this . _el . _leaflet_pos = stepPos ;
45
50
46
51
this . fire ( 'step' ) ;
47
52
} ,
@@ -58,8 +63,9 @@ L.PosAnimation = L.Class.extend({
58
63
59
64
if ( L . Browser . any3d ) {
60
65
matches = style [ L . DomUtil . TRANSFORM ] . match ( this . _transformRe ) ;
61
- left = matches ? parseFloat ( matches [ 1 ] ) : 0 ;
62
- top = matches ? parseFloat ( matches [ 2 ] ) : 0 ;
66
+ if ( ! matches ) { return ; }
67
+ left = parseFloat ( matches [ 1 ] ) ;
68
+ top = parseFloat ( matches [ 2 ] ) ;
63
69
} else {
64
70
left = parseFloat ( style . left ) ;
65
71
top = parseFloat ( style . top ) ;
You can’t perform that action at this time.
0 commit comments