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

SMP-101 Custom layout and styles. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions src/components/MediaPlayer.Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ class MediaPLayer extends HTMLElement {
if (configData.toolbar) {
this.toolbar = configData.toolbar;
}

if (configData.css) {
this.style = configData.css;
}

if (configData.toolbarHTML) {
this.toolbarHTML = configData.toolbarHTML;
}
}

get data() {
Expand All @@ -44,6 +52,35 @@ class MediaPLayer extends HTMLElement {
return this._config.toolbar;
}

set style (newStyles) {
let style;
if (this.$('#mp-customstyles')) {
style = this.$('#mp-customstyles');
style.textContent = newStyles;
} else {
style = document.createElement('style');
style.id = 'mp-customstyles';
style.textContent = newStyles;
this.shadowRoot.appendChild(style);
}
}

set toolbarHTML (newLayout) {
if (newLayout) {
this._refs.toolbar.innerHTML = newLayout;
} else {
let template = document.createElement('template');
template.innerHTML = html;
this._refs.toolbar.innerHTML = template.content.querySelector('.toolbar').innerHTML;
// template.content;
// this._refs.toolbar.innerHTML = template.;
}
this._refs.toolbar_buttons = this.$('.toolbar__buttons');
this._refs.displayTime = this.$('.displayTime span');
this.updateDisplayTime();
this.initToolbar();
}

togglePlay(e) {
let svgEL = e.currentTarget.querySelector('svg');
if (this.isPlaying) {
Expand Down Expand Up @@ -250,9 +287,9 @@ class MediaPLayer extends HTMLElement {
displayTime: this.$('.displayTime span')
};

this._refs.video.addEventListener('canplay', () => {
this._refs.video.addEventListener('canplay', () => {
this.dispatchEvent(new CustomEvent('canplay', { detail: this, composed: true }));
this.updateDisplayTime();
this.updateDisplayTime();
});
this._refs.video.addEventListener('timeupdate', () => { this.updateDisplayTime(); });
}
Expand Down
4 changes: 4 additions & 0 deletions src/config.mediaplayer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const config = {
toolbarHTML: '',
css: '',

video: [
'https://www.w3schools.com/tags/mov_bbb.mp4',
'https://www.w3schools.com/tags/mov_bbb.ogg'
],

toolbar: {
id: 'toolbar',
className: 'mytoolbar',
Expand Down
26 changes: 26 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const root = document.getElementById('root');
const button = Component('button', 'Add Custom Volume Button', '', 'mycustombtn');
const buttonPosition = Component('button', 'Change Toolbar Position', '', 'mycustombtn');
const buttonVideo = Component('button', 'Change Video', '', 'mycustombtn');
const buttonLayout = Component('button', 'Change Layout and Styles', '', 'mycustombtn');


mediaPlayer.addEventListener('ready', function () {
Expand All @@ -24,11 +25,13 @@ rightSide.appendChild(eventLogConsole);
rightSide.appendChild(button);
rightSide.appendChild(buttonPosition);
rightSide.appendChild(buttonVideo);
rightSide.appendChild(buttonLayout);
root.appendChild(rightSide);

button.addEventListener('click', addButton);
buttonPosition.addEventListener('click', changePosition);
buttonVideo.addEventListener('click', changeVideo);
buttonLayout.addEventListener('click', changeLayoutAndStyles);

function changeVideo() {
mediaPlayer.autoplay = true;
Expand Down Expand Up @@ -65,6 +68,29 @@ function unmutePlayer() {
}
}

let flag = true;
function changeLayoutAndStyles() {
if (flag) {
mediaPlayer.toolbarHTML = `
<span class="displayTime"><span></span></span>
<div class="toolbar__buttons"></div>
`;
mediaPlayer.style = `
button {background:#ff000022;}
.toolbar {background:#ff000022;}
.displayTime {background:#ff000022; margin-left: 0; margin-right: auto;}
`;
buttonLayout.innerHTML = 'Reset Styles';
flag = false;
} else {
// Reset styles
buttonLayout.innerHTML = 'Change Layout and Styles';
mediaPlayer.toolbarHTML = '';
mediaPlayer.style = '';
flag = true;
}
}

mediaPlayer.data = config;

mediaPlayer.addEventListener('play', function () {
Expand Down