@@ -28,3 +28,35 @@ if (!IS_PRODUCTION) {
28
28
Error . stackTraceLimit = Infinity ;
29
29
require ( 'zone.js/dist/long-stack-trace-zone' ) ;
30
30
}
31
+
32
+ interface Element {
33
+ scrollIntoViewIfNeeded ( centerIfNeeded ?: boolean ) : void ;
34
+ } ;
35
+
36
+ if ( ! ( < any > Element ) . prototype . scrollIntoViewIfNeeded ) {
37
+ ( < any > Element ) . prototype . scrollIntoViewIfNeeded = function ( centerIfNeeded ) {
38
+ centerIfNeeded = arguments . length === 0 ? true : ! ! centerIfNeeded ;
39
+
40
+ var parent = this . parentNode ,
41
+ parentComputedStyle = window . getComputedStyle ( parent , null ) ,
42
+ parentBorderTopWidth = parseInt ( parentComputedStyle . getPropertyValue ( 'border-top-width' ) ) ,
43
+ parentBorderLeftWidth = parseInt ( parentComputedStyle . getPropertyValue ( 'border-left-width' ) ) ,
44
+ overTop = this . offsetTop - parent . offsetTop < parent . scrollTop ,
45
+ overBottom = ( this . offsetTop - parent . offsetTop + this . clientHeight - parentBorderTopWidth ) > ( parent . scrollTop + parent . clientHeight ) ,
46
+ overLeft = this . offsetLeft - parent . offsetLeft < parent . scrollLeft ,
47
+ overRight = ( this . offsetLeft - parent . offsetLeft + this . clientWidth - parentBorderLeftWidth ) > ( parent . scrollLeft + parent . clientWidth ) ,
48
+ alignWithTop = overTop && ! overBottom ;
49
+
50
+ if ( ( overTop || overBottom ) && centerIfNeeded ) {
51
+ parent . scrollTop = this . offsetTop - parent . offsetTop - parent . clientHeight / 2 - parentBorderTopWidth + this . clientHeight / 2 ;
52
+ }
53
+
54
+ if ( ( overLeft || overRight ) && centerIfNeeded ) {
55
+ parent . scrollLeft = this . offsetLeft - parent . offsetLeft - parent . clientWidth / 2 - parentBorderLeftWidth + this . clientWidth / 2 ;
56
+ }
57
+
58
+ if ( ( overTop || overBottom || overLeft || overRight ) && ! centerIfNeeded ) {
59
+ this . scrollIntoView ( alignWithTop ) ;
60
+ }
61
+ } ;
62
+ }
0 commit comments