UNPKG

kdf

Version:

KD: a non-document focused UI Framework for web applications.

73 lines (45 loc) 1.77 kB
KDCustomHTMLView = require './../../core/customhtmlview' KDScrollView = require './scrollview' KDScrollThumb = require './scrollthumb' KDScrollTrack = require './scrolltrack' module.exports = class KDCustomScrollViewWrapper extends KDScrollView scroll: (event) -> if @verticalThumb.beingDragged or @horizontalThumb.beingDragged return KD.utils.stopDOMEvent event mouseWheel: (event) -> super {deltaX, deltaY, deltaFactor} = event speed = deltaFactor or @getOptions().mouseWheelSpeed or 1 x = -deltaX y = -deltaY resX = if x isnt 0 and @getScrollWidth() > @horizontalThumb.getTrackSize() then @_scrollHorizontally {speed, velocity : x} else no resY = if y isnt 0 and @getScrollHeight() > @verticalThumb.getTrackSize() then @_scrollVertically {speed, velocity : y} else no stop = if Math.abs(x) > Math.abs(y) then resX else resY KD.utils.stopDOMEvent event unless stop return !stop _scrollVertically: do -> lastPosition = 0 ({speed, velocity})-> stepInPixels = velocity * speed actPosition = @getScrollTop() newPosition = actPosition + stepInPixels shouldStop = if velocity > 0 then lastPosition > newPosition else lastPosition < newPosition @setScrollTop lastPosition = newPosition return shouldStop _scrollHorizontally: do -> lastPosition = 0 ({speed, velocity})-> stepInPixels = velocity * speed actPosition = @getScrollLeft() newPosition = actPosition - stepInPixels shouldStop = if velocity > 0 then lastPosition < newPosition else lastPosition > newPosition @setScrollLeft lastPosition = newPosition return shouldStop