Try a smaller timeout + minor fixes.

This commit is contained in:
Paulo Reis 2016-08-01 11:12:50 +01:00
parent 16e8cd7820
commit 0d4e1e5495
2 changed files with 4 additions and 9 deletions

View file

@ -138,7 +138,7 @@ define [
console.error err
if ide.browserIsSafari
ide.safariScrollPatcher = new SafariScrollPatcher(ide, $scope)
ide.safariScrollPatcher = new SafariScrollPatcher($scope)
# User can append ?ft=somefeature to url to activate a feature toggle
ide.featureToggle = location?.search?.match(/^\?ft=(\w+)$/)?[1]

View file

@ -1,7 +1,7 @@
define [
], () ->
class SafariScrollPatcher
constructor: (ide, $scope) ->
constructor: ($scope) ->
@isOverAce = false # Flag to control if the pointer is over Ace.
@pdfDiv = null
@aceDiv = null
@ -10,24 +10,20 @@ define [
# P.S. This is the problem in a nutshell: although the pointer is elsewhere,
# wheel events keep being dispatched to the PDF.
@handlePdfDivMouseLeave = () =>
console.log "dispatching to ace enabled"
@pdfDiv.addEventListener "wheel", @dispatchToAce
# Stop listening to wheel events when the pointer enters the PDF region. If
# the pointer is over the PDF, native behaviour is adequate.
@handlePdfDivMouseEnter = () =>
console.log "dispatching to ace disabled"
@pdfDiv.removeEventListener "wheel", @dispatchToAce
# Set the "pointer over Ace" flag as false, when the mouse leaves its area.
@handleAceDivMouseLeave = () =>
@isOverAce = false
console.log 'is over ace = ' + @isOverAce
# Set the "pointer over Ace" flag as true, when the mouse enters its area.
@handleAceDivMouseEnter = () =>
@isOverAce = true
console.log 'is over ace = ' + @isOverAce
# Grab the elements (pdfDiv, aceDiv) and set the "hover" event listeners.
# If elements are already defined, clear existing event listeners and do
@ -46,7 +42,7 @@ define [
# Grab elements.
@pdfDiv = document.querySelector ".pdfjs-viewer" # Grab the PDF div.
@aceDiv = document.querySelector ".ace_content" # Also the editor.
@aceDiv = document.querySelector ".ace_content" # Also the editor.
# Set hover-related listeners.
@pdfDiv.addEventListener "mouseleave", @handlePdfDivMouseLeave
@ -61,14 +57,13 @@ define [
if @isOverAce
# If this is logged, the problem just happened: the event arrived
# here (the PDF wheel handler), but it should've gone to Ace.
console.log "Event was bound to the PDF, dispatching to Ace"
# Small timeout - if we dispatch immediately, an exception is thrown.
window.setTimeout(() =>
# Dispatch the exact same event to Ace (this will keep values
# values e.g. `wheelDelta` consistent with user interaction).
@aceDiv.dispatchEvent e
, 5)
, 1)
# Avoid scrolling the PDF, as we assume this was intended to the
# editor.