Skip to content

Commit

Permalink
fix destroy container inner dom not remove bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bosscheng committed Jul 18, 2023
1 parent de10026 commit 0f70497
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
Binary file modified demo/public/dist.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/jessibuca.js

Large diffs are not rendered by default.

45 changes: 38 additions & 7 deletions src/control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import property from './property';
import events from './events';
import './style.scss'
import hotkey from "./hotkey";
import {removeElement} from "../utils";

export default class Control {
constructor(player) {
Expand All @@ -20,21 +21,51 @@ export default class Control {

destroy() {
if (this.$poster) {
this.player.$container.removeChild(this.$poster);
const result = removeElement(this.$poster);
if(!result){
const $poster = this.player.$container.querySelector('.jessibuca-poster');
if ($poster && this.player.$container) {
this.player.$container.removeChild($poster);
}
}
}
if (this.$loading) {
this.player.$container.removeChild(this.$loading);
const result = removeElement(this.$loading)
if (!result) {
const $loading = this.player.$container.querySelector('.jessibuca-loading');
if ($loading && this.player.$container) {
this.player.$container.removeChild($loading);
}
}
}
if (this.$controls) {
this.player.$container.removeChild(this.$controls);
const result = removeElement(this.$controls)
if (!result) {
const $controls = this.player.$container.querySelector('.jessibuca-controls');
if ($controls && this.player.$container) {
this.player.$container.removeChild($controls);
}
}
}

if(this.$recording){
this.player.$container.removeChild(this.$recording);
if (this.$recording) {
const result = removeElement(this.$recording)
if (!result) {
const $recording = this.player.$container.querySelector('.jessibuca-recording');
if ($recording && this.player.$container) {
this.player.$container.removeChild($recording);
}
}
}

if(this.$playBig){
this.player.$container.removeChild(this.$playBig);
if (this.$playBig) {
const result = removeElement(this.$playBig)
if (!result) {
const $playBig = this.player.$container.querySelector('.jessibuca-play-big');
if ($playBig && this.player.$container) {
this.player.$container.removeChild($playBig);
}
}
}

this.player.debug.log('control', 'destroy');
Expand Down
12 changes: 12 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,15 @@ export function closeVideoFrame(videoFrame) {
videoFrame.destroy()
}
}


export function removeElement(element) {
let result = false;
if (element) {
if (element.parentNode) {
element.parentNode.removeChild(element);
result = true;
}
}
return result;
}

1 comment on commit 0f70497

@vercel
Copy link

@vercel vercel bot commented on 0f70497 Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.