mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 22:01:20 -08:00
add Artplayer.LOG_VERSION
This commit is contained in:
1 parent
3179d1241e
commit
894a9db1d7
34 files changed
+182
-136
No files matched your search
@@ -4,5 +4,5 @@ export const isWechat = /MicroMessenger/i.test(userAgent);
|
||||
export const isIE = /MSIE|Trident/i.test(userAgent);
|
||||
export const isAndroid = /android/i.test(userAgent);
|
||||
export const isIOS = /iPad|iPhone|iPod/i.test(userAgent) && !window.MSStream;
|
||||
export const isIOS13 = isIOS || (userAgent.includes('Macintosh') && navigator.maxTouchPoints >= 1);
|
||||
export const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent) || isIOS13;
|
||||
export const isIOS13 = isIOS ?? (userAgent.includes('Macintosh') && navigator.maxTouchPoints >= 1);
|
||||
export const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent) ?? isIOS13;
|
||||
@@ -46,10 +46,10 @@ export default class Component {
|
||||
|
||||
add(getOption) {
|
||||
const option = typeof getOption === 'function' ? getOption(this.art) : getOption;
|
||||
option.html = option.html || '';
|
||||
option.html = option.html ?? '';
|
||||
validator(option, ComponentOption);
|
||||
if (!this.$parent || !this.name || option.disable) return;
|
||||
const name = option.name || `${this.name}${this.id}`;
|
||||
if (!this.$parent ?? !this.name ?? option.disable) return;
|
||||
const name = option.name ?? `${this.name}${this.id}`;
|
||||
const item = this.cache.get(name);
|
||||
errorHandle(!item, `Can't add an existing [${name}] to the [${this.name}]`);
|
||||
|
||||
@@ -59,7 +59,7 @@ export default class Component {
|
||||
addClass($ref, `art-${this.name}-${name}`);
|
||||
|
||||
const childs = Array.from(this.$parent.children);
|
||||
$ref.dataset.index = option.index || this.id;
|
||||
$ref.dataset.index = option.index ?? this.id;
|
||||
const nextChild = childs.find((item) => Number(item.dataset.index) >= Number($ref.dataset.index));
|
||||
if (nextChild) {
|
||||
nextChild.insertAdjacentElement('beforebegin', $ref);
|
||||
@@ -135,12 +135,12 @@ export default class Component {
|
||||
hover($ref, setLeft);
|
||||
|
||||
const destroyEvent = proxy($list, 'click', async (event) => {
|
||||
const path = event.composedPath() || [];
|
||||
const path = event.composedPath() ?? [];
|
||||
const $item = path.find((item) => hasClass(item, 'art-selector-item'));
|
||||
if (!$item) return;
|
||||
inverseClass($item, 'art-current');
|
||||
const index = Number($item.dataset.index);
|
||||
const find = option.selector[index] || {};
|
||||
const find = option.selector[index] ?? {};
|
||||
$value.innerText = $item.innerText;
|
||||
if (option.onSelect) {
|
||||
const result = await option.onSelect.call(this.art, find, $item, event);
|
||||
|
||||
@@ -26,7 +26,7 @@ export function append(parent, child) {
|
||||
} else {
|
||||
parent.insertAdjacentHTML('beforeend', String(child));
|
||||
}
|
||||
return parent.lastElementChild || parent.lastChild;
|
||||
return parent.lastElementChild ?? parent.lastChild;
|
||||
}
|
||||
|
||||
export function remove(child) {
|
||||
@@ -68,8 +68,8 @@ export function tooltip(target, msg, pos = 'top') {
|
||||
|
||||
export function isInViewport(el, offset = 0) {
|
||||
const rect = el.getBoundingClientRect();
|
||||
const windowHeight = window.innerHeight || document.documentElement.clientHeight;
|
||||
const windowWidth = window.innerWidth || document.documentElement.clientWidth;
|
||||
const windowHeight = window.innerHeight ?? document.documentElement.clientHeight;
|
||||
const windowWidth = window.innerWidth ?? document.documentElement.clientWidth;
|
||||
const vertInView = rect.top - offset <= windowHeight && rect.top + rect.height + offset >= 0;
|
||||
const horInView = rect.left - offset <= windowWidth + offset && rect.left + rect.width + offset >= 0;
|
||||
return vertInView && horInView;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export default class Emitter {
|
||||
on(name, fn, ctx) {
|
||||
const e = this.e || (this.e = {});
|
||||
(e[name] || (e[name] = [])).push({ fn, ctx });
|
||||
const e = this.e ?? (this.e = {});
|
||||
(e[name] ?? (e[name] = [])).push({ fn, ctx });
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export default class Emitter {
|
||||
}
|
||||
|
||||
emit(name, ...data) {
|
||||
const evtArr = ((this.e || (this.e = {}))[name] || []).slice();
|
||||
const evtArr = ((this.e ?? (this.e = {}))[name] ?? []).slice();
|
||||
for (let i = 0; i < evtArr.length; i += 1) {
|
||||
evtArr[i].fn.apply(evtArr[i].ctx, data);
|
||||
}
|
||||
@@ -24,7 +24,7 @@ export default class Emitter {
|
||||
}
|
||||
|
||||
off(name, callback) {
|
||||
const e = this.e || (this.e = {});
|
||||
const e = this.e ?? (this.e = {});
|
||||
const evts = e[name];
|
||||
const liveEvents = [];
|
||||
if (evts && callback) {
|
||||
|
||||
@@ -2,7 +2,7 @@ export class ArtPlayerError extends Error {
|
||||
constructor(message, context) {
|
||||
super(message);
|
||||
if (typeof Error.captureStackTrace === 'function') {
|
||||
Error.captureStackTrace(this, context || this.constructor);
|
||||
Error.captureStackTrace(this, context ?? this.constructor);
|
||||
}
|
||||
this.name = 'ArtPlayerError';
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ export function isStringOrNumber(val) {
|
||||
}
|
||||
|
||||
export function secondToTime(second) {
|
||||
if (!second) return '00:00';
|
||||
const add0 = (num) => (num < 10 ? `0${num}` : String(num));
|
||||
const hour = Math.floor(second / 3600);
|
||||
const min = Math.floor((second - hour * 3600) / 60);
|
||||
@@ -28,6 +29,6 @@ export function escape(str) {
|
||||
'>': '>',
|
||||
"'": ''',
|
||||
'"': '"',
|
||||
}[tag] || tag),
|
||||
}[tag] ?? tag),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user