mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 13:51:20 -08:00
移除两个依赖
This commit is contained in:
1 parent
dc8337dc65
commit
98c600c244
10 files changed
+257
-368
No files matched your search
@@ -1,24 +1,41 @@
|
||||
import { ResizeObserver } from 'resize-observer';
|
||||
import { throttle } from '../utils';
|
||||
|
||||
export default function resizeInit(art, events) {
|
||||
const {
|
||||
option,
|
||||
player,
|
||||
template: { $player },
|
||||
} = art;
|
||||
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
if (option.autoSize) {
|
||||
if (!art.player.fullscreen && !art.player.fullscreenWeb && !art.player.pip) {
|
||||
art.player.autoSize = true;
|
||||
} else {
|
||||
art.player.autoSize = false;
|
||||
|
||||
const object = document.createElement('object');
|
||||
object.setAttribute('aria-hidden', 'true');
|
||||
object.setAttribute('tabindex', -1);
|
||||
object.type = 'text/html';
|
||||
object.data = 'about:blank';
|
||||
let playerWidth = player.width;
|
||||
let playerHeight = player.height;
|
||||
const resizeFn = throttle(() => {
|
||||
if (player.width !== playerWidth || player.height !== playerHeight) {
|
||||
playerWidth = player.width;
|
||||
playerHeight = player.height;
|
||||
if (option.autoSize) {
|
||||
if (!art.player.fullscreen && !art.player.fullscreenWeb && !art.player.pip) {
|
||||
art.player.autoSize = true;
|
||||
} else {
|
||||
art.player.autoSize = false;
|
||||
}
|
||||
}
|
||||
art.player.aspectRatioReset = true;
|
||||
art.emit('resize', {
|
||||
width: player.width,
|
||||
height: player.height,
|
||||
});
|
||||
}
|
||||
art.player.aspectRatioReset = true;
|
||||
art.emit('resize', $player);
|
||||
});
|
||||
resizeObserver.observe($player);
|
||||
events.destroyEvents.push(() => {
|
||||
resizeObserver.unobserve($player);
|
||||
}, 500);
|
||||
|
||||
events.proxy(object, 'load', () => {
|
||||
events.proxy(object.contentDocument.defaultView, 'resize', resizeFn);
|
||||
});
|
||||
|
||||
$player.appendChild(object);
|
||||
}
|
||||
Reference in new issue
Block a user