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
ff22099b
Commit
ff22099b
authored
Jun 04, 2012
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide the caption first when on the iOS browser
This prevent user from prematurely seeking the video.
parent
ac8e3dfe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
116 additions
and
68 deletions
+116
-68
static/coffee/spec/helper.coffee
+2
-6
static/coffee/spec/modules/video/video_caption_spec.coffee
+103
-61
static/coffee/src/modules/video/video_caption.coffee
+11
-1
No files found.
static/coffee/spec/helper.coffee
View file @
ff22099b
...
@@ -11,12 +11,8 @@ jasmine.stubbedMetadata =
...
@@ -11,12 +11,8 @@ jasmine.stubbedMetadata =
duration
:
300
duration
:
300
jasmine
.
stubbedCaption
=
jasmine
.
stubbedCaption
=
start
:
[
0
,
10000
,
20000
,
30000
,
40000
,
50000
,
60000
,
70000
,
80000
,
90000
,
start
:
[
0
,
10000
,
20000
,
30000
]
100000
,
110000
,
120000
]
text
:
[
'Caption at 0'
,
'Caption at 10000'
,
'Caption at 20000'
,
'Caption at 30000'
]
text
:
[
'Caption at 0'
,
'Caption at 10000'
,
'Caption at 20000'
,
'Caption at 30000'
,
'Caption at 40000'
,
'Caption at 50000'
,
'Caption at 60000'
,
'Caption at 70000'
,
'Caption at 80000'
,
'Caption at 90000'
,
'Caption at 100000'
,
'Caption at 110000'
,
'Caption at 120000'
]
jasmine
.
stubRequests
=
->
jasmine
.
stubRequests
=
->
spyOn
(
$
,
'ajax'
).
andCallFake
(
settings
)
->
spyOn
(
$
,
'ajax'
).
andCallFake
(
settings
)
->
...
...
static/coffee/spec/modules/video/video_caption_spec.coffee
View file @
ff22099b
...
@@ -9,66 +9,82 @@ describe 'VideoCaption', ->
...
@@ -9,66 +9,82 @@ describe 'VideoCaption', ->
describe
'constructor'
,
->
describe
'constructor'
,
->
beforeEach
->
beforeEach
->
spyOn
(
$
,
'getWithPrefix'
).
andCallThrough
()
spyOn
(
$
,
'getWithPrefix'
).
andCallThrough
()
@
caption
=
new
VideoCaption
@
player
,
'def456'
it
'set the player'
,
->
describe
'always'
,
->
expect
(
@
caption
.
player
).
toEqual
@
player
beforeEach
->
@
caption
=
new
VideoCaption
@
player
,
'def456'
it
'set the youtube id'
,
->
expect
(
@
caption
.
youtubeId
).
toEqual
'def456'
it
'set the player'
,
->
expect
(
@
caption
.
player
).
toEqual
@
player
it
'create the caption element'
,
->
expect
(
$
(
'.video'
)).
toContain
'ol.subtitles'
it
'set the youtube id'
,
->
expect
(
@
caption
.
youtubeId
).
toEqual
'def456'
it
'add caption control to video player'
,
->
expect
(
$
(
'.video'
)).
toContain
'a.hide-subtitles'
it
'create the caption element'
,
->
expect
(
$
(
'.video'
)).
toContain
'ol.subtitles'
it
'fetch the caption'
,
->
expect
(
$
.
getWithPrefix
).
toHaveBeenCalledWith
@
caption
.
captionURL
(),
jasmine
.
any
(
Function
)
it
'add caption control to video player'
,
->
expect
(
$
(
'.video'
)).
toContain
'a.hide-subtitles'
it
'render the caption'
,
->
expect
(
$
(
'.subtitles'
).
html
()).
toMatch
new
RegExp
(
'''
it
'fetch the caption'
,
->
<li data-index="0" data-start="0">Caption at 0</li>
expect
(
$
.
getWithPrefix
).
toHaveBeenCalledWith
@
caption
.
captionURL
(),
jasmine
.
any
(
Function
)
<li data-index="1" data-start="10000">Caption at 10000</li>
<li data-index="2" data-start="20000">Caption at 20000</li>
it
'bind window resize event'
,
->
<li data-index="3" data-start="30000">Caption at 30000</li>
expect
(
$
(
window
)).
toHandleWith
'resize'
,
@
caption
.
onWindowResize
<li data-index="4" data-start="40000">Caption at 40000</li>
<li data-index="5" data-start="50000">Caption at 50000</li>
it
'bind player resize event'
,
->
<li data-index="6" data-start="60000">Caption at 60000</li>
expect
(
$
(
@
player
)).
toHandleWith
'resize'
,
@
caption
.
onWindowResize
<li data-index="7" data-start="70000">Caption at 70000</li>
<li data-index="8" data-start="80000">Caption at 80000</li>
it
'bind player updatePlayTime event'
,
->
<li data-index="9" data-start="90000">Caption at 90000</li>
expect
(
$
(
@
player
)).
toHandleWith
'updatePlayTime'
,
@
caption
.
onUpdatePlayTime
<li data-index="10" data-start="100000">Caption at 100000</li>
<li data-index="11" data-start="110000">Caption at 110000</li>
it
'bind player play event'
,
->
<li data-index="12" data-start="120000">Caption at 120000</li>
expect
(
$
(
@
player
)).
toHandleWith
'play'
,
@
caption
.
onPlay
'''
.
replace
(
/\n/g
,
''
))
it
'bind the hide caption button'
,
->
it
'add a padding element to caption'
,
->
expect
(
$
(
'.hide-subtitles'
)).
toHandleWith
'click'
,
@
caption
.
toggle
expect
(
$
(
'.subtitles li:first'
)).
toBe
'.spacing'
expect
(
$
(
'.subtitles li:last'
)).
toBe
'.spacing'
it
'bind the mouse movement'
,
->
expect
(
$
(
'.subtitles'
)).
toHandleWith
'mouseenter'
,
@
caption
.
onMouseEnter
it
'bind all the caption link'
,
->
expect
(
$
(
'.subtitles'
)).
toHandleWith
'mouseleave'
,
@
caption
.
onMouseLeave
$
(
'.subtitles li[data-index]'
).
each
(
index
,
link
)
=>
expect
(
$
(
'.subtitles'
)).
toHandleWith
'mousemove'
,
@
caption
.
onMovement
expect
(
$
(
link
)).
toHandleWith
'click'
,
@
caption
.
seekPlayer
expect
(
$
(
'.subtitles'
)).
toHandleWith
'mousewheel'
,
@
caption
.
onMovement
expect
(
$
(
'.subtitles'
)).
toHandleWith
'DOMMouseScroll'
,
@
caption
.
onMovement
it
'bind window resize event'
,
->
expect
(
$
(
window
)).
toHandleWith
'resize'
,
@
caption
.
onWindowResize
describe
'when on a non touch-based device'
,
->
beforeEach
->
it
'bind player resize event'
,
->
spyOn
(
window
,
'onTouchBasedDevice'
).
andReturn
false
expect
(
$
(
@
player
)).
toHandleWith
'resize'
,
@
caption
.
onWindowResize
@
caption
=
new
VideoCaption
@
player
,
'def456'
it
'bind player updatePlayTime event'
,
->
it
'render the caption'
,
->
expect
(
$
(
@
player
)).
toHandleWith
'updatePlayTime'
,
@
caption
.
onUpdatePlayTime
expect
(
$
(
'.subtitles'
).
html
()).
toMatch
new
RegExp
(
'''
<li data-index="0" data-start="0">Caption at 0</li>
it
'bind the hide caption button'
,
->
<li data-index="1" data-start="10000">Caption at 10000</li>
expect
(
$
(
'.hide-subtitles'
)).
toHandleWith
'click'
,
@
caption
.
toggle
<li data-index="2" data-start="20000">Caption at 20000</li>
<li data-index="3" data-start="30000">Caption at 30000</li>
it
'bind the mouse movement'
,
->
'''
.
replace
(
/\n/g
,
''
))
expect
(
$
(
'.subtitles'
)).
toHandleWith
'mouseenter'
,
@
caption
.
onMouseEnter
expect
(
$
(
'.subtitles'
)).
toHandleWith
'mouseleave'
,
@
caption
.
onMouseLeave
it
'add a padding element to caption'
,
->
expect
(
$
(
'.subtitles'
)).
toHandleWith
'mousemove'
,
@
caption
.
onMovement
expect
(
$
(
'.subtitles li:first'
)).
toBe
'.spacing'
expect
(
$
(
'.subtitles'
)).
toHandleWith
'mousewheel'
,
@
caption
.
onMovement
expect
(
$
(
'.subtitles li:last'
)).
toBe
'.spacing'
expect
(
$
(
'.subtitles'
)).
toHandleWith
'DOMMouseScroll'
,
@
caption
.
onMovement
it
'bind all the caption link'
,
->
$
(
'.subtitles li[data-index]'
).
each
(
index
,
link
)
=>
expect
(
$
(
link
)).
toHandleWith
'click'
,
@
caption
.
seekPlayer
it
'set rendered to true'
,
->
expect
(
@
caption
.
rendered
).
toBeTruthy
()
describe
'when on a touch-based device'
,
->
beforeEach
->
spyOn
(
window
,
'onTouchBasedDevice'
).
andReturn
true
@
caption
=
new
VideoCaption
@
player
,
'def456'
it
'show explaination message'
,
->
expect
(
$
(
'.subtitles li'
)).
toHaveHtml
"Caption will be displayed when you start playing the video."
it
'does not set rendered to true'
,
->
expect
(
@
caption
.
rendered
).
toBeFalsy
()
describe
'mouse movement'
,
->
describe
'mouse movement'
,
->
beforeEach
->
beforeEach
->
...
@@ -145,8 +161,34 @@ describe 'VideoCaption', ->
...
@@ -145,8 +161,34 @@ describe 'VideoCaption', ->
expect
(
@
caption
.
search
(
9999
)).
toEqual
0
expect
(
@
caption
.
search
(
9999
)).
toEqual
0
expect
(
@
caption
.
search
(
10000
)).
toEqual
1
expect
(
@
caption
.
search
(
10000
)).
toEqual
1
expect
(
@
caption
.
search
(
15000
)).
toEqual
1
expect
(
@
caption
.
search
(
15000
)).
toEqual
1
expect
(
@
caption
.
search
(
120000
)).
toEqual
12
expect
(
@
caption
.
search
(
30000
)).
toEqual
3
expect
(
@
caption
.
search
(
120001
)).
toEqual
12
expect
(
@
caption
.
search
(
30001
)).
toEqual
3
describe
'onPlay'
,
->
describe
'when the caption was not rendered'
,
->
beforeEach
->
spyOn
(
window
,
'onTouchBasedDevice'
).
andReturn
true
@
caption
=
new
VideoCaption
@
player
,
'def456'
@
caption
.
onPlay
()
it
'render the caption'
,
->
expect
(
$
(
'.subtitles'
).
html
()).
toMatch
new
RegExp
(
'''
<li data-index="0" data-start="0">Caption at 0</li>
<li data-index="1" data-start="10000">Caption at 10000</li>
<li data-index="2" data-start="20000">Caption at 20000</li>
<li data-index="3" data-start="30000">Caption at 30000</li>
'''
.
replace
(
/\n/g
,
''
))
it
'add a padding element to caption'
,
->
expect
(
$
(
'.subtitles li:first'
)).
toBe
'.spacing'
expect
(
$
(
'.subtitles li:last'
)).
toBe
'.spacing'
it
'bind all the caption link'
,
->
$
(
'.subtitles li[data-index]'
).
each
(
index
,
link
)
=>
expect
(
$
(
link
)).
toHandleWith
'click'
,
@
caption
.
seekPlayer
it
'set rendered to true'
,
->
expect
(
@
caption
.
rendered
).
toBeTruthy
()
describe
'onUpdatePlayTime'
,
->
describe
'onUpdatePlayTime'
,
->
beforeEach
->
beforeEach
->
...
...
static/coffee/src/modules/video/video_caption.coffee
View file @
ff22099b
...
@@ -10,6 +10,7 @@ class @VideoCaption
...
@@ -10,6 +10,7 @@ class @VideoCaption
$
(
window
).
bind
(
'resize'
,
@
onWindowResize
)
$
(
window
).
bind
(
'resize'
,
@
onWindowResize
)
$
(
@
player
).
bind
(
'resize'
,
@
onWindowResize
)
$
(
@
player
).
bind
(
'resize'
,
@
onWindowResize
)
$
(
@
player
).
bind
(
'updatePlayTime'
,
@
onUpdatePlayTime
)
$
(
@
player
).
bind
(
'updatePlayTime'
,
@
onUpdatePlayTime
)
$
(
@
player
).
bind
(
'play'
,
@
onPlay
)
@
$
(
'.hide-subtitles'
).
click
@
toggle
@
$
(
'.hide-subtitles'
).
click
@
toggle
@
$
(
'.subtitles'
).
mouseenter
(
@
onMouseEnter
).
mouseleave
(
@
onMouseLeave
)
@
$
(
'.subtitles'
).
mouseenter
(
@
onMouseEnter
).
mouseleave
(
@
onMouseLeave
)
.
mousemove
(
@
onMovement
).
bind
(
'mousewheel'
,
@
onMovement
)
.
mousemove
(
@
onMovement
).
bind
(
'mousewheel'
,
@
onMovement
)
...
@@ -32,7 +33,11 @@ class @VideoCaption
...
@@ -32,7 +33,11 @@ class @VideoCaption
$
.
getWithPrefix
@
captionURL
(),
(
captions
)
=>
$
.
getWithPrefix
@
captionURL
(),
(
captions
)
=>
@
captions
=
captions
.
text
@
captions
=
captions
.
text
@
start
=
captions
.
start
@
start
=
captions
.
start
@
renderCaption
()
if
onTouchBasedDevice
()
$
(
'.subtitles li'
).
html
"Caption will be displayed when you start playing the video."
else
@
renderCaption
()
renderCaption
:
->
renderCaption
:
->
container
=
$
(
'<ol>'
)
container
=
$
(
'<ol>'
)
...
@@ -49,6 +54,8 @@ class @VideoCaption
...
@@ -49,6 +54,8 @@ class @VideoCaption
@
$
(
'.subtitles'
).
prepend
(
$
(
'<li class="spacing">'
).
height
(
@
topSpacingHeight
()))
@
$
(
'.subtitles'
).
prepend
(
$
(
'<li class="spacing">'
).
height
(
@
topSpacingHeight
()))
.
append
(
$
(
'<li class="spacing">'
).
height
(
@
bottomSpacingHeight
()))
.
append
(
$
(
'<li class="spacing">'
).
height
(
@
bottomSpacingHeight
()))
@
rendered
=
true
search
:
(
time
)
->
search
:
(
time
)
->
min
=
0
min
=
0
max
=
@
start
.
length
-
1
max
=
@
start
.
length
-
1
...
@@ -62,6 +69,9 @@ class @VideoCaption
...
@@ -62,6 +69,9 @@ class @VideoCaption
return
min
return
min
onPlay
:
=>
@
renderCaption
()
unless
@
rendered
onUpdatePlayTime
:
(
event
,
time
)
=>
onUpdatePlayTime
:
(
event
,
time
)
=>
# This 250ms offset is required to match the video speed
# This 250ms offset is required to match the video speed
time
=
Math
.
round
(
Time
.
convert
(
time
,
@
player
.
currentSpeed
(),
'1.0'
)
*
1000
+
250
)
time
=
Math
.
round
(
Time
.
convert
(
time
,
@
player
.
currentSpeed
(),
'1.0'
)
*
1000
+
250
)
...
...
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