From 6ad757816251fb5f082d6757ea83987a6a73a4a4 Mon Sep 17 00:00:00 2001 From: unknown <1533540012@qq.com> Date: Mon, 15 Jul 2024 14:49:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/eplayer.js | 28 +++++++++++----------------- package.json | 2 +- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/docs/eplayer.js b/docs/eplayer.js index c8d298e..46b383e 100644 --- a/docs/eplayer.js +++ b/docs/eplayer.js @@ -6,6 +6,7 @@ class Eplayer extends HTMLElement { this.type = this.getAttribute('type') this.live = JSON.parse(this.getAttribute('live')) this.danmaku = null + this.subs = [] this.init() this.stream() @@ -82,10 +83,12 @@ class Eplayer extends HTMLElement { this.video.play() this.danmaku.resume() this.$('.is-play').setAttribute('icon-id', 'pause') + this.emit('play') } else { this.video.pause() this.danmaku.pause() this.$('.is-play').setAttribute('icon-id', 'play') + this.emit('pause') } } @@ -479,16 +482,6 @@ class Eplayer extends HTMLElement { let dom = this.shadowRoot.querySelectorAll(key) this.doms[key] = dom.length > 1 ? [...dom] : dom[0] } - - - for (const name in Eplayer.plugins) { - const cb = Eplayer.plugins[name] - let node = document.createElement('li') - node.innerText = name - let panel = this.$('.panel') - panel.appendChild(node) - node.addEventListener('click', () => cb(this.shadowRoot)) - } } connectedCallback() { @@ -524,7 +517,6 @@ class Eplayer extends HTMLElement { }) this.delegate('keydown', this.keydown) this.delegate('mousemove', this.alow) - this.$('.eplayer').oncontextmenu = () => false } delegate(type, map) { @@ -546,14 +538,20 @@ class Eplayer extends HTMLElement { } } + emit (name) { + const fn = Eplayer.subs[name] + fn && fn.call(this, this.shadowRoot) + } + } -Eplayer.plugins = {} +Eplayer.subs = {} Eplayer.use = function (name, cb) { - this.plugins[name] = cb + this.subs[name] = cb } + function getTimeStr(time) { let h = Math.floor(time / 3600) let m = Math.floor((time % 3600) / 60) @@ -574,8 +572,4 @@ function isFullScreen() { document.head.appendChild(link) })() -Eplayer.use('github源码', (ep) => { - window.location.href = 'https://github.com/132yse/eplayer' -}) - customElements.define('e-player', Eplayer) diff --git a/package.json b/package.json index 606baa8..34df388 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eplayer", - "version": "1.6.5", + "version": "1.6.6", "description": "A web-components html5 video player facing future", "main": "./docs/eplayer.js", "module": "./docs/eplayer.js",