Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

customview: keyboard handling #119

Merged
merged 1 commit into from
Mar 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kdf",
"version": "0.1.14",
"version": "0.1.15",
"description": "KD: a non-document focused UI Framework for web applications.",
"main": "gulpfile.js",
"scripts": {
Expand Down
74 changes: 74 additions & 0 deletions src/components/scrollview/customscrollviewinner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ KDScrollTrack = require './scrolltrack'

module.exports = class KDCustomScrollViewWrapper extends KDScrollView

SPACEBAR = 32
PAGEUP = 33
PAGEDOWN = 34
END = 35
HOME = 36

constructor: (options = {}, data) ->

options.bind = KD.utils.curry 'keydown', options.bind
options.attributes ?= {}
options.attributes.tabindex ?= "0"

@globalKeydownEventBound = no

super options, data

@on 'MutationHappened', @bound "toggleGlobalKeydownEventOnSizeCheck"


scroll: (event) ->

if @verticalThumb.beingDragged or @horizontalThumb.beingDragged
Expand Down Expand Up @@ -70,3 +89,58 @@ module.exports = class KDCustomScrollViewWrapper extends KDScrollView
@setScrollLeft lastPosition = newPosition

return shouldStop


toggleGlobalKeydownEventOnSizeCheck: ->

winHeight = $(window).height()
needToBind = @getHeight() >= winHeight
@toggleGlobalKeydownEvent needToBind


toggleGlobalKeydownEvent: (needToBind) ->

eventName = "keydown.customscroll#{@getId()}"

if needToBind
$(document).on eventName, @bound "keyDown" unless @globalKeydownEventBound
else
$(document).off eventName if @globalKeydownEventBound

@globalKeydownEventBound = needToBind


destroy: ->

@toggleGlobalKeydownEvent no
super


pageUp: ->
@scrollTo top : Math.max @getScrollTop() - @getHeight(), 0


pageDown: ->
@scrollTo top : @getScrollTop() + @getHeight()


keyDown: (event) ->

editables = "input,textarea,select,datalist,keygen,[contenteditable='true']"

return yes if ($ document.activeElement).is editables
return yes if not(@getDomElement().is ":visible")
return yes if @getScrollHeight() <= @verticalThumb.getTrackSize()

shouldPropagate = no
if event.which is SPACEBAR and event.shiftKey
@pageUp()
else
switch event.which
when PAGEUP then @pageUp()
when SPACEBAR, PAGEDOWN then @pageDown()
when END then @scrollToBottom()
when HOME then @scrollTo top : 0
else shouldPropagate = yes

return shouldPropagate
3 changes: 3 additions & 0 deletions src/themes/default/kd.scrollview.styl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
overflow hidden !important
height 100%

&:focus
outline none

.kdscrolltrack
right 0
z-index 1000
Expand Down