File tree 2 files changed +59
-0
lines changed
2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1
1
import qs from 'qs' ;
2
+ import ResizeObserver from './lib/ResizeObserver' ;
2
3
import controller from './lib/controller' ;
3
4
import log from './lib/log' ;
4
5
import './styles/vendor.styl' ;
@@ -63,6 +64,24 @@ import(`./widgets/${widget}`)
63
64
}
64
65
} , '*' ) ;
65
66
} ) ;
67
+
68
+ new ResizeObserver ( ( ) => {
69
+ // Use the postMessage API for inter-frame communication
70
+ window . parent . postMessage ( {
71
+ token : params . token ,
72
+ action : {
73
+ type : 'resize' ,
74
+ payload : {
75
+ clientHeight : document . body . clientHeight ,
76
+ clientWidth : document . body . clientWidth ,
77
+ offsetHeight : document . body . offsetHeight ,
78
+ offsetWidth : document . body . offsetWidth ,
79
+ scrollHeight : document . body . scrollHeight ,
80
+ scrollWidth : document . body . scrollWidth
81
+ }
82
+ }
83
+ } , '*' ) ;
84
+ } ) . observe ( document . body ) ;
66
85
} )
67
86
. catch ( err => {
68
87
log . error ( err ) ;
Original file line number Diff line number Diff line change
1
+ class ResizeObserver {
2
+ callback = null ;
3
+ observer = null ;
4
+
5
+ constructor ( callback ) {
6
+ if ( typeof callback === 'function' ) {
7
+ this . callback = callback ;
8
+ }
9
+ return this ;
10
+ }
11
+ observe ( target ) {
12
+ if ( this . observer ) {
13
+ this . observer . disconnect ( ) ;
14
+ this . observer = null ;
15
+ }
16
+
17
+ this . callback && this . callback ( ) ;
18
+
19
+ this . observer = new MutationObserver ( mutations => {
20
+ this . callback && this . callback ( ) ;
21
+ } ) ;
22
+
23
+ this . observer . observe ( target , {
24
+ attributes : true ,
25
+ attributeOldValue : false ,
26
+ characterData : true ,
27
+ characterDataOldValue : false ,
28
+ childList : true ,
29
+ subtree : true
30
+ } ) ;
31
+ }
32
+ disconnect ( ) {
33
+ if ( this . observer ) {
34
+ this . observer . disconnect ( ) ;
35
+ this . observer = null ;
36
+ }
37
+ }
38
+ }
39
+
40
+ export default ResizeObserver ;
You can’t perform that action at this time.
0 commit comments