Skip to content

Commit

Permalink
Refactor isScrollable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Rämö committed Apr 23, 2019
1 parent f70e83a commit b9bcfff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
18 changes: 12 additions & 6 deletions dist/muuri.js
Original file line number Diff line number Diff line change
Expand Up @@ -944,21 +944,27 @@
return offsetDiff;
}

var styleOverflow = 'overflow';
var styleOverflowX = 'overflow-x';
var styleOverflowY = 'overflow-y';
var overflowAuto = 'auto';
var overflowScroll = 'scroll';

/**
* Check if an element is scrollable.
*
* @param {HTMLElement} element
* @returns {Boolean}
*/
function isScrollable(element) {
var overflow = getStyle(element, 'overflow');
if (overflow === 'auto' || overflow === 'scroll') return true;
var overflow = getStyle(element, styleOverflow);
if (overflow === overflowAuto || overflow === overflowScroll) return true;

overflow = getStyle(element, 'overflow-x');
if (overflow === 'auto' || overflow === 'scroll') return true;
overflow = getStyle(element, styleOverflowX);
if (overflow === overflowAuto || overflow === overflowScroll) return true;

overflow = getStyle(element, 'overflow-y');
if (overflow === 'auto' || overflow === 'scroll') return true;
overflow = getStyle(element, styleOverflowY);
if (overflow === overflowAuto || overflow === overflowScroll) return true;

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/muuri.min.js

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions src/utils/isScrollable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@

import getStyle from './getStyle';

var styleOverflow = 'overflow';
var styleOverflowX = 'overflow-x';
var styleOverflowY = 'overflow-y';
var overflowAuto = 'auto';
var overflowScroll = 'scroll';

/**
* Check if an element is scrollable.
*
* @param {HTMLElement} element
* @returns {Boolean}
*/
export default function isScrollable(element) {
var overflow = getStyle(element, 'overflow');
if (overflow === 'auto' || overflow === 'scroll') return true;
var overflow = getStyle(element, styleOverflow);
if (overflow === overflowAuto || overflow === overflowScroll) return true;

overflow = getStyle(element, 'overflow-x');
if (overflow === 'auto' || overflow === 'scroll') return true;
overflow = getStyle(element, styleOverflowX);
if (overflow === overflowAuto || overflow === overflowScroll) return true;

overflow = getStyle(element, 'overflow-y');
if (overflow === 'auto' || overflow === 'scroll') return true;
overflow = getStyle(element, styleOverflowY);
if (overflow === overflowAuto || overflow === overflowScroll) return true;

return false;
}

0 comments on commit b9bcfff

Please sign in to comment.