kdf
Version:
94 lines (69 loc) • 2.85 kB
text/coffeescript
window.MutationSummary = require './../../../libs/mutation-summary.js'
KDCustomHTMLView = require './../../core/customhtmlview'
KDScrollTrack = require './scrolltrack'
KDCustomScrollViewWrapper = require './customscrollviewinner'
module.exports = class KDCustomScrollView extends KDCustomHTMLView
constructor: (options = {}, data) ->
options.bind = KD.utils.curry 'mouseenter mouseleave', options.bind
options.cssClass = KD.utils.curry 'kdcustomscrollview', options.cssClass
options.mouseWheelSpeed ?= 3
super options, data
{mouseWheelSpeed, lazyLoadThreshold, wrapperClass} = ()
() if options.offscreenIndicatorClassName?
Wrapper = wrapperClass or KDCustomScrollViewWrapper
= new Wrapper {
tagName : 'main'
lazyLoadThreshold
mouseWheelSpeed
scroll:
if options.offscreenIndicatorClassName?
then 'updateOffscreenIndicators'
}
= new KDScrollTrack delegate :
= new KDScrollTrack delegate : , type : 'horizontal'
.verticalThumb = .thumb
.horizontalThumb = .thumb
.on 'ScrollTrackShown', (type) => "has-#{type}"
.on 'ScrollTrackHidden', (type) => "has-#{type}"
.on 'MutationHappened', =>
.thumb.reset()
.thumb.reset()
'mouseenter', 'showTracks'
'mouseleave', 'hideTracks'
_windowDidResize: ->
()
updateOffscreenIndicators: ->
wrapperEl = .getElement()
{ offscreenIndicatorClassName } = ()
{ above, below } = [].slice.call(
wrapperEl.getElementsByClassName(offscreenIndicatorClassName))
.reduce (memo, child) ->
[_, y] = KD.utils.relativeOffset child, wrapperEl
if y < wrapperEl.scrollTop
memo.above.push child
else if y > wrapperEl.scrollTop + wrapperEl.offsetHeight
memo.below.push child
return memo
, { above: [], below: [] }
if above.length > 0
'OffscreenItemsAbove', above
else
'NoOffscreenItemsAbove'
if below.length > 0
'OffscreenItemsBelow', below
else
'NoOffscreenItemsBelow'
viewAppended: ->
.observeMutations()
intent = null
hideTracks: ->
intent = KD.utils.wait 1000, =>
.setClass 'out'
.setClass 'out'
showTracks: ->
KD.utils.killWait intent if intent
.unsetClass 'out'
.unsetClass 'out'