mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-28 02:01:20 -08:00
格式化
This commit is contained in:
1 parent
0454f785be
commit
203ad0d3a0
75 files changed
+3120
-2904
No files matched your search
@@ -1,11 +1,13 @@
|
||||
export default function clickInit(art, events) {
|
||||
const { refs: { $player } } = art;
|
||||
events.proxy(document, ['click', 'contextmenu'], event => {
|
||||
if (event.composedPath().indexOf($player) > -1) {
|
||||
art.isFocus = true;
|
||||
} else {
|
||||
art.isFocus = false;
|
||||
art.contextmenu.hide();
|
||||
}
|
||||
});
|
||||
const {
|
||||
refs: { $player },
|
||||
} = art;
|
||||
events.proxy(document, ['click', 'contextmenu'], event => {
|
||||
if (event.composedPath().indexOf($player) > -1) {
|
||||
art.isFocus = true;
|
||||
} else {
|
||||
art.isFocus = false;
|
||||
art.contextmenu.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
export default function doubleClickInit(art, events) {
|
||||
const { refs: { $video } } = art;
|
||||
events.proxy($video, 'dblclick', () => {
|
||||
art.player.fullscreenToggle();
|
||||
art.emit('dblclick');
|
||||
});
|
||||
const {
|
||||
refs: { $video },
|
||||
} = art;
|
||||
events.proxy($video, 'dblclick', () => {
|
||||
art.player.fullscreenToggle();
|
||||
art.emit('dblclick');
|
||||
});
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
export default function hoverInit(art, events) {
|
||||
const { refs: { $player } } = art;
|
||||
events.hover(
|
||||
$player,
|
||||
() => {
|
||||
$player.classList.add('artplayer-hover');
|
||||
art.emit('hoverenter');
|
||||
},
|
||||
() => {
|
||||
$player.classList.remove('artplayer-hover');
|
||||
art.emit('hoverleave');
|
||||
}
|
||||
);
|
||||
const {
|
||||
refs: { $player },
|
||||
} = art;
|
||||
events.hover(
|
||||
$player,
|
||||
() => {
|
||||
$player.classList.add('artplayer-hover');
|
||||
art.emit('hoverenter');
|
||||
},
|
||||
() => {
|
||||
$player.classList.remove('artplayer-hover');
|
||||
art.emit('hoverleave');
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -5,58 +5,60 @@ import resizeInit from './resizeInit';
|
||||
import doubleClickInit from './doubleClickInit';
|
||||
|
||||
export default class Events {
|
||||
constructor(art) {
|
||||
this.destroyEvents = [];
|
||||
this.proxy = this.proxy.bind(this);
|
||||
this.hover = this.hover.bind(this);
|
||||
this.loadImg = this.loadImg.bind(this);
|
||||
clickInit(art, this);
|
||||
hoverInit(art, this);
|
||||
mousemoveInit(art, this);
|
||||
resizeInit(art, this);
|
||||
doubleClickInit(art, this);
|
||||
}
|
||||
|
||||
proxy(target, name, callback, option = {}) {
|
||||
if (Array.isArray(name)) {
|
||||
name.forEach(item => this.proxy(target, item, callback, option));
|
||||
return;
|
||||
constructor(art) {
|
||||
this.destroyEvents = [];
|
||||
this.proxy = this.proxy.bind(this);
|
||||
this.hover = this.hover.bind(this);
|
||||
this.loadImg = this.loadImg.bind(this);
|
||||
clickInit(art, this);
|
||||
hoverInit(art, this);
|
||||
mousemoveInit(art, this);
|
||||
resizeInit(art, this);
|
||||
doubleClickInit(art, this);
|
||||
}
|
||||
|
||||
target.addEventListener(name, callback, option);
|
||||
this.destroyEvents.push(() => {
|
||||
target.removeEventListener(name, callback, option);
|
||||
});
|
||||
}
|
||||
proxy(target, name, callback, option = {}) {
|
||||
if (Array.isArray(name)) {
|
||||
name.forEach(item => this.proxy(target, item, callback, option));
|
||||
return;
|
||||
}
|
||||
|
||||
hover(target, mouseenter, mouseleave) {
|
||||
this.proxy(target, 'mouseenter', mouseenter);
|
||||
this.proxy(target, 'mouseleave', mouseleave);
|
||||
}
|
||||
target.addEventListener(name, callback, option);
|
||||
this.destroyEvents.push(() => {
|
||||
target.removeEventListener(name, callback, option);
|
||||
});
|
||||
}
|
||||
|
||||
loadImg(img) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let image;
|
||||
hover(target, mouseenter, mouseleave) {
|
||||
this.proxy(target, 'mouseenter', mouseenter);
|
||||
this.proxy(target, 'mouseleave', mouseleave);
|
||||
}
|
||||
|
||||
if (img instanceof HTMLImageElement) {
|
||||
image = img;
|
||||
} else if (typeof img === 'string') {
|
||||
image = new Image();
|
||||
image.src = img;
|
||||
} else {
|
||||
return reject(img);
|
||||
}
|
||||
loadImg(img) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let image;
|
||||
|
||||
if (image.complete) {
|
||||
return resolve(image);
|
||||
}
|
||||
if (img instanceof HTMLImageElement) {
|
||||
image = img;
|
||||
} else if (typeof img === 'string') {
|
||||
image = new Image();
|
||||
image.src = img;
|
||||
} else {
|
||||
return reject(img);
|
||||
}
|
||||
|
||||
this.proxy(image, 'load', () => resolve(image));
|
||||
this.proxy(image, 'error', () => reject(image));
|
||||
});
|
||||
}
|
||||
if (image.complete) {
|
||||
return resolve(image);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.destroyEvents.forEach(event => event());
|
||||
}
|
||||
this.proxy(image, 'load', () => resolve(image));
|
||||
this.proxy(image, 'error', () => reject(image));
|
||||
|
||||
return img;
|
||||
});
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.destroyEvents.forEach(event => event());
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,28 @@
|
||||
import { debounce } from '../utils';
|
||||
|
||||
export default function mousemoveInitInit(art, events) {
|
||||
const { refs: { $player } } = art;
|
||||
const {
|
||||
refs: { $player },
|
||||
} = art;
|
||||
|
||||
const autoHide = debounce(() => {
|
||||
$player.classList.add('artplayer-hide-cursor');
|
||||
$player.classList.remove('artplayer-hover');
|
||||
art.controls.hide();
|
||||
}, 5000);
|
||||
const autoHide = debounce(() => {
|
||||
$player.classList.add('artplayer-hide-cursor');
|
||||
$player.classList.remove('artplayer-hover');
|
||||
art.controls.hide();
|
||||
}, 5000);
|
||||
|
||||
art.on('hoverleave', () => {
|
||||
if (art.isPlaying) {
|
||||
autoHide();
|
||||
}
|
||||
});
|
||||
art.on('hoverleave', () => {
|
||||
if (art.isPlaying) {
|
||||
autoHide();
|
||||
}
|
||||
});
|
||||
|
||||
events.proxy($player, 'mousemove', () => {
|
||||
autoHide.clearTimeout();
|
||||
$player.classList.remove('artplayer-hide-cursor');
|
||||
art.controls.show();
|
||||
if (!art.player.pipState && art.isPlaying) {
|
||||
autoHide();
|
||||
}
|
||||
});
|
||||
events.proxy($player, 'mousemove', () => {
|
||||
autoHide.clearTimeout();
|
||||
$player.classList.remove('artplayer-hide-cursor');
|
||||
art.controls.show();
|
||||
if (!art.player.pipState && art.isPlaying) {
|
||||
autoHide();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,27 +1,26 @@
|
||||
import { sleep } from '../utils';
|
||||
import { ResizeObserver } from 'resize-observer';
|
||||
import { sleep } from '../utils';
|
||||
|
||||
export default function resizeInit(art, events) {
|
||||
const { option, refs: { $player } } = art;
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
sleep().then(() => {
|
||||
if (option.autoSize) {
|
||||
if (
|
||||
!art.player.fullscreenState &&
|
||||
!art.player.fullscreenWebState &&
|
||||
!art.player.pipState
|
||||
) {
|
||||
art.player.autoSize();
|
||||
} else {
|
||||
art.player.autoSizeRemove();
|
||||
}
|
||||
}
|
||||
art.player.aspectRatioReset();
|
||||
art.emit('resize', $player);
|
||||
const {
|
||||
option,
|
||||
refs: { $player },
|
||||
} = art;
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
sleep().then(() => {
|
||||
if (option.autoSize) {
|
||||
if (!art.player.fullscreenState && !art.player.fullscreenWebState && !art.player.pipState) {
|
||||
art.player.autoSize();
|
||||
} else {
|
||||
art.player.autoSizeRemove();
|
||||
}
|
||||
}
|
||||
art.player.aspectRatioReset();
|
||||
art.emit('resize', $player);
|
||||
});
|
||||
});
|
||||
resizeObserver.observe($player);
|
||||
events.destroyEvents.push(() => {
|
||||
resizeObserver.unobserve($player);
|
||||
});
|
||||
});
|
||||
resizeObserver.observe($player);
|
||||
events.destroyEvents.push(() => {
|
||||
resizeObserver.unobserve($player);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user