分离includeFromEvent函数

This commit is contained in:
Harvey committed 2020-08-24 09:28:59 +08:00
1 parent d475f26dfb
commit dd1ae0f499
9 files changed
+42 -22

No files matched your search

+2 -2
View File
@@ -1,4 +1,4 @@
import { setStyles } from '../utils';
import { setStyles, includeFromEvent } from '../utils';
import Component from '../utils/component';
import playbackRate from './playbackRate';
import aspectRatio from './aspectRatio';
@@ -100,7 +100,7 @@ export default class Contextmenu extends Component {
});
proxy($player, 'click', (event) => {
if (event.composedPath && !event.composedPath().indexOf($contextmenu) > -1) {
if (!includeFromEvent(event, $contextmenu)) {
this.show = false;
}
});
+18 -8
View File
@@ -1,4 +1,14 @@
import { append, clamp, secondToTime, setStyle, getStyle, query, addClass, removeClass } from '../utils';
import {
append,
clamp,
secondToTime,
setStyle,
getStyle,
query,
addClass,
removeClass,
includeFromEvent,
} from '../utils';
export function getPosFromEvent(art, event) {
const {
@@ -15,7 +25,7 @@ export function getPosFromEvent(art, event) {
}
export default function progress(option) {
return art => {
return (art) => {
const {
option: { highlight, theme },
events: { proxy },
@@ -32,7 +42,7 @@ export default function progress(option) {
<div class="art-progress-tip art-tip"></div>
</div>
`,
mounted: $control => {
mounted: ($control) => {
let isDroging = false;
const $loaded = query('.art-progress-loaded', $control);
const $played = query('.art-progress-played', $control);
@@ -82,7 +92,7 @@ export default function progress(option) {
}
}
highlight.forEach(item => {
highlight.forEach((item) => {
const left = (clamp(item.time, 0, player.duration) / player.duration) * 100;
append(
$highlight,
@@ -104,9 +114,9 @@ export default function progress(option) {
setBar('played', 1);
});
proxy($control, 'mousemove', event => {
proxy($control, 'mousemove', (event) => {
setStyle($tip, 'display', 'block');
if (event.composedPath && event.composedPath().indexOf($highlight) > -1) {
if (includeFromEvent(event, $highlight)) {
showHighlight(event);
} else {
showTime(event);
@@ -117,7 +127,7 @@ export default function progress(option) {
setStyle($tip, 'display', 'none');
});
proxy($control, 'click', event => {
proxy($control, 'click', (event) => {
if (event.target !== $indicator) {
const { second, percentage } = getPosFromEvent(art, event);
setBar('played', percentage);
@@ -129,7 +139,7 @@ export default function progress(option) {
isDroging = true;
});
proxy(document, 'mousemove', event => {
proxy(document, 'mousemove', (event) => {
if (isDroging) {
const { second, percentage } = getPosFromEvent(art, event);
addClass($indicator, 'art-show-indicator');
+3 -1
View File
@@ -1,3 +1,5 @@
import { includeFromEvent } from '../utils';
export default function clickInit(art, events) {
const {
controls,
@@ -5,7 +7,7 @@ export default function clickInit(art, events) {
} = art;
events.proxy(document, ['click', 'contextmenu'], (event) => {
if (event.composedPath && event.composedPath().indexOf($player) > -1) {
if (includeFromEvent(event, $player)) {
art.isFocus = true;
art.emit('focus');
} else {
+4
View File
@@ -73,3 +73,7 @@ export function isInViewport(el) {
const horInView = rect.left <= windowWidth && rect.left + rect.width >= 0;
return vertInView && horInView;
}
export function includeFromEvent(event, target) {
return event.composedPath && event.composedPath().indexOf(target) > -1;
}