()
| 43 | } |
| 44 | |
| 45 | init() { |
| 46 | const floatBox = document.createElement('div'); |
| 47 | const container = document.createElement('div'); |
| 48 | // Use to remember which float container is shown. |
| 49 | container.classList.add(this.name); |
| 50 | container.classList.add('mu-float-container'); |
| 51 | floatBox.classList.add('mu-float-wrapper'); |
| 52 | |
| 53 | floatBox.appendChild(container); |
| 54 | document.body.appendChild(floatBox); |
| 55 | |
| 56 | this.floatBox = floatBox; |
| 57 | this.container = container; |
| 58 | |
| 59 | // Since the size of the container is not fixed and changes according to the change of content, |
| 60 | // the floatBox needs to set the size according to the container size |
| 61 | const resizeObserver = (this._resizeObserver = new ResizeObserver(() => { |
| 62 | // Use requestAnimationFrame to avoid "ResizeObserver loop completed" warning |
| 63 | requestAnimationFrame(() => { |
| 64 | const { offsetWidth, offsetHeight } = container; |
| 65 | |
| 66 | Object.assign(floatBox.style, { |
| 67 | width: `${offsetWidth}px`, |
| 68 | height: `${offsetHeight}px`, |
| 69 | }); |
| 70 | }); |
| 71 | })); |
| 72 | |
| 73 | resizeObserver.observe(container); |
| 74 | } |
| 75 | |
| 76 | listen() { |
| 77 | const { eventCenter, domNode } = this.muya; |
no test coverage detected