Skip to content

Commit

Permalink
插件机制
Browse files Browse the repository at this point in the history
  • Loading branch information
yisar committed Jul 15, 2024
1 parent a1d7cd0 commit 6ad7578
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
28 changes: 11 additions & 17 deletions docs/eplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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')
}
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 6ad7578

Please sign in to comment.