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

feat: Player can be replaced with original el after dispose() #7722

Merged
merged 4 commits into from
May 18, 2022

Conversation

mister-ben
Copy link
Contributor

Description

Adds an option to replace player with a clone of the original element on dispose, which has been asked for several times.

Specific Changes proposed

  • Component accepts an options object. If provided, the component element will be replaced by the element provided at options.restoreEl.
  • Player passes a restoreEl to super.dispose() if provided as a player option
  • The videojs() constructor accepts a restoreEl option, which can be any element, or true in which case the element the player is initialised on is used.

Docs will need to be added at videojs.com/guides

Requirements Checklist

  • [*] Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
    • [*] Change has been verified in an actual browser (Chrome, Firefox, IE)
    • [*] Unit Tests updated or fixed
    • Docs/guides updated
    • Example created (starter template on JSBin)
  • Reviewed by Two Core Contributors

@codecov
Copy link

codecov bot commented Apr 11, 2022

Codecov Report

Merging #7722 (f2b27b6) into main (ae15270) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #7722      +/-   ##
==========================================
- Coverage   80.91%   80.91%   -0.01%     
==========================================
  Files         116      116              
  Lines        7457     7461       +4     
  Branches     1806     1810       +4     
==========================================
+ Hits         6034     6037       +3     
- Misses       1423     1424       +1     
Impacted Files Coverage Δ
src/js/component.js 93.97% <100.00%> (+0.02%) ⬆️
src/js/player.js 88.37% <100.00%> (ø)
src/js/video.js 93.85% <100.00%> (+0.10%) ⬆️
...rc/js/control-bar/progress-control/time-tooltip.js 82.05% <0.00%> (-2.57%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae15270...f2b27b6. Read the comment docs.

@misteroneill misteroneill added the minor This PR can be added to a minor release. It should not be added to a patch release. label Apr 14, 2022
Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

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

Confirmed with:

var d= document.createElement('div')
d.innerHTML = '<span style="color: red; font-size: 30px;">RESTORED</span>'
player.options_.restoreEl = d
player.dispose()

If you're able to add the other tests, that would be awesome, but I think it's probably ok as is.

src/js/video.js Outdated
@@ -162,6 +162,11 @@ function videojs(id, options, ready) {

options = options || {};

// Store a copy of the el before modification, if it is to be restored in destroy()
if (options.restoreEl === true) {
options.restoreEl = el.cloneNode(true);
Copy link
Member

Choose a reason for hiding this comment

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

Not a block: Clever to re-use the option to store the clone element, though, that might be a bit unexpected.

src/js/video.js Outdated
@@ -162,6 +162,11 @@ function videojs(id, options, ready) {

options = options || {};

// Store a copy of the el before modification, if it is to be restored in destroy()
if (options.restoreEl === true) {
options.restoreEl = el.cloneNode(true);
Copy link
Member

Choose a reason for hiding this comment

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

to get this line covered by tests, we probably want to add a test to https://github.com/videojs/video.js/blob/main/test/unit/video.test.js

Ideally, we'd have a test per embed type https://videojs.com/guides/embeds/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add some more tests. And sine this can be a minor I'll rebase onto main. Before starting I was thinking this would be more impactful a change than it is.

@mister-ben mister-ben changed the base branch from next to main April 20, 2022 16:39
@mister-ben mister-ben requested a review from gkatsev April 20, 2022 16:45
];

embeds.forEach(embed => {
const comparisonEl = document.createRange().createContextualFragment(embed.src).children[0];
Copy link
Member

Choose a reason for hiding this comment

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

huh, never seen createContextualFragment before


const player = videojs(embed.initSelector, {restoreEl: true});

assert.ok(comparisonEl.isEqualNode(player.options_.restoreEl), `${embed.type}: restoreEl option replaced by element`);
Copy link
Member

Choose a reason for hiding this comment

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

non-blocking: should we check that player.el() isn't equal to comparisonEl?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed minor This PR can be added to a minor release. It should not be added to a patch release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants