Skip to content

Commit

Permalink
Move to dom.js
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois committed Jun 19, 2023
1 parent 69f08d5 commit 77becf3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
32 changes: 1 addition & 31 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -3076,7 +3076,7 @@ class Player extends Component {
width: this.videoWidth(),
height: this.videoHeight()
}).then(pipWindow => {
this.copyStyleSheetsToWindow_(pipWindow);
Dom.copyStyleSheetsToWindow_(pipWindow);
this.el_.parentNode.insertBefore(pipContainer, this.el_);

pipWindow.document.body.append(this.el_);
Expand Down Expand Up @@ -3109,36 +3109,6 @@ class Player extends Component {
return Promise.reject('No PiP mode is available');
}

/**
* Copy document style sheets to another window.
*
* @param {Window} win
*
* @private
*/
copyStyleSheetsToWindow_(win) {
const allCSS = [...document.styleSheets]
.map((styleSheet) => {
try {
return [...styleSheet.cssRules].map((rule) => rule.cssText).join('');
} catch (e) {
const link = document.createElement('link');

link.rel = 'stylesheet';
link.type = styleSheet.type;
link.media = styleSheet.media;
link.href = styleSheet.href;
win.document.head.appendChild(link);
}
})
.filter(Boolean)
.join('\n');
const style = document.createElement('style');

style.textContent = allCSS;
win.document.head.appendChild(style);
}

/**
* Exit Picture-in-Picture mode.
*
Expand Down
30 changes: 30 additions & 0 deletions src/js/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,3 +857,33 @@ export function computedStyle(el, prop) {

return '';
}

/**
* Copy document style sheets to another window.
*
* @param {Window} win
* The window element you want to copy the document style style to.
*
*/
export function copyStyleSheetsToWindow_(win) {
const allCSS = [...document.styleSheets]
.map((styleSheet) => {
try {
return [...styleSheet.cssRules].map((rule) => rule.cssText).join('');
} catch (e) {
const link = document.createElement('link');

link.rel = 'stylesheet';
link.type = styleSheet.type;
link.media = styleSheet.media;
link.href = styleSheet.href;
win.document.head.appendChild(link);
}
})
.filter(Boolean)
.join('\n');
const style = document.createElement('style');

style.textContent = allCSS;
win.document.head.appendChild(style);
}

0 comments on commit 77becf3

Please sign in to comment.