MCPcopy Create free account
hub / github.com/breck7/scroll / onScrollWheel

Function onScrollWheel

external/.scrollLibs.js:6183–6273  ·  view source on GitHub ↗
(cm, e)

Source from the content-addressed store, hash-verified

6181 }
6182
6183 function onScrollWheel(cm, e) {
6184 var delta = wheelEventDelta(e),
6185 dx = delta.x,
6186 dy = delta.y
6187
6188 var display = cm.display,
6189 scroll = display.scroller
6190 // Quit if there's nothing to scroll here
6191 var canScrollX = scroll.scrollWidth > scroll.clientWidth
6192 var canScrollY = scroll.scrollHeight > scroll.clientHeight
6193 if (!((dx && canScrollX) || (dy && canScrollY))) {
6194 return
6195 }
6196
6197 // Webkit browsers on OS X abort momentum scrolls when the target
6198 // of the scroll event is removed from the scrollable element.
6199 // This hack (see related code in patchDisplay) makes sure the
6200 // element is kept around.
6201 if (dy && mac && webkit) {
6202 outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
6203 for (var i = 0; i < view.length; i++) {
6204 if (view[i].node == cur) {
6205 cm.display.currentWheelTarget = cur
6206 break outer
6207 }
6208 }
6209 }
6210 }
6211
6212 // On some browsers, horizontal scrolling will cause redraws to
6213 // happen before the gutter has been realigned, causing it to
6214 // wriggle around in a most unseemly way. When we have an
6215 // estimated pixels/delta value, we just handle horizontal
6216 // scrolling entirely here. It'll be slightly off from native, but
6217 // better than glitching out.
6218 if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
6219 if (dy && canScrollY) {
6220 updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit))
6221 }
6222 setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit))
6223 // Only prevent default scrolling if vertical scrolling is
6224 // actually possible. Otherwise, it causes vertical scroll
6225 // jitter on OSX trackpads when deltaX is small and deltaY
6226 // is large (issue #3579)
6227 if (!dy || (dy && canScrollY)) {
6228 e_preventDefault(e)
6229 }
6230 display.wheelStartX = null // Abort measurement, if in progress
6231 return
6232 }
6233
6234 // 'Project' the visible viewport to cover the area that is being
6235 // scrolled into view (if we know enough to estimate it).
6236 if (dy && wheelPixelsPerUnit != null) {
6237 var pixels = dy * wheelPixelsPerUnit
6238 var top = cm.doc.scrollTop,
6239 bot = top + display.wrapper.clientHeight
6240 if (pixels < 0) {

Callers 1

registerEventHandlersFunction · 0.85

Calls 7

wheelEventDeltaFunction · 0.85
updateScrollTopFunction · 0.85
setScrollLeftFunction · 0.85
e_preventDefaultFunction · 0.85
updateDisplaySimpleFunction · 0.85
maxMethod · 0.80
minMethod · 0.80

Tested by

no test coverage detected