Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ac52a7f
Make CueSync a web component
nkdas91 Oct 28, 2024
ae2c83a
Remove an event listener before adding it, to avoid having duplicate …
nkdas91 Nov 7, 2024
f0115a5
Hide the settings menu when clicked outside
nkdas91 Dec 10, 2024
6021a55
Update CueSync behavior to reflect attribute changes
nkdas91 Dec 11, 2024
d4e8120
Refactor and remove redundancy
nkdas91 Dec 11, 2024
e7b734c
Rename audio, video and transcript files
nkdas91 Dec 16, 2024
5e71da5
Move CSS from cuesync.js to a separate cuesync.scss file for better s…
nkdas91 Dec 16, 2024
d9477d5
Move documentation related to v2 into a new folder
nkdas91 Jan 21, 2025
0c80cab
Add version selector
nkdas91 Apr 4, 2025
ead1ddb
Merge branch main into web-component
nkdas91 Apr 10, 2025
5c85a09
Merge branch 'main' into web-component
nkdas91 Apr 10, 2025
3a78a25
Update documentation
nkdas91 Apr 16, 2025
d399ee2
Call _renderComponent() before calling _requestRefresh() to remove un…
nkdas91 Apr 16, 2025
456cc49
Rename class names and css custom properties
nkdas91 Apr 17, 2025
00de59e
Update Specs page
nkdas91 Apr 17, 2025
5bb3c8c
Update examples doc
nkdas91 Apr 17, 2025
8ef766e
Update docs and add an image marking different parts of CueSync compo…
nkdas91 Apr 18, 2025
bc60da3
Add an image showing different parts of the cuesync element
nkdas91 Apr 21, 2025
81523f2
Update JS variables
nkdas91 Apr 21, 2025
94b0efb
Update dependencies
nkdas91 Apr 21, 2025
8e32387
Add links to framework examples
nkdas91 Apr 24, 2025
f2f88b1
Update description and cdn links
nkdas91 Apr 25, 2025
8732b51
Merge main into web-component
nkdas91 Apr 25, 2025
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
Prev Previous commit
Next Next commit
Call _renderComponent() before calling _requestRefresh() to remove un…
…wanted html elements

Recreate _handleTimeUpdate() everytime _addMediaEventListener() is called to avoid referencing to stale transcript lines.
  • Loading branch information
nkdas91 committed Apr 16, 2025
commit d399ee259b1fcb91b7815b0532bc60943c4ba4b4
56 changes: 29 additions & 27 deletions js/src/cuesync.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class CueSync extends HTMLElement {
if (['theme', 'layout', 'show-timestamp', 'auto-scroll'].includes(name)) {
this._applyAttributeChange(name)
} else {
this._renderComponent()
this._requestRefresh()
}
}
Expand Down Expand Up @@ -660,46 +661,47 @@ export default class CueSync extends HTMLElement {
}
}

if (!this._handleTimeUpdate) {
this._handleTimeUpdate = () => {
const { currentTime } = media
if (this._handleTimeUpdate) {
media.removeEventListener('timeupdate', this._handleTimeUpdate)
}

// Identify the new active cue index
let newActiveIndex = activeCueIndex
this._handleTimeUpdate = () => {
const { currentTime } = media

for (let i = 0; i < cues.length; i++) {
const { startTime, endTime } = cues[i]
if (currentTime >= startTime && (i === cues.length - 1 || currentTime < endTime)) {
newActiveIndex = i
break
}
// Identify the new active cue index
let newActiveIndex = activeCueIndex

for (let i = 0; i < cues.length; i++) {
const { startTime, endTime } = cues[i]
if (currentTime >= startTime && (i === cues.length - 1 || currentTime < endTime)) {
newActiveIndex = i
break
}
}

// Update only if there's a change in the active cue
if (newActiveIndex !== activeCueIndex) {
if (activeCueIndex >= 0) {
updateActiveLine(activeCueIndex, false)
}
// Update only if there's a change in the active cue
if (newActiveIndex !== activeCueIndex) {
if (activeCueIndex >= 0) {
updateActiveLine(activeCueIndex, false)
}

activeCueIndex = newActiveIndex
activeCueIndex = newActiveIndex

if (activeCueIndex >= 0) {
updateActiveLine(activeCueIndex, true)
if (activeCueIndex >= 0) {
updateActiveLine(activeCueIndex, true)

// Add the 'active-added' class once the media starts
if (!transcriptContainer.classList.contains('active-added')) {
transcriptContainer.classList.add('active-added')
}
// Add the 'active-added' class once the media starts
if (!transcriptContainer.classList.contains('active-added')) {
transcriptContainer.classList.add('active-added')
}

if (this._config.autoScroll) {
this._scroll(transcriptLines[activeCueIndex])
}
if (this._config.autoScroll) {
this._scroll(transcriptLines[activeCueIndex])
}
}
}
}

media.removeEventListener('timeupdate', this._handleTimeUpdate)
media.addEventListener('timeupdate', this._handleTimeUpdate)
}

Expand Down
Loading