Skip to content

Commit

Permalink
Merge pull request #709 from vimeo/destroy-wrapper-div
Browse files Browse the repository at this point in the history
Remove wrapper div when destroying player
  • Loading branch information
rkrishnan8594 committed Apr 15, 2021
2 parents 3e240bb + b1f64ed commit 78e344c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 11 deletions.
16 changes: 14 additions & 2 deletions dist/player.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,13 @@ var Player = /*#__PURE__*/function () {
}

if (_this5.element && _this5.element.nodeName === 'IFRAME' && _this5.element.parentNode) {
_this5.element.parentNode.removeChild(_this5.element);
// If we've added an additional wrapper div, remove that from the DOM.
// If not, just remove the iframe element.
if (_this5._originalElement !== _this5.element.parentNode && _this5.element.parentNode.parentNode) {
_this5.element.parentNode.parentNode.removeChild(_this5.element.parentNode);
} else {
_this5.element.parentNode.removeChild(_this5.element);
}
} // If the clip is private there is a case where the element stays the
// div element. Destroy should reset the div and remove the iframe child.

Expand All @@ -1737,7 +1743,13 @@ var Player = /*#__PURE__*/function () {
var iframe = _this5.element.querySelector('iframe');

if (iframe && iframe.parentNode) {
iframe.parentNode.removeChild(iframe);
// If we've added an additional wrapper div, remove that from the DOM.
// If not, just remove the iframe element.
if (_this5._originalElement !== iframe.parentNode && iframe.parentNode.parentNode) {
iframe.parentNode.parentNode.removeChild(iframe.parentNode);
} else {
iframe.parentNode.removeChild(iframe);
}
}
}

Expand Down
16 changes: 14 additions & 2 deletions dist/player.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/player.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/player.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/player.min.js.map

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,13 @@ class Player {
}

if (this.element && this.element.nodeName === 'IFRAME' && this.element.parentNode) {
this.element.parentNode.removeChild(this.element);
// If we've added an additional wrapper div, remove that from the DOM.
// If not, just remove the iframe element.
if (this._originalElement !== this.element.parentNode && this.element.parentNode.parentNode) {
this.element.parentNode.parentNode.removeChild(this.element.parentNode);
} else {
this.element.parentNode.removeChild(this.element);
}
}

// If the clip is private there is a case where the element stays the
Expand All @@ -556,7 +562,13 @@ class Player {
this.element.removeAttribute('data-vimeo-initialized');
const iframe = this.element.querySelector('iframe');
if (iframe && iframe.parentNode) {
iframe.parentNode.removeChild(iframe);
// If we've added an additional wrapper div, remove that from the DOM.
// If not, just remove the iframe element.
if (this._originalElement !== iframe.parentNode && iframe.parentNode.parentNode) {
iframe.parentNode.parentNode.removeChild(iframe.parentNode);
} else {
iframe.parentNode.removeChild(iframe);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/embed-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test('getOEmbedData doesn’t operate on non-Vimeo urls', async (t) => {

test('getOEmbedData returns a json oembed response', async (t) => {
t.plan(2);
const result = await getOEmbedData('https://player.vimeo.com/video/18');
const result = await getOEmbedData('https://player.vimeo.com/video/336812660');
t.is(typeof result, 'object');
t.is(result.type, 'video');
});
Expand Down Expand Up @@ -65,7 +65,7 @@ test('createEmbed returns the iframe from a responsive embed', (t) => {
});

test('initializeEmbeds should create embeds', async (t) => {
const div = html`<div data-vimeo-id="18" data-vimeo-width="640" id="handstick"></div>`;
const div = html`<div data-vimeo-id="336812660" data-vimeo-width="640" id="handstick"></div>`;
document.body.appendChild(div);

await new Promise((resolve, reject) => {
Expand Down

0 comments on commit 78e344c

Please sign in to comment.