Skip to content

Commit

Permalink
Merge pull request #48 from 0x6368/master
Browse files Browse the repository at this point in the history
Fixed and improved scrolling using the arrow keys
  • Loading branch information
stonesam92 committed Aug 21, 2015
2 parents 01ea99e + 606a633 commit 160d8bc
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions WhatsMac/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,19 @@ function clickOnItemWithIndex (index, scrollToItem) {
var desiredItem = $this.get(0);
desiredItem.firstChild.click();
if (scrollToItem) {
var scrollPos = offsetOfListItem($(desiredItem));
$('.pane-list-body')[0].scrollTop = scrollPos;
$scrollView = $('.pane-list-body');
$desiredItem = $(desiredItem);

// Check whether the desired item is not inside the viewport (below)
if ($desiredItem.position().top + CHAT_ITEM_HEIGHT > $scrollView.scrollTop() + $scrollView.height()) {
var scrollPos = $desiredItem.position().top - $scrollView.height() + CHAT_ITEM_HEIGHT;
$scrollView.stop().animate({scrollTop: scrollPos}, 150);
}
// Check whether the desired item is not inside the viewport (above)
else if ($desiredItem.position().top < $scrollView.scrollTop()) {
var scrollPos = $desiredItem.position().top;
$scrollView.stop().animate({scrollTop: scrollPos}, 150);
}
}
return false;
}
Expand Down Expand Up @@ -128,6 +139,7 @@ jQuery(function () {
var isInputFieldEmpty = $input.contents().length === 0 ||
$input.contents()[0].nodeName === 'BR';
if (direction && isInputFieldEmpty) {
event.preventDefault();
var $selectedItem = null;
var $infiniteListItems = $('.infinite-list-viewport .infinite-list-item');
$.each($infiniteListItems, function () {
Expand Down

0 comments on commit 160d8bc

Please sign in to comment.