mirror of
https://github.com/videojs/video.js.git
synced 2024-12-16 11:37:29 +02:00
Merge pull request #457 from gkatsev/fix/calculateDistance
Fix calculateDistance on slider to work in iframes and all devices.
This commit is contained in:
commit
f81b369955
@ -135,9 +135,7 @@ vjs.Slider.prototype.calculateDistance = function(event){
|
||||
boxW = boxW - handleW;
|
||||
}
|
||||
|
||||
// This is done because on Android, event.pageX is always 0 and the actual
|
||||
// values live under the changedTouches array.
|
||||
if (pageX === 0 && event.changedTouches) {
|
||||
if (event.changedTouches) {
|
||||
pageX = event.changedTouches[0].pageX;
|
||||
}
|
||||
|
||||
@ -161,4 +159,4 @@ vjs.Slider.prototype.onKeyPress = function(event){
|
||||
|
||||
vjs.Slider.prototype.onBlur = function(){
|
||||
vjs.off(document, 'keyup', vjs.bind(this, this.onKeyPress));
|
||||
};
|
||||
};
|
||||
|
24
test/unit/controls.js
vendored
24
test/unit/controls.js
vendored
@ -75,3 +75,27 @@ test('should test and toggle volume control on `loadstart`', function(){
|
||||
ok(muteToggle.el().className.indexOf('vjs-hidden') < 0,
|
||||
'muteToggle does not show itself');
|
||||
});
|
||||
|
||||
test('calculateDistance should use changedTouches, if available', function() {
|
||||
var noop, player, slider, event;
|
||||
noop = function(){};
|
||||
player = {
|
||||
id: noop,
|
||||
on: noop,
|
||||
ready: noop
|
||||
};
|
||||
slider = new vjs.Slider(player);
|
||||
document.body.appendChild(slider.el_);
|
||||
slider.el_.style.position = 'absolute';
|
||||
slider.el_.style.width = '200px';
|
||||
slider.el_.style.left = '0px';
|
||||
|
||||
event = {
|
||||
pageX: 10,
|
||||
changedTouches: [{
|
||||
pageX: 100
|
||||
}]
|
||||
};
|
||||
|
||||
equal(slider.calculateDistance(event), 0.5, 'we should have touched exactly in the center, so, the ratio should be half');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user