mirror of
				https://github.com/videojs/video.js.git
				synced 2025-10-31 00:08:01 +02:00 
			
		
		
		
	feat: playerresize event in all cases (#4864)
Use ResizeObserver when available for better and more performant resizing information, otherwise, fall back to a throttled resize event on an iframe that's the size of the player.
Allows a video.js user to disable this by setting resizeManager: false as an option since the component will not be initialized.
Add a debounce util.
This reverts #4800 (e0ed0b5) because we end up getting two playerresize events with the dimension methods now.
			
			
This commit is contained in:
		| @@ -18,6 +18,7 @@ The architecture of the Video.js player is centered around components. The `Play | ||||
| * [Specific Component Details](#specific-component-details) | ||||
|   * [Volume Panel](#volume-panel) | ||||
|   * [Text Track Settings](#text-track-settings) | ||||
|   * [Resize Manager](#resize-manager) | ||||
|  | ||||
| ## What is a Component? | ||||
|  | ||||
| @@ -312,7 +313,8 @@ Player | ||||
| │ ├── AudioTrackButton (hidden, unless there are relevant tracks) | ||||
| │ └── FullscreenToggle | ||||
| ├── ErrorDisplay (hidden, until there is an error) | ||||
| └── TextTrackSettings | ||||
| ├── TextTrackSettings | ||||
| └── ResizeManager (hidden) | ||||
| ``` | ||||
|  | ||||
| ## Specific Component Details | ||||
| @@ -338,3 +340,37 @@ let player = videojs('myplayer', { | ||||
| The text track settings component is only available when using emulated text tracks. | ||||
|  | ||||
| [api]: http://docs.videojs.com/Component.html | ||||
|  | ||||
| ### Resize Manager | ||||
|  | ||||
| This new component is in charge of triggering a `playerresize` event when the player size changed. | ||||
| It uses the ResizeObserver if available or a polyfill was provided. It has no element when using the ResizeObserver. | ||||
| If a ResizeObserver is not available, it will fallback to an iframe element and listen to its resize event via a debounced handler. | ||||
|  | ||||
| A ResizeObserver polyfill can be passed in like so: | ||||
|  | ||||
| ```js | ||||
| var player = videojs('myplayer', { | ||||
|   resizeManager: { | ||||
|     ResizeObserver: ResizeObserverPoylfill | ||||
|   } | ||||
| }); | ||||
| ``` | ||||
|  | ||||
| To force using the iframe fallback, pass in `null` as the `ResizeObserver`: | ||||
|  | ||||
| ```js | ||||
| var player = videojs('myplayer', { | ||||
|   resizeManager: { | ||||
|     ResizeObserver: null | ||||
|   } | ||||
| }); | ||||
| ``` | ||||
|  | ||||
| The ResizeManager can also just be disabled like so: | ||||
|  | ||||
| ```js | ||||
| var player = videojs('myplayer', { | ||||
|   resizeManager: false | ||||
| }); | ||||
| ``` | ||||
|   | ||||
		Reference in New Issue
	
	Block a user