| 21489 | }); |
| 21490 | var DATA_IS_SCROLLABLE_ATTRIBUTE = "data-is-scrollable"; |
| 21491 | var allowScrollOnElement = function(element, events) { |
| 21492 | if (!element) return; |
| 21493 | var _previousClientY = 0; |
| 21494 | var _element = null; |
| 21495 | // remember the clientY for future calls of _preventOverscrolling |
| 21496 | var _saveClientY = function(event) { |
| 21497 | if (event.targetTouches.length === 1) _previousClientY = event.targetTouches[0].clientY; |
| 21498 | }; |
| 21499 | // prevent the body from scrolling when the user attempts |
| 21500 | // to scroll past the top or bottom of the element |
| 21501 | var _preventOverscrolling = function(event) { |
| 21502 | // only respond to a single-finger touch |
| 21503 | if (event.targetTouches.length !== 1) return; |
| 21504 | // prevent the body touchmove handler from firing |
| 21505 | // so that scrolling is allowed within the element |
| 21506 | event.stopPropagation(); |
| 21507 | if (!_element) return; |
| 21508 | var clientY = event.targetTouches[0].clientY - _previousClientY; |
| 21509 | var scrollableParent = findScrollableParent(event.target); |
| 21510 | if (scrollableParent) _element = scrollableParent; |
| 21511 | // if the element is scrolled to the top, |
| 21512 | // prevent the user from scrolling up |
| 21513 | if (_element.scrollTop === 0 && clientY > 0) event.preventDefault(); |
| 21514 | // if the element is scrolled to the bottom, |
| 21515 | // prevent the user from scrolling down |
| 21516 | if (_element.scrollHeight - Math.ceil(_element.scrollTop) <= _element.clientHeight && clientY < 0) event.preventDefault(); |
| 21517 | }; |
| 21518 | events.on(element, "touchstart", _saveClientY, { |
| 21519 | passive: false |
| 21520 | }); |
| 21521 | events.on(element, "touchmove", _preventOverscrolling, { |
| 21522 | passive: false |
| 21523 | }); |
| 21524 | _element = element; |
| 21525 | }; |
| 21526 | var allowOverscrollOnElement = function(element, events) { |
| 21527 | if (!element) return; |
| 21528 | var _allowElementScroll = function(event) { |