Skip to content

Commit

Permalink
feat(xgplayer): add controlStyle config
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxin92 committed Oct 8, 2018
1 parent ec6c3c7 commit e5565f0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/xgplayer/browser/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/xgplayer/dist/index.js

Large diffs are not rendered by default.

49 changes: 38 additions & 11 deletions packages/xgplayer/src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,29 @@ class Player extends Proxy {
this.root.style.width = `${this.config.width}px`
this.root.style.height = `${this.config.height}px`
}
if (Player.plugins) {
let ignores = this.config.ignores
Object.keys(Player.plugins).forEach(name => {
let descriptor = Player.plugins[name]
if (!ignores.some(item => name === item)) {
if (['pc', 'tablet', 'mobile'].some(type => type === name)) {
if (name === sniffer.device) {
descriptor.call(this, this)
if (this.config.controlStyle && util.typeOf(this.config.controlStyle) === 'String') {
let self = this
fetch(self.config.controlStyle, {
method: 'GET',
headers: {
Accept: 'application/json'
}
}).then(function (res) {
if (res.ok) {
res.json().then(function (obj) {
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
self.config[prop] = obj[prop]
}
}
} else {
descriptor.call(this, this)
}
self.pluginsCall()
})
}
}).catch(function (err) {
console.log('Fetch错误:' + err)
})
} else {
this.pluginsCall()
}
this.ev.forEach((item) => {
let evName = Object.keys(item)[0]
Expand Down Expand Up @@ -228,6 +237,24 @@ class Player extends Proxy {
}
}

pluginsCall () {
if (Player.plugins) {
let ignores = this.config.ignores
Object.keys(Player.plugins).forEach(name => {
let descriptor = Player.plugins[name]
if (!ignores.some(item => name === item)) {
if (['pc', 'tablet', 'mobile'].some(type => type === name)) {
if (name === sniffer.device) {
descriptor.call(this, this)
}
} else {
descriptor.call(this, this)
}
}
})
}
}

onFocus () {
let player = this
util.removeClass(this.root, 'xgplayer-inactive')
Expand Down

0 comments on commit e5565f0

Please sign in to comment.