MCPcopy Create free account
hub / github.com/code100x/cms / setCurrentLabel

Function setCurrentLabel

src/lib/createAndHandleSegments.ts:69–113  ·  view source on GitHub ↗
(
  e: any,
  preview_position: any,
  segments: Segment[],
  player: any,
)

Source from the content-addressed store, hash-verified

67}
68
69function setCurrentLabel(
70 e: any,
71 preview_position: any,
72 segments: Segment[],
73 player: any,
74) {
75 let currentLabel = segments[0].title;
76
77 const currentPos = preview_position * player?.duration();
78 if (preview_position !== 0) {
79 segments?.forEach((each: Segment) => {
80 if (each?.start < currentPos && each?.end > currentPos) {
81 currentLabel = each?.title;
82 }
83 });
84 }
85
86 const timelineLabel = document.querySelector(
87 '#timeline-label',
88 ) as HTMLDivElement;
89 const timelineContainer = document.querySelector(
90 '#timeline-container',
91 ) as HTMLDivElement;
92
93 const rect = timelineContainer && timelineContainer?.getBoundingClientRect();
94
95 let timelineLabelWidth = timelineLabel?.offsetWidth / 2;
96
97 if (timelineLabel && rect && timelineContainer) {
98 timelineLabel.innerHTML = `<div>${formatTime(preview_position.toFixed(2) * player?.duration())} - ${currentLabel}</div>`;
99
100 if (Math.max(0, e?.x - rect?.x) < timelineLabel?.offsetWidth / 2) {
101 timelineLabelWidth = Math.max(0, e?.x - rect?.x);
102 } else if (
103 Math.max(0, e?.x - rect?.x) >
104 timelineContainer.offsetWidth - timelineLabel?.offsetWidth / 2
105 ) {
106 timelineLabelWidth =
107 timelineLabel?.offsetWidth -
108 (timelineContainer?.offsetWidth - (e?.x - rect?.x));
109 }
110
111 timelineLabel.style.left = `calc(${preview_position * 100}% - ${timelineLabelWidth}px)`;
112 }
113}
114
115let isMouseOver = false;
116let isMouseDown = false;

Callers 1

updateTimelineFunction · 0.85

Calls 1

formatTimeFunction · 0.90

Tested by

no test coverage detected