Created
December 19, 2016 21:48
-
-
Save Oceanswave/2d29e6a2f24f7a7b1881e0fb8207b0a9 to your computer and use it in GitHub Desktop.
Netflix Seek
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var showControls = function() { | |
uiEventsHappening += 1; | |
var scrubber = $('#scrubber-component'); | |
var eventOptions = { | |
'bubbles': true, | |
'button': 0, | |
'currentTarget': scrubber[0] | |
}; | |
scrubber[0].dispatchEvent(new MouseEvent('mousemove', eventOptions)); | |
return delay(10)().then(function() { | |
uiEventsHappening -= 1; | |
}); | |
}; | |
var seek = function(milliseconds) { | |
uiEventsHappening += 1; | |
var eventOptions, scrubber; | |
return showControls().then(function() { | |
// compute the parameters for the mouse events | |
scrubber = $('#scrubber-component'); | |
var factor = milliseconds / getDuration(); | |
var mouseX = scrubber.offset().left + Math.round(scrubber.width() * factor); // relative to the document | |
var mouseY = scrubber.offset().top + scrubber.height() / 2; // relative to the document | |
eventOptions = { | |
'bubbles': true, | |
'button': 0, | |
'screenX': mouseX - $(window).scrollLeft(), | |
'screenY': mouseY - $(window).scrollTop(), | |
'clientX': mouseX - $(window).scrollLeft(), | |
'clientY': mouseY - $(window).scrollTop(), | |
'offsetX': mouseX - scrubber.offset().left, | |
'offsetY': mouseY - scrubber.offset().top, | |
'pageX': mouseX, | |
'pageY': mouseY, | |
'currentTarget': scrubber[0] | |
}; | |
// make the "trickplay preview" show up | |
scrubber[0].dispatchEvent(new MouseEvent('mouseover', eventOptions)); | |
}).then(delay(10)).then(function() { | |
// simulate a click on the scrubber | |
scrubber[0].dispatchEvent(new MouseEvent('mousedown', eventOptions)); | |
scrubber[0].dispatchEvent(new MouseEvent('mouseup', eventOptions)); | |
scrubber[0].dispatchEvent(new MouseEvent('mouseout', eventOptions)); | |
}).then(delay(1)).then(hideControls).then(function() { | |
uiEventsHappening -= 1; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment