Commit 19ca94c1 by Prem Sichanugrist

Do not display play/pause button on iOS Device

iOS devices has a restriction that user has to click on the video
element to initiate playback. By visually disable the button, user will
be forced to click on the video itself, and everything will be worked as
expected.

Fixes https://www.pivotaltracker.com/story/show/30334381
parent 6b9130fa
describe 'VideoControl', -> describe 'VideoControl', ->
beforeEach -> beforeEach ->
@player = jasmine.stubVideoPlayer @ @player = jasmine.stubVideoPlayer @
$('.video-controls').html ''
describe 'constructor', -> describe 'constructor', ->
beforeEach ->
@control = new VideoControl @player
it 'render the video controls', -> it 'render the video controls', ->
new VideoControl @player
expect($('.video-controls').html()).toContain ''' expect($('.video-controls').html()).toContain '''
<div class="slider"></div> <div class="slider"></div>
<div> <div>
<ul class="vcr"> <ul class="vcr">
<li><a class="video_control play">Play</a></li> <li><a class="video_control play" href="#">Play</a></li>
<li> <li>
<div class="vidtime">0:00 / 0:00</div> <div class="vidtime">0:00 / 0:00</div>
</li> </li>
...@@ -23,12 +22,33 @@ describe 'VideoControl', -> ...@@ -23,12 +22,33 @@ describe 'VideoControl', ->
''' '''
it 'bind player events', -> it 'bind player events', ->
expect($(@player)).toHandleWith 'play', @control.onPlay control = new VideoControl @player
expect($(@player)).toHandleWith 'pause', @control.onPause expect($(@player)).toHandleWith 'play', control.onPlay
expect($(@player)).toHandleWith 'ended', @control.onPause expect($(@player)).toHandleWith 'pause', control.onPause
expect($(@player)).toHandleWith 'ended', control.onPause
it 'bind the playback button', -> it 'bind the playback button', ->
expect($('.video_control')).toHandleWith 'click', @control.togglePlayback control = new VideoControl @player
expect($('.video_control')).toHandleWith 'click', control.togglePlayback
describe 'when on a touch based device', ->
beforeEach ->
spyOn(window, 'onTouchBasedDevice').andReturn true
it 'does not add the play class to video control', ->
new VideoControl @player
expect($('.video_control')).not.toHaveClass 'play'
expect($('.video_control')).not.toHaveHtml 'Play'
describe 'when on a non-touch based device', ->
beforeEach ->
spyOn(window, 'onTouchBasedDevice').andReturn false
it 'add the play class to video control', ->
new VideoControl @player
expect($('.video_control')).toHaveClass 'play'
expect($('.video_control')).toHaveHtml 'Play'
describe 'onPlay', -> describe 'onPlay', ->
beforeEach -> beforeEach ->
...@@ -54,20 +74,47 @@ describe 'VideoControl', -> ...@@ -54,20 +74,47 @@ describe 'VideoControl', ->
beforeEach -> beforeEach ->
@control = new VideoControl @player @control = new VideoControl @player
describe 'when the video is playing', -> describe 'when the control does not have play or pause class', ->
beforeEach -> beforeEach ->
spyOn(@player, 'isPlaying').andReturn true $('.video_control').removeClass('play').removeClass('pause')
spyOnEvent @player, 'pause'
@control.togglePlayback jQuery.Event('click')
it 'trigger the pause event', -> describe 'when the video is playing', ->
expect('pause').toHaveBeenTriggeredOn @player beforeEach ->
spyOn(@player, 'isPlaying').andReturn true
spyOnEvent @player, 'pause'
@control.togglePlayback jQuery.Event('click')
describe 'when the video is paused', -> it 'does not trigger the pause event', ->
beforeEach -> expect('pause').not.toHaveBeenTriggeredOn @player
spyOn(@player, 'isPlaying').andReturn false
spyOnEvent @player, 'play' describe 'when the video is paused', ->
@control.togglePlayback jQuery.Event('click') beforeEach ->
spyOn(@player, 'isPlaying').andReturn false
spyOnEvent @player, 'play'
@control.togglePlayback jQuery.Event('click')
it 'does not trigger the play event', ->
expect('play').not.toHaveBeenTriggeredOn @player
for className in ['play', 'pause']
describe "when the control has #{className} class", ->
beforeEach ->
$('.video_control').addClass className
describe 'when the video is playing', ->
beforeEach ->
spyOn(@player, 'isPlaying').andReturn true
spyOnEvent @player, 'pause'
@control.togglePlayback jQuery.Event('click')
it 'trigger the pause event', ->
expect('pause').toHaveBeenTriggeredOn @player
describe 'when the video is paused', ->
beforeEach ->
spyOn(@player, 'isPlaying').andReturn false
spyOnEvent @player, 'play'
@control.togglePlayback jQuery.Event('click')
it 'trigger the play event', -> it 'trigger the play event', ->
expect('play').toHaveBeenTriggeredOn @player expect('play').toHaveBeenTriggeredOn @player
...@@ -17,7 +17,7 @@ class @VideoControl ...@@ -17,7 +17,7 @@ class @VideoControl
<div class="slider"></div> <div class="slider"></div>
<div> <div>
<ul class="vcr"> <ul class="vcr">
<li><a class="video_control play">Play</a></li> <li><a class="video_control" href="#"></a></li>
<li> <li>
<div class="vidtime">0:00 / 0:00</div> <div class="vidtime">0:00 / 0:00</div>
</li> </li>
...@@ -26,7 +26,10 @@ class @VideoControl ...@@ -26,7 +26,10 @@ class @VideoControl
<a href="#" class="add-fullscreen" title="Fill browser">Fill Browser</a> <a href="#" class="add-fullscreen" title="Fill browser">Fill Browser</a>
</div> </div>
</div> </div>
""" """
unless onTouchBasedDevice()
@$('.video_control').addClass('play').html('Play')
onPlay: => onPlay: =>
@$('.video_control').removeClass('play').addClass('pause').html('Pause') @$('.video_control').removeClass('play').addClass('pause').html('Pause')
...@@ -36,7 +39,8 @@ class @VideoControl ...@@ -36,7 +39,8 @@ class @VideoControl
togglePlayback: (event) => togglePlayback: (event) =>
event.preventDefault() event.preventDefault()
if @player.isPlaying() if $('.video_control').hasClass('play') || $('.video_control').hasClass('pause')
$(@player).trigger('pause') if @player.isPlaying()
else $(@player).trigger('pause')
$(@player).trigger('play') else
$(@player).trigger('play')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment