Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
b1daa59c
Commit
b1daa59c
authored
May 15, 2012
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor video caption to use binary search
parent
8a87a4ba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
16 deletions
+21
-16
templates/coffee/src/modules/video/video_caption.coffee
+21
-16
No files found.
templates/coffee/src/modules/video/video_caption.coffee
View file @
b1daa59c
class
VideoCaption
constructor
:
(
@
player
,
@
youtubeId
)
->
@
index
=
[]
@
render
()
@
bind
()
...
...
@@ -29,6 +28,12 @@ class VideoCaption
@
$
(
'.subtitles'
).
css
maxHeight
:
@
$
(
'.video-wrapper'
).
height
()
-
5
@
fetchCaption
()
fetchCaption
:
->
$
.
getWithPrefix
@
captionURL
(),
(
captions
)
=>
@
captions
=
captions
.
text
@
start
=
captions
.
start
@
renderCaption
()
renderCaption
:
->
container
=
$
(
'<ol>'
)
...
...
@@ -44,28 +49,28 @@ class VideoCaption
@
$
(
'.subtitles'
).
prepend
(
$
(
'<li class="spacing">'
).
height
(
@
topSpacingHeight
()))
.
append
(
$
(
'<li class="spacing">'
).
height
(
@
bottomSpacingHeight
()))
fetchCaption
:
->
$
.
getWithPrefix
@
captionURL
(),
(
captions
)
=>
@
captions
=
captions
.
text
@
start
=
captions
.
start
for
index
in
[
0
...
captions
.
start
.
length
]
for
time
in
[
captions
.
start
[
index
]..
captions
.
end
[
index
]]
@
index
[
time
]
||=
[]
@
index
[
time
].
push
(
index
)
@
renderCaption
()
search
:
(
time
)
->
min
=
0
max
=
@
start
.
length
-
1
while
min
<
max
index
=
Math
.
ceil
((
max
+
min
)
/
2
)
if
time
<
@
start
[
index
]
max
=
index
-
1
if
time
>=
@
start
[
index
]
min
=
index
return
min
onUpdatePlayTime
:
(
event
,
time
)
=>
# This 250ms offset is required to match the video speed
time
=
Math
.
round
(
Time
.
convert
(
time
,
@
player
.
currentSpeed
(),
'1.0'
)
*
1000
+
250
)
newIndex
=
@
index
[
time
]
newIndex
=
@
search
time
if
newIndex
!=
undefined
&&
@
currentIndex
!=
newIndex
if
@
currentIndex
for
index
in
@
currentIndex
@
$
(
".subtitles li[data-index='
#{
index
}
']"
).
removeClass
(
'current'
)
for
index
in
newIndex
@
$
(
".subtitles li[data-index='
#{
newIndex
}
']"
).
addClass
(
'current'
)
@
$
(
".subtitles li.current"
).
removeClass
(
'current'
)
@
$
(
".subtitles li[data-index='
#{
newIndex
}
']"
).
addClass
(
'current'
)
@
currentIndex
=
newIndex
@
scrollCaption
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment