File tree 1 file changed +20
-15
lines changed
src/features/auto-resize-grid/js
1 file changed +20
-15
lines changed Original file line number Diff line number Diff line change 19
19
require : 'uiGrid' ,
20
20
scope : false ,
21
21
link : function ( $scope , $elm , $attrs , uiGridCtrl ) {
22
- var timeout = null ;
22
+ var elementWidth ,
23
+ elementHeight ;
23
24
24
- var debounce = function ( width , height ) {
25
- if ( timeout !== null ) {
26
- clearTimeout ( timeout ) ;
27
- }
28
- timeout = setTimeout ( function ( ) {
29
- uiGridCtrl . grid . gridWidth = width ;
30
- uiGridCtrl . grid . gridHeight = height ;
31
- uiGridCtrl . grid . refresh ( ) ;
32
- timeout = null ;
33
- } , 400 ) ;
34
- } ;
25
+ var updateWidth = gridUtil . throttle ( function ( ) {
26
+ elementWidth = gridUtil . elementWidth ( $elm ) ;
27
+ } , 200 ) ;
28
+
29
+ var updateHeight = gridUtil . throttle ( function ( ) {
30
+ elementHeight = gridUtil . elementHeight ( $elm ) ;
31
+ } , 200 ) ;
32
+
33
+ var refresh = gridUtil . throttle ( function ( width , height ) {
34
+ uiGridCtrl . grid . gridWidth = width ;
35
+ uiGridCtrl . grid . gridHeight = height ;
36
+ uiGridCtrl . grid . refresh ( ) ;
37
+ } , 300 ) ;
35
38
36
39
$scope . $watchGroup ( [
37
40
function ( ) {
38
- return gridUtil . elementWidth ( $elm ) ;
41
+ updateWidth ( ) ;
42
+ return elementWidth ;
39
43
} ,
40
44
function ( ) {
41
- return gridUtil . elementHeight ( $elm ) ;
45
+ updateHeight ( ) ;
46
+ return elementHeight ;
42
47
}
43
48
] , function ( newValues , oldValues , scope ) {
44
49
if ( ! angular . equals ( newValues , oldValues ) ) {
45
- debounce ( newValues [ 0 ] , newValues [ 1 ] ) ;
50
+ refresh ( newValues [ 0 ] , newValues [ 1 ] ) ;
46
51
}
47
52
} ) ;
48
53
}
You can’t perform that action at this time.
0 commit comments