From b52b515282281d5f718212015c18fce91d0ffbf6 Mon Sep 17 00:00:00 2001 From: Yann Randin Date: Tue, 13 Jul 2021 12:31:35 +0200 Subject: [PATCH] use-element-for-api-player-init Use constructor with HTMLElement instead of the one with id --- index.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 52f457c..37b6eb9 100644 --- a/index.js +++ b/index.js @@ -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, @@ -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 @@ -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,