Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for keybd events #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
60 changes: 57 additions & 3 deletions jquery.slimscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@
borderRadius: '7px',

// sets border radius of the rail
railBorderRadius : '7px'
railBorderRadius : '7px',

//default tab index
tabIndex: 0,

//Page scroll threshold
pageScrollThreshold: 10
};

var o = $.extend(defaults, options);
Expand Down Expand Up @@ -156,6 +162,9 @@
// wrap content
var wrapper = $(divS)
.addClass(o.wrapperClass)
.attr({
tabindex: o.tabIndex
})
.css({
position: 'relative',
overflow: 'hidden',
Expand Down Expand Up @@ -308,6 +317,51 @@
if (!o.alwaysVisible) { bar.hide(); }
}

//attach keyboard events
attachKeybd();
function _onKeyPress(e)
{
if (!isOverPanel) { return; }
e = e || window.event;
var delta = 1;
var target = e.target || e.srcTarget || e.srcElement;
if ($(target).closest('.' + o.wrapperClass).is(me.parent())) {
var key = e.key || e.keyIdentifier || e.keyCode;
switch (key) {
case 33://pageup
scrollContent(-delta, true, true, true);
break;
case 34://pagedown
scrollContent(delta, true, true, true);
break;
case 38://alert('up');
scrollContent(-delta, true);
break;
case 40://alert('down');
scrollContent(delta, true);
break;
default: return;
}
}
// stop window scroll
if (e.preventDefault && !releaseScroll) { e.preventDefault(); }
if (!releaseScroll) { e.returnValue = false; }
}
function attachKeybd()
{
var parent = me.closest('.'+o.wrapperClass);
parent
.bind('keydown', _onKeyPress)
.bind('focusin', function () {
isOverPanel = true;
showBar();
hideBar();
})
.bind('focusout', function () {
isOverPanel = false;
hideBar();
});
}
// attach scroll events
attachWheel();

Expand All @@ -333,7 +387,7 @@
if (!releaseScroll) { e.returnValue = false; }
}

function scrollContent(y, isWheel, isJump)
function scrollContent(y, isWheel, isJump, isPageJump)
{
releaseScroll = false;
var delta = y;
Expand Down Expand Up @@ -363,7 +417,7 @@

if (isJump)
{
delta = y;
delta = (isPageJump)? me.scrollTop() + (y * me.outerHeight()) - o.pageScrollThreshold : y;
var offsetTop = delta / me[0].scrollHeight * me.outerHeight();
offsetTop = Math.min(Math.max(offsetTop, 0), maxTop);
bar.css({ top: offsetTop + 'px' });
Expand Down