File tree Expand file tree Collapse file tree 1 file changed +20
-15
lines changed
src/features/auto-resize-grid/js Expand file tree Collapse file tree 1 file changed +20
-15
lines changed Original file line number Diff line number Diff line change 1919 require : 'uiGrid' ,
2020 scope : false ,
2121 link : function ( $scope , $elm , $attrs , uiGridCtrl ) {
22- var timeout = null ;
22+ var elementWidth ,
23+ elementHeight ;
2324
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 ) ;
3538
3639 $scope . $watchGroup ( [
3740 function ( ) {
38- return gridUtil . elementWidth ( $elm ) ;
41+ updateWidth ( ) ;
42+ return elementWidth ;
3943 } ,
4044 function ( ) {
41- return gridUtil . elementHeight ( $elm ) ;
45+ updateHeight ( ) ;
46+ return elementHeight ;
4247 }
4348 ] , function ( newValues , oldValues , scope ) {
4449 if ( ! angular . equals ( newValues , oldValues ) ) {
45- debounce ( newValues [ 0 ] , newValues [ 1 ] ) ;
50+ refresh ( newValues [ 0 ] , newValues [ 1 ] ) ;
4651 }
4752 } ) ;
4853 }
You can’t perform that action at this time.
0 commit comments