mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-26 00:37:37 +08:00
Simplify replay seek click handler (#1667)
Makes use of jQuery.fn.on 2nd argument selector (https://stackoverflow.com/a/1207393/6791873). Apart from being a lot simpler and cross-platform, this also fixes replay seeking breaking in some strange conditions like having the Firefox devtools open. Yes, it took me a while to figure that one out.
This commit is contained in:
parent
e02c6d57a1
commit
ecee05cd50
1 changed files with 3 additions and 15 deletions
|
|
@ -264,27 +264,15 @@ $(".pageTest #playpauseReplayButton").click(async (event) => {
|
|||
}
|
||||
});
|
||||
|
||||
$("#replayWords").click((event) => {
|
||||
$("#replayWords").on("click", "letter", (event) => {
|
||||
//allows user to click on the place they want to start their replay at
|
||||
pauseReplay();
|
||||
const replayWords = document.querySelector("#replayWords");
|
||||
let range;
|
||||
let textNode;
|
||||
|
||||
if (document.caretPositionFromPoint) {
|
||||
// standard
|
||||
range = document.caretPositionFromPoint(event.pageX, event.pageY);
|
||||
textNode = range.offsetNode;
|
||||
} else if (document.caretRangeFromPoint) {
|
||||
// WebKit
|
||||
range = document.caretRangeFromPoint(event.pageX, event.pageY);
|
||||
textNode = range.startContainer;
|
||||
}
|
||||
|
||||
const words = [...replayWords.children];
|
||||
targetWordPos = words.indexOf(textNode.parentNode.parentNode);
|
||||
targetWordPos = words.indexOf(event.target.parentNode);
|
||||
const letters = [...words[targetWordPos].children];
|
||||
targetCurPos = letters.indexOf(textNode.parentNode);
|
||||
targetCurPos = letters.indexOf(event.target);
|
||||
|
||||
initializeReplayPrompt();
|
||||
loadOldReplay();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue