kdf
Version:
137 lines (84 loc) • 2.85 kB
text/coffeescript
KDView = require './../../core/view.coffee'
module.exports = class KDScrollThumb extends KDView
constructor:(options = {}, data) ->
options.type or= 'vertical'
options.cssClass = KD.utils.curry 'kdscrollthumb', options.cssClass
options.draggable ?=
axis : if options.type is 'vertical' then 'y' else 'x'
containment : this
super options, data
{ , } =
= .getDelegate()
'viewAppended', 'calculateSize'
'DragInAction', 'handleDrag'
.on 'scroll', 'calculatePosition'
resetSizes: ->
= null
= null
= null
reset: ->
handleDrag: ->
size =
offset =
thumbDiff = - # in case of given min-height/width with css
trackSize = - thumbDiff
availOffset = trackSize - size
ratio = Math.min Math.max(0, offset/availOffset), 1
if
then .setScrollTop ( .getScrollHeight() - trackSize) * ratio
else .setScrollLeft ( .getScrollWidth() - trackSize) * ratio
isVertical: -> is 'vertical'
getTrackSize: ->
if then
else if
then .getHeight()
else .getWidth()
setSize: (size) ->
if
then size
else size
= size
getSize: (force) ->
if and not force then
else if
then
else
setOffset: (offset) ->
if
then top : offset
else left : offset
getOffset: ->
if
then - .getY()
else - .getX()
getScrollOffset: ->
if
then .getScrollTop()
else .getScrollLeft()
getScrollSize: ->
if then
else if
then .getScrollHeight()
else .getScrollWidth()
calculateSize: ->
=
=
* /
calculatePosition: (event) ->
ratio = /
thumbDiff = - # in case of given min-height/width with css
trackSize =
(trackSize - thumbDiff) * ratio
setTrackVisibility: ->
if >=
then .hide()
else .show()
# I assume, this would fire a lot
# we may throttle this in case - SY
_windowDidResize: ->