Skip to content

Commit 2d0618e

Browse files
authored
Merge pull request #688 from kchar601/master
lecture-player video transplant problem
2 parents 2c2fed6 + 640a879 commit 2d0618e

File tree

3 files changed

+49
-43
lines changed

3 files changed

+49
-43
lines changed

elements/video-player/demo/lecture-player.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
</head>
1616
<body>
1717

18+
<lecture-player>
1819
<video-player source="https://www.youtube.com/embed/-MTSQjw5DrM?si=TDthCE9uHS07JxO0"></video-player>
1920

2021
<div class="pageContent">
21-
<h2 id="1">Start of Video</h2>
22+
<h2 id="title1">Start of Video</h2>
2223
<p>Lorem ipsum dolor sit amet, consectetur
23-
<lecture-anchor data-primary="11" data-accent="1" timestamp=422 target="video-player" associatedID="1">Install Express</lecture-anchor>
24+
<lecture-anchor data-primary="11" data-accent="1" timestamp=422 target="video-player" associatedID="title1">Install Express</lecture-anchor>
2425
adipiscing elit, sed do eiusmod tempor ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
2526
<h2 id="section2">Next part in the video</h2>
2627
<p>Lorem ipsum dolor sit amet consectetur adipiscing. Diam ut venenatis tellus in metus. Et netus et malesuada fames ac turpis egestas. Commodo quis imperdiet massa tincidunt nunc. Pulvinar etiam non quam lacus suspendisse faucibus interdum posuere lorem. <lecture-anchor timestamp=213 icon="image:palette" data-primary="20" data-accent="2" target="video-player" associatedID="section2">Index JS</lecture-anchor> enim facilisis gravida neque convallis. Amet volutpat consequat mauris nunc congue nisi vitae suscipit. Turpis nunc eget lorem dolor sed. Mattis enim ut tellus elementum sagittis vitae et leo. Lacus sed viverra tellus in hac habitasse platea. Luctus venenatis lectus magna fringilla. A diam sollicitudin tempor id. Congue nisi vitae suscipit tellus mauris. Et malesuada fames ac turpis egestas sed.</p>
@@ -34,8 +35,9 @@ <h2 id="heading3">Third Section of the video</h2>
3435
The Great White shark can grow to be 15 ft to more than 20 ft in length and weigh 2.5 tons or more.
3536
</self-check>
3637
<h2 id="testSection">Test Section</h2>
37-
<lecture-anchor data-primary="11" data-accent="1" timestamp=12 target="video-player" associatedID="1">Extra 1</lecture-anchor>
38+
<lecture-anchor data-primary="11" data-accent="1" timestamp=12 target="video-player" associatedID="title1">Extra 1</lecture-anchor>
3839
<lecture-anchor data-primary="11" data-accent="1" timestamp=462 target="video-player" associatedID="section2">Extra 2</lecture-anchor>
3940
</div>
41+
</lecture-player>
4042
</body>
4143
</html>

elements/video-player/lib/lecture-anchor.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class LectureAnchor extends DDD {
99
static get properties() {
1010
return {
1111
icon: { type: String, reflect: true },
12-
timestamp: { type: Number, reflect: true },
12+
value: { type: Number, reflect: true },
1313
target: { type: String, reflect: true },
1414
associatedID : { type: String, reflect: true },
1515
};
@@ -18,7 +18,7 @@ class LectureAnchor extends DDD {
1818
constructor() {
1919
super();
2020
this.icon = "icons:flag";
21-
this.timestamp = 0;
21+
this.value = 0;
2222
this.jumbotronHeading = "";
2323
this.jumbotronContent = "";
2424
this.target = "video-player";
@@ -78,8 +78,8 @@ class LectureAnchor extends DDD {
7878
case "lecture-player":
7979
case "video-player":
8080
case "audio-player":
81-
if (this.timestamp) {
82-
node.seek(parseInt(this.timestamp));
81+
if (this.value) {
82+
node.seek(parseInt(this.value));
8383
} else {
8484
node.play();
8585
}
@@ -113,8 +113,8 @@ class LectureAnchor extends DDD {
113113
return "video-player-flag";
114114
}
115115

116-
static get timestamp() {
117-
return this.timestamp;
116+
static get value() {
117+
return this.value;
118118
}
119119

120120
static get jumbotronHeading() {

elements/video-player/lib/lecture-player.js

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ class LecturePlayer extends DDDSuper(LitElement) {
3636
this.associatedNodes ={};
3737

3838
window.onload = () => {
39-
const flags = document.querySelectorAll("lecture-anchor");
39+
const flags = this.querySelectorAll("lecture-anchor");
4040
flags.forEach((flag) => {
4141
console.log(flag.associatedID);
42-
this.associatedNodes[flag.timestamp] = flag.associatedID;
42+
this.associatedNodes[flag.value] = flag.associatedID;
4343
});
4444
console.log(this.associatedNodes);
4545
for (const [key, value] of Object.entries(this.associatedNodes)) {
4646
console.log(`${key}: ${value}`);
4747
}
4848
}
49+
50+
this.videoPlayer = this.querySelector("video-player").outerHTML;
4951
}
5052

5153
static get properties() {
@@ -60,12 +62,12 @@ class LecturePlayer extends DDDSuper(LitElement) {
6062
super.updated(changedProperties);
6163
changedProperties.forEach((oldValue, propName) => {
6264
if (propName === "activeIndex") {
63-
if (!document.querySelector("video-player").playing) {
65+
if (!this.querySelector("video-player").playing) {
6466
this.play();
6567
}
6668
console.log("activeIndex changed to: ", this.activeIndex);
67-
console.log(document.querySelector("#" + this.activeIndex));
68-
this.seek(document.querySelector("#" + this.activeIndex).timestamp);
69+
console.log(this.querySelector("#" + this.activeIndex));
70+
this.seek(this.querySelector("#" + this.activeIndex).value);
6971
this.updateJumbotron();
7072
this.updatePlaylist();
7173
this.checkDisabledButtons();
@@ -74,12 +76,12 @@ class LecturePlayer extends DDDSuper(LitElement) {
7476
}
7577

7678
scan() {
77-
const lectureAnchors = document.querySelectorAll("lecture-anchor");
79+
const lectureAnchors = this.querySelectorAll("lecture-anchor");
7880
console.log(lectureAnchors);
7981
const anchorsArray = Array.from(lectureAnchors);
8082
anchorsArray.sort((a, b) => {
81-
const timeA = parseInt(a.getAttribute("timestamp"), 10);
82-
const timeB = parseInt(b.getAttribute("timestamp"), 10);
83+
const timeA = parseInt(a.getAttribute("value"), 10);
84+
const timeB = parseInt(b.getAttribute("value"), 10);
8385
return timeA - timeB;
8486
});
8587
anchorsArray.forEach((anchor, index) => {
@@ -93,8 +95,8 @@ class LecturePlayer extends DDDSuper(LitElement) {
9395

9496
setJumbotronAttributes() {
9597
console.log("setJumbotronAttributes");
96-
document.querySelectorAll("lecture-anchor").forEach((anchor) => {
97-
let header = document.getElementById(anchor.getAttribute("associatedID"));
98+
this.querySelectorAll("lecture-anchor").forEach((anchor) => {
99+
let header = this.querySelector(`#${anchor.getAttribute("associatedID")}`);
98100
anchor.setAttribute("jumbotronHeading", header.textContent);
99101
anchor.setAttribute("jumbotronContent", this.getNextSiblingHTML(header));
100102
// Scrub the ids from the lecture-anchor elements in the content
@@ -185,30 +187,30 @@ class LecturePlayer extends DDDSuper(LitElement) {
185187

186188
updatePlaylist() {
187189
console.log("updatePlaylist");
188-
const timestampList = document.querySelector(".timestampList");
189-
timestampList.innerHTML = "";
190+
const valueList = document.querySelector(".valueList");
191+
valueList.innerHTML = "";
190192
const listOfAnchorElements = this.getSortedAnchors();
191193
listOfAnchorElements.forEach((anchor) => {
192-
const timestampBtn = document.createElement("button");
193-
timestampBtn.classList.add("timestampBtn");
194-
timestampBtn.innerText = anchor.getAttribute("jumbotronHeading");
195-
timestampBtn.timestamp = anchor.getAttribute("timestamp");
196-
timestampBtn.addEventListener("click", () => {
194+
const valueBtn = document.createElement("button");
195+
valueBtn.classList.add("valueBtn");
196+
valueBtn.innerText = anchor.getAttribute("jumbotronHeading");
197+
valueBtn.value = anchor.getAttribute("value");
198+
valueBtn.addEventListener("click", () => {
197199
this.activeIndex = anchor.id;
198200
});
199201
if (anchor.id === this.activeIndex) {
200-
timestampBtn.classList.add("active");
202+
valueBtn.classList.add("active");
201203
}
202-
timestampList.appendChild(timestampBtn);
204+
valueList.appendChild(valueBtn);
203205
});
204-
document.querySelector(".timestampList").scrollTo({
205-
left: document.querySelector(".timestampBtn.active").offsetLeft - 125,
206+
document.querySelector(".valueList").scrollTo({
207+
left: document.querySelector(".valueBtn.active").offsetLeft - 125,
206208
behavior: "smooth",
207209
});
208210
}
209211

210212
getSortedAnchors() {
211-
// Returns an array of all the lecture-anchor elements sorted by timestamp, to assing their IDs in order
213+
// Returns an array of all the lecture-anchor elements sorted by value, to assing their IDs in order
212214
// May need to support the option for sorting by how the tags appear in the content order
213215
let anchors = [];
214216
let i = 1;
@@ -221,9 +223,9 @@ class LecturePlayer extends DDDSuper(LitElement) {
221223
return anchors;
222224
}
223225

224-
seek(timestamp) {
226+
seek(value) {
225227
console.log("seek");
226-
console.log(timestamp);
228+
console.log(value);
227229
console.log(
228230
document
229231
.querySelector("video-player")
@@ -237,7 +239,7 @@ class LecturePlayer extends DDDSuper(LitElement) {
237239
document
238240
.querySelector("video-player")
239241
.shadowRoot.querySelector("a11y-media-player")
240-
.seek(timestamp);
242+
.seek(value);
241243
}
242244
}
243245

@@ -336,7 +338,7 @@ class LecturePlayer extends DDDSuper(LitElement) {
336338
word-break: break-word;
337339
}
338340
339-
.timestampList {
341+
.valueList {
340342
display: flex; /* Use flexbox to layout items in a row */
341343
flex-wrap: nowrap; /* Prevent wrapping of items */
342344
border: var(--ddd-border-xs);
@@ -346,7 +348,7 @@ class LecturePlayer extends DDDSuper(LitElement) {
346348
overflow-y: hidden; /* Hide vertical overflow */
347349
}
348350
349-
.timestampBtn {
351+
.valueBtn {
350352
flex-shrink: 0; /* Prevent buttons from shrinking */
351353
background: white;
352354
border: none;
@@ -362,7 +364,7 @@ class LecturePlayer extends DDDSuper(LitElement) {
362364
font-family: var(--ddd-font-primary, sans-serif);
363365
}
364366
365-
.timestampBtn:not(:last-child){
367+
.valueBtn:not(:last-child){
366368
border-right: 1px solid black;
367369
}
368370
@@ -387,15 +389,15 @@ class LecturePlayer extends DDDSuper(LitElement) {
387389
width: calc(100% - 16px);
388390
}
389391
390-
.timestamp-navigation-button{
392+
.value-navigation-button{
391393
background: white;
392394
cursor: pointer;
393395
padding: 4px;
394396
height: fit-content;
395397
margin: auto;
396398
}
397399
398-
.timestampBtn.active{
400+
.valueBtn.active{
399401
background: #dfedf5;
400402
}
401403
@@ -430,16 +432,17 @@ class LecturePlayer extends DDDSuper(LitElement) {
430432
}
431433
</style>
432434
<div class="videoSection">
433-
<video-player source="${this.source}" source-type="${this.sourceType}"></video-player>
435+
${this.videoPlayer}
434436
<div class="jumbotron"></div>
435437
</div>
436438
<div class="playlist">
437-
<button class="timestamp-navigation-button" id="prevSlideBtn"><simple-icon-lite icon="lrn:arrow-left"></simple-icon-lite></button>
438-
<div class="timestampList">
439+
<button class="value-navigation-button" id="prevSlideBtn"><simple-icon-lite icon="lrn:arrow-left"></simple-icon-lite></button>
440+
<div class="valueList">
439441
</div>
440-
<button class="timestamp-navigation-button" id="nextSlideBtn"><simple-icon-lite icon="lrn:arrow-right"></simple-icon-lite></button>
442+
<button class="value-navigation-button" id="nextSlideBtn"><simple-icon-lite icon="lrn:arrow-right"></simple-icon-lite></button>
441443
</div>
442444
`;
445+
this.querySelector("video-player").setAttribute("hidden", true);
443446
const evnt = new CustomEvent("simple-modal-show", {
444447
bubbles: true,
445448
cancelable: true,
@@ -454,6 +457,7 @@ class LecturePlayer extends DDDSuper(LitElement) {
454457
render() {
455458
return html`
456459
<simple-cta id="lectureActivation" @click="${this.showModal}">Open Lecture Player</simple-cta>
460+
<slot></slot>
457461
`;
458462
}
459463
}

0 commit comments

Comments
 (0)