Last active
October 19, 2016 12:52
-
-
Save reddo/d7ab532e03ffb41b3fa9870aab0a1d09 to your computer and use it in GitHub Desktop.
Added check for touch devices.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Determines the way of scrolling up or down: | |
* by 'automatically' scrolling a section or by using the default and normal scrolling. | |
*/ | |
function scrolling(type, scrollable){ | |
if (!isScrollAllowed.m[type]) { | |
return; | |
} | |
var firstTimeToTop = typeof scrollable.data('firstTimeToTop') === "undefined" ? true : scrollable.data('firstTimeToTop'), // get variable from data instance if it's set, otherwise set default. | |
firstTimeToBottom = typeof scrollable.data('firstTimeToBottom') === "undefined" ? true : scrollable.data('firstTimeToBottom'), // get variable from data instance if it's set, otherwise set default. | |
check = (type === 'down') ? 'bottom' : 'top', | |
scrollSection = (type === 'down') ? moveSectionDown : moveSectionUp; | |
if (FP.scrollHorizontally) { | |
scrollSection = FP.scrollHorizontally.getScrollSection(type, scrollSection); | |
} | |
if ( scrollable.length > 0 ) { | |
//is the scrollbar at the start/end of the scroll? | |
var iscrollInstance = scrollable.data('iscrollInstance'); | |
if ( firstTimeToBottom === false && iscrollInstance.maxScrollY !== iscrollInstance.y ) { | |
firstTimeToBottom = true; // Resetting the variable if the section was resized | |
scrollable.data('firstTimeToBottom', firstTimeToBottom); // add variable to data instance | |
} | |
if (options.scrollOverflowHandler.isScrolled(check, scrollable)) { | |
if (type === 'down') { | |
if (!firstTimeToBottom || isTouchDevice) { | |
scrollSection(); // It isn't the 1st time we reach bottom and it's not a touch device, section can be scrolled. | |
firstTimeToBottom = true; // Resetting variable for the next section. | |
firstTimeToTop = true; // Resetting variable for the next section. | |
scrollable.data('firstTimeToBottom', firstTimeToBottom); // add variable to data instance | |
scrollable.data('firstTimeToTop', firstTimeToTop); // add variable to data instance | |
} else { | |
setTimeout(function(){ | |
firstTimeToBottom = false; // this will make the section scroll on the next scroll. | |
firstTimeToTop = true; // Resetting the other variable so it won't scroll if the user switches scroll direction. | |
scrollable.data('firstTimeToBottom', firstTimeToBottom); // add variable to data instance | |
scrollable.data('firstTimeToTop', firstTimeToTop); // add variable to data instance | |
}, 500); | |
return false; | |
} | |
} else { | |
if (!firstTimeToTop || isTouchDevice) { | |
scrollSection(); // It isn't the 1st time we reach bottom, section can be scrolled. | |
firstTimeToBottom = true; // Resetting variable for the next section. | |
firstTimeToTop = true; // Resetting variable for the next section. | |
scrollable.data('firstTimeToBottom', firstTimeToBottom); // add variable to data instance | |
scrollable.data('firstTimeToTop', firstTimeToTop); // add variable to data instance | |
} else { | |
setTimeout(function(){ | |
firstTimeToBottom = true; // Resetting the other variable so it won't scroll if the user switches scroll direction. | |
firstTimeToTop = false; // The section will scroll when next scroll occurs. | |
scrollable.data('firstTimeToBottom', firstTimeToBottom); // add variable to data instance | |
scrollable.data('firstTimeToTop', firstTimeToTop); // add variable to data instance | |
}, 500); | |
return false; | |
} | |
} | |
} else { | |
return true; | |
} | |
} else { | |
// moved up/down | |
scrollSection(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment