Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use-element-for-api-player-init Use constructor with HTMLElement inst… #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 3 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,10 @@ class YouTubePlayer extends EventEmitter {
constructor (element, opts) {
super()

const elem = typeof element === 'string'
this._elem = typeof element === 'string'
? document.querySelector(element)
: element

if (elem.id) {
this._id = elem.id // use existing element id
} else {
this._id = elem.id = 'ytplayer-' + Math.random().toString(16).slice(2, 8)
}

this._opts = Object.assign({
width: 640,
height: 360,
Expand Down Expand Up @@ -230,7 +224,7 @@ class YouTubePlayer extends EventEmitter {

this.videoId = null

this._id = null
this._elem = null
this._opts = null
this._api = null
this._player = null
Expand Down Expand Up @@ -301,7 +295,7 @@ class YouTubePlayer extends EventEmitter {

const opts = this._opts

this._player = new this._api.Player(this._id, {
this._player = new this._api.Player(this._elem, {
width: opts.width,
height: opts.height,
videoId: videoId,
Expand Down