分离工具函数

This commit is contained in:
Harvey committed 2019-11-14 11:24:02 +08:00
1 parent 7a84c262da
commit 8ef582f714
22 files changed
+724 -687

No files matched your search

+4 -4
View File
@@ -1,4 +1,4 @@
import { setStyle } from '../utils';
import { setStyle, addClass, removeClass, hasClass } from '../utils';
export default function resizeMix(art, player) {
const {
@@ -7,7 +7,7 @@ export default function resizeMix(art, player) {
Object.defineProperty(player, 'autoSize', {
get() {
return $container.classList.contains('artplayer-auto-size');
return hasClass($container, 'artplayer-auto-size');
},
set(value) {
if (value) {
@@ -15,7 +15,7 @@ export default function resizeMix(art, player) {
const { width, height } = $container.getBoundingClientRect();
const videoRatio = videoWidth / videoHeight;
const containerRatio = width / height;
$container.classList.add('artplayer-auto-size');
addClass($container, 'artplayer-auto-size');
if (containerRatio > videoRatio) {
const percentage = ((height * videoRatio) / width) * 100;
setStyle($player, 'width', `${percentage}%`);
@@ -27,7 +27,7 @@ export default function resizeMix(art, player) {
}
art.emit('autoSizeChange');
} else {
$container.classList.remove('artplayer-auto-size');
removeClass($container, 'artplayer-auto-size');
setStyle($player, 'width', null);
setStyle($player, 'height', null);
art.emit('autoSizeRemove');
+2 -2
View File
@@ -1,5 +1,5 @@
import config from '../config';
import { sleep } from '../utils';
import { sleep, addClass } from '../utils';
export default function eventInit(art, player) {
const {
@@ -69,7 +69,7 @@ export default function eventInit(art, player) {
} else {
art.loading.show = false;
art.controls.show = false;
$player.classList.add('artplayer-error');
addClass($player, 'artplayer-error');
sleep(1000).then(() => {
notice.show(i18n.get('Video load failed'), false);
art.destroy();
+2 -2
View File
@@ -116,7 +116,7 @@ function customPip(art, player) {
if (value) {
player.autoSize = false;
cacheStyle = $player.style.cssText;
$player.classList.add('artplayer-pip');
addClass($player, 'artplayer-pip');
const $body = document.body;
setStyle($player, 'top', `${$body.clientHeight - player.height - 50}px`);
setStyle($player, 'left', `${$body.clientWidth - player.width - 50}px`);
@@ -127,7 +127,7 @@ function customPip(art, player) {
art.emit('pipEnabled');
} else if (player.pip) {
$player.style.cssText = cacheStyle;
$player.classList.remove('artplayer-pip');
removeClass($player, 'artplayer-pip');
setStyle($player, 'top', null);
setStyle($player, 'left', null);
player.fullscreen = false;