@polymer/iron-overlay-behavior
Advanced tools
Comparing version 3.0.0-pre.8 to 3.0.0-pre.10
{ | ||
"name": "iron-overlay-behavior", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"license": "http://polymer.github.io/LICENSE.txt", | ||
@@ -5,0 +5,0 @@ "description": "Provides a behavior for making an element an overlay", |
@@ -15,3 +15,3 @@ import '../polymer/polymer.js'; | ||
* @param {!Node} node | ||
* @return {Array<HTMLElement>} | ||
* @return {!Array<!HTMLElement>} | ||
*/ | ||
@@ -88,3 +88,3 @@ getTabbableNodes: function(node) { | ||
* if tabbable. | ||
* @param {!Array<HTMLElement>} result | ||
* @param {!Array<!HTMLElement>} result | ||
* @return {boolean} | ||
@@ -98,3 +98,3 @@ * @private | ||
} | ||
var element = /** @type {HTMLElement} */ (node); | ||
var element = /** @type {!HTMLElement} */ (node); | ||
var tabIndex = this._normalizedTabIndex(element); | ||
@@ -152,4 +152,4 @@ var needsSort = tabIndex > 0; | ||
* Sorts an array of tabbable elements by tabindex. Returns a new array. | ||
* @param {!Array<HTMLElement>} tabbables | ||
* @return {Array<HTMLElement>} | ||
* @param {!Array<!HTMLElement>} tabbables | ||
* @return {!Array<!HTMLElement>} | ||
* @private | ||
@@ -172,5 +172,5 @@ */ | ||
* Merge sort iterator, merges the two arrays into one, sorted by tab index. | ||
* @param {!Array<HTMLElement>} left | ||
* @param {!Array<HTMLElement>} right | ||
* @return {Array<HTMLElement>} | ||
* @param {!Array<!HTMLElement>} left | ||
* @param {!Array<!HTMLElement>} right | ||
* @return {!Array<!HTMLElement>} | ||
* @private | ||
@@ -177,0 +177,0 @@ */ |
@@ -5,5 +5,6 @@ import '../polymer/polymer.js'; | ||
import { IronOverlayManager } from './iron-overlay-manager.js'; | ||
import { IronScrollManager } from './iron-scroll-manager.js'; | ||
import { removeScrollLock, pushScrollLock } from './iron-scroll-manager.js'; | ||
import { IronFocusablesHelper } from './iron-focusables-helper.js'; | ||
import { dom } from '../polymer/lib/legacy/polymer.dom.js'; | ||
import { useShadow } from '../polymer/lib/utils/settings.js'; | ||
@@ -88,3 +89,3 @@ export const IronOverlayBehaviorImpl = { | ||
/** | ||
* Set to true to allow clicks to go through overlays. | ||
* Set to true to allow clicks to go through overlays. | ||
* When the user clicks outside this overlay, the click may | ||
@@ -118,3 +119,3 @@ * close the overlay below. | ||
* @private | ||
* @type {Polymer.IronOverlayManagerClass} | ||
* @type {!Polymer.IronOverlayManagerClass} | ||
*/ | ||
@@ -146,3 +147,3 @@ _manager: { | ||
* The backdrop element. | ||
* @type {Element} | ||
* @return {!Element} | ||
*/ | ||
@@ -155,3 +156,3 @@ get backdropElement() { | ||
* Returns the node to give focus to. | ||
* @type {Node} | ||
* @return {!Node} | ||
*/ | ||
@@ -169,3 +170,3 @@ get _focusNode() { | ||
* you can override this method to return only `[firstFocusable, lastFocusable];` | ||
* @type {Array<Node>} | ||
* @return {!Array<!Node>} | ||
* @protected | ||
@@ -177,2 +178,5 @@ */ | ||
/** | ||
* @return {void} | ||
*/ | ||
ready: function() { | ||
@@ -622,3 +626,3 @@ // Used to skip calls to notifyResize and refit while the overlay is animating. | ||
if (!isAttached || !opened || !this.__isValidScrollAction(scrollAction)) { | ||
IronScrollManager.removeScrollLock(this); | ||
removeScrollLock(this); | ||
this.__removeScrollListeners(); | ||
@@ -628,3 +632,3 @@ } else { | ||
this.__saveScrollPosition(); | ||
IronScrollManager.pushScrollLock(this); | ||
pushScrollLock(this); | ||
} | ||
@@ -634,3 +638,3 @@ this.__addScrollListeners(); | ||
}, | ||
/** | ||
@@ -644,3 +648,3 @@ * @private | ||
// when in native ShadowDOM. | ||
if ('attachShadow' in Element.prototype && 'getRootNode' in Element.prototype) { | ||
if (useShadow) { | ||
var node = this; | ||
@@ -663,3 +667,3 @@ while (node) { | ||
}, | ||
/** | ||
@@ -666,0 +670,0 @@ * @private |
@@ -10,3 +10,3 @@ import '../polymer/polymer.js'; | ||
* Used to keep track of the opened overlays. | ||
* @private {Array<Element>} | ||
* @private {!Array<!Element>} | ||
*/ | ||
@@ -47,3 +47,3 @@ this._overlays = []; | ||
* The shared backdrop element. | ||
* @type {!Element} backdropElement | ||
* @return {!Element} backdropElement | ||
*/ | ||
@@ -59,3 +59,3 @@ get backdropElement() { | ||
* The deepest active element. | ||
* @type {!Element} activeElement the active element | ||
* @return {!Element} activeElement the active element | ||
*/ | ||
@@ -175,3 +175,3 @@ get deepActiveElement() { | ||
* Returns the current overlay. | ||
* @return {Element|undefined} | ||
* @return {!Element|undefined} | ||
*/ | ||
@@ -225,3 +225,3 @@ currentOverlay: function() { | ||
/** | ||
* @return {Array<Element>} | ||
* @return {!Array<!Element>} | ||
*/ | ||
@@ -248,3 +248,3 @@ getBackdrops: function() { | ||
* Returns the top opened overlay that has a backdrop. | ||
* @return {Element|undefined} | ||
* @return {!Element|undefined} | ||
* @private | ||
@@ -298,4 +298,4 @@ */ | ||
* Returns the deepest overlay in the path. | ||
* @param {Array<Element>=} path | ||
* @return {Element|undefined} | ||
* @param {!Array<!Element>=} path | ||
* @return {!Element|undefined} | ||
* @suppress {missingProperties} | ||
@@ -321,3 +321,3 @@ * @private | ||
if (i === -1) return; | ||
var path = dom(event).path; | ||
var path = /** @type {!Array<!EventTarget>} */ (dom(event).path); | ||
var overlay; | ||
@@ -324,0 +324,0 @@ // Check if clicked outside of overlay. |
@@ -17,3 +17,3 @@ import '../polymer/polymer.js'; | ||
/** | ||
* @type {!Array<Node>} | ||
* @type {!Array<!Node>} | ||
*/ | ||
@@ -36,327 +36,259 @@ var lastScrollableNodes = []; | ||
export const IronScrollManager = { | ||
export function currentLockingElement() { | ||
return _lockingElements[_lockingElements.length - 1]; | ||
} | ||
/** | ||
* The current element that defines the DOM boundaries of the | ||
* scroll lock. This is always the most recently locking element. | ||
*/ | ||
get currentLockingElement() { | ||
return this._lockingElements[this._lockingElements.length - 1]; | ||
}, | ||
export function elementIsScrollLocked(element) { | ||
var currentLockingElement = currentLockingElement; | ||
/** | ||
* Returns true if the provided element is "scroll locked", which is to | ||
* say that it cannot be scrolled via pointer or keyboard interactions. | ||
* | ||
* @param {HTMLElement} element An HTML element instance which may or may | ||
* not be scroll locked. | ||
*/ | ||
elementIsScrollLocked: function(element) { | ||
var currentLockingElement = this.currentLockingElement; | ||
if (currentLockingElement === undefined) | ||
return false; | ||
if (currentLockingElement === undefined) | ||
return false; | ||
var scrollLocked; | ||
var scrollLocked; | ||
if (_hasCachedLockedElement(element)) { | ||
return true; | ||
} | ||
if (this._hasCachedLockedElement(element)) { | ||
return true; | ||
} | ||
if (_hasCachedUnlockedElement(element)) { | ||
return false; | ||
} | ||
if (this._hasCachedUnlockedElement(element)) { | ||
return false; | ||
} | ||
scrollLocked = !!currentLockingElement && | ||
currentLockingElement !== element && | ||
!_composedTreeContains(currentLockingElement, element); | ||
scrollLocked = !!currentLockingElement && | ||
currentLockingElement !== element && | ||
!this._composedTreeContains(currentLockingElement, element); | ||
if (scrollLocked) { | ||
_lockedElementCache.push(element); | ||
} else { | ||
_unlockedElementCache.push(element); | ||
} | ||
if (scrollLocked) { | ||
this._lockedElementCache.push(element); | ||
} else { | ||
this._unlockedElementCache.push(element); | ||
} | ||
return scrollLocked; | ||
} | ||
return scrollLocked; | ||
}, | ||
export function pushScrollLock(element) { | ||
// Prevent pushing the same element twice | ||
if (_lockingElements.indexOf(element) >= 0) { | ||
return; | ||
} | ||
/** | ||
* Push an element onto the current scroll lock stack. The most recently | ||
* pushed element and its children will be considered scrollable. All | ||
* other elements will not be scrollable. | ||
* | ||
* Scroll locking is implemented as a stack so that cases such as | ||
* dropdowns within dropdowns are handled well. | ||
* | ||
* @param {HTMLElement} element The element that should lock scroll. | ||
*/ | ||
pushScrollLock: function(element) { | ||
// Prevent pushing the same element twice | ||
if (this._lockingElements.indexOf(element) >= 0) { | ||
return; | ||
} | ||
if (_lockingElements.length === 0) { | ||
_lockScrollInteractions(); | ||
} | ||
if (this._lockingElements.length === 0) { | ||
this._lockScrollInteractions(); | ||
} | ||
_lockingElements.push(element); | ||
this._lockingElements.push(element); | ||
_lockedElementCache = []; | ||
_unlockedElementCache = []; | ||
} | ||
this._lockedElementCache = []; | ||
this._unlockedElementCache = []; | ||
}, | ||
export function removeScrollLock(element) { | ||
var index = _lockingElements.indexOf(element); | ||
/** | ||
* Remove an element from the scroll lock stack. The element being | ||
* removed does not need to be the most recently pushed element. However, | ||
* the scroll lock constraints only change when the most recently pushed | ||
* element is removed. | ||
* | ||
* @param {HTMLElement} element The element to remove from the scroll | ||
* lock stack. | ||
*/ | ||
removeScrollLock: function(element) { | ||
var index = this._lockingElements.indexOf(element); | ||
if (index === -1) { | ||
return; | ||
} | ||
if (index === -1) { | ||
return; | ||
} | ||
_lockingElements.splice(index, 1); | ||
this._lockingElements.splice(index, 1); | ||
_lockedElementCache = []; | ||
_unlockedElementCache = []; | ||
this._lockedElementCache = []; | ||
this._unlockedElementCache = []; | ||
if (_lockingElements.length === 0) { | ||
_unlockScrollInteractions(); | ||
} | ||
} | ||
if (this._lockingElements.length === 0) { | ||
this._unlockScrollInteractions(); | ||
} | ||
}, | ||
export const _lockingElements = []; | ||
export const _lockedElementCache = null; | ||
export const _unlockedElementCache = null; | ||
_lockingElements: [], | ||
export function _hasCachedLockedElement(element) { | ||
return _lockedElementCache.indexOf(element) > -1; | ||
} | ||
_lockedElementCache: null, | ||
export function _hasCachedUnlockedElement(element) { | ||
return _unlockedElementCache.indexOf(element) > -1; | ||
} | ||
_unlockedElementCache: null, | ||
export function _composedTreeContains(element, child) { | ||
// NOTE(cdata): This method iterates over content elements and their | ||
// corresponding distributed nodes to implement a contains-like method | ||
// that pierces through the composed tree of the ShadowDOM. Results of | ||
// this operation are cached (elsewhere) on a per-scroll-lock basis, to | ||
// guard against potentially expensive lookups happening repeatedly as | ||
// a user scrolls / touchmoves. | ||
var contentElements; | ||
var distributedNodes; | ||
var contentIndex; | ||
var nodeIndex; | ||
_hasCachedLockedElement: function(element) { | ||
return this._lockedElementCache.indexOf(element) > -1; | ||
}, | ||
if (element.contains(child)) { | ||
return true; | ||
} | ||
_hasCachedUnlockedElement: function(element) { | ||
return this._unlockedElementCache.indexOf(element) > -1; | ||
}, | ||
contentElements = dom(element).querySelectorAll('content,slot'); | ||
_composedTreeContains: function(element, child) { | ||
// NOTE(cdata): This method iterates over content elements and their | ||
// corresponding distributed nodes to implement a contains-like method | ||
// that pierces through the composed tree of the ShadowDOM. Results of | ||
// this operation are cached (elsewhere) on a per-scroll-lock basis, to | ||
// guard against potentially expensive lookups happening repeatedly as | ||
// a user scrolls / touchmoves. | ||
var contentElements; | ||
var distributedNodes; | ||
var contentIndex; | ||
var nodeIndex; | ||
for (contentIndex = 0; contentIndex < contentElements.length; ++contentIndex) { | ||
if (element.contains(child)) { | ||
return true; | ||
} | ||
distributedNodes = dom(contentElements[contentIndex]).getDistributedNodes(); | ||
contentElements = dom(element).querySelectorAll('content,slot'); | ||
for (nodeIndex = 0; nodeIndex < distributedNodes.length; ++nodeIndex) { | ||
// Polymer 2.x returns slot.assignedNodes which can contain text nodes. | ||
if (distributedNodes[nodeIndex].nodeType !== Node.ELEMENT_NODE) continue; | ||
for (contentIndex = 0; contentIndex < contentElements.length; ++contentIndex) { | ||
distributedNodes = dom(contentElements[contentIndex]).getDistributedNodes(); | ||
for (nodeIndex = 0; nodeIndex < distributedNodes.length; ++nodeIndex) { | ||
// Polymer 2.x returns slot.assignedNodes which can contain text nodes. | ||
if (distributedNodes[nodeIndex].nodeType !== Node.ELEMENT_NODE) continue; | ||
if (this._composedTreeContains(distributedNodes[nodeIndex], child)) { | ||
return true; | ||
} | ||
if (_composedTreeContains(distributedNodes[nodeIndex], child)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}, | ||
return false; | ||
} | ||
_scrollInteractionHandler: function(event) { | ||
// Avoid canceling an event with cancelable=false, e.g. scrolling is in | ||
// progress and cannot be interrupted. | ||
if (event.cancelable && this._shouldPreventScrolling(event)) { | ||
event.preventDefault(); | ||
} | ||
// If event has targetTouches (touch event), update last touch position. | ||
if (event.targetTouches) { | ||
var touch = event.targetTouches[0]; | ||
lastTouchPosition.pageX = touch.pageX; | ||
lastTouchPosition.pageY = touch.pageY; | ||
} | ||
}, | ||
export function _scrollInteractionHandler(event) { | ||
// Avoid canceling an event with cancelable=false, e.g. scrolling is in | ||
// progress and cannot be interrupted. | ||
if (event.cancelable && _shouldPreventScrolling(event)) { | ||
event.preventDefault(); | ||
} | ||
// If event has targetTouches (touch event), update last touch position. | ||
if (event.targetTouches) { | ||
var touch = event.targetTouches[0]; | ||
lastTouchPosition.pageX = touch.pageX; | ||
lastTouchPosition.pageY = touch.pageY; | ||
} | ||
} | ||
_lockScrollInteractions: function() { | ||
this._boundScrollHandler = this._boundScrollHandler || | ||
this._scrollInteractionHandler.bind(this); | ||
for (var i = 0, l = scrollEvents.length; i < l; i++) { | ||
// NOTE: browsers that don't support objects as third arg will | ||
// interpret it as boolean, hence useCapture = true in this case. | ||
document.addEventListener(scrollEvents[i], this._boundScrollHandler, { | ||
capture: true, | ||
passive: false | ||
}); | ||
} | ||
}, | ||
export function _lockScrollInteractions() { | ||
_boundScrollHandler = _boundScrollHandler || | ||
_scrollInteractionHandler.bind(Polymer.IronScrollManager); | ||
for (var i = 0, l = scrollEvents.length; i < l; i++) { | ||
// NOTE: browsers that don't support objects as third arg will | ||
// interpret it as boolean, hence useCapture = true in this case. | ||
document.addEventListener(scrollEvents[i], _boundScrollHandler, { | ||
capture: true, | ||
passive: false | ||
}); | ||
} | ||
} | ||
_unlockScrollInteractions: function() { | ||
for (var i = 0, l = scrollEvents.length; i < l; i++) { | ||
// NOTE: browsers that don't support objects as third arg will | ||
// interpret it as boolean, hence useCapture = true in this case. | ||
document.removeEventListener(scrollEvents[i], this._boundScrollHandler, { | ||
capture: true, | ||
passive: false | ||
}); | ||
} | ||
}, | ||
export function _unlockScrollInteractions() { | ||
for (var i = 0, l = scrollEvents.length; i < l; i++) { | ||
// NOTE: browsers that don't support objects as third arg will | ||
// interpret it as boolean, hence useCapture = true in this case. | ||
document.removeEventListener(scrollEvents[i], _boundScrollHandler, { | ||
capture: true, | ||
passive: false | ||
}); | ||
} | ||
} | ||
/** | ||
* Returns true if the event causes scroll outside the current locking | ||
* element, e.g. pointer/keyboard interactions, or scroll "leaking" | ||
* outside the locking element when it is already at its scroll boundaries. | ||
* @param {!Event} event | ||
* @return {boolean} | ||
* @private | ||
*/ | ||
_shouldPreventScrolling: function(event) { | ||
export function _shouldPreventScrolling(event) { | ||
// Update if root target changed. For touch events, ensure we don't | ||
// update during touchmove. | ||
var target = dom(event).rootTarget; | ||
if (event.type !== 'touchmove' && lastRootTarget !== target) { | ||
lastRootTarget = target; | ||
lastScrollableNodes = this._getScrollableNodes(dom(event).path); | ||
} | ||
// Update if root target changed. For touch events, ensure we don't | ||
// update during touchmove. | ||
var target = dom(event).rootTarget; | ||
if (event.type !== 'touchmove' && lastRootTarget !== target) { | ||
lastRootTarget = target; | ||
lastScrollableNodes = _getScrollableNodes(dom(event).path); | ||
} | ||
// Prevent event if no scrollable nodes. | ||
if (!lastScrollableNodes.length) { | ||
return true; | ||
} | ||
// Don't prevent touchstart event inside the locking element when it has | ||
// scrollable nodes. | ||
if (event.type === 'touchstart') { | ||
return false; | ||
} | ||
// Get deltaX/Y. | ||
var info = this._getScrollInfo(event); | ||
// Prevent if there is no child that can scroll. | ||
return !this._getScrollingNode(lastScrollableNodes, info.deltaX, info.deltaY); | ||
}, | ||
// Prevent event if no scrollable nodes. | ||
if (!lastScrollableNodes.length) { | ||
return true; | ||
} | ||
// Don't prevent touchstart event inside the locking element when it has | ||
// scrollable nodes. | ||
if (event.type === 'touchstart') { | ||
return false; | ||
} | ||
// Get deltaX/Y. | ||
var info = _getScrollInfo(event); | ||
// Prevent if there is no child that can scroll. | ||
return !_getScrollingNode(lastScrollableNodes, info.deltaX, info.deltaY); | ||
} | ||
/** | ||
* Returns an array of scrollable nodes up to the current locking element, | ||
* which is included too if scrollable. | ||
* @param {!Array<Node>} nodes | ||
* @return {Array<Node>} scrollables | ||
* @private | ||
*/ | ||
_getScrollableNodes: function(nodes) { | ||
var scrollables = []; | ||
var lockingIndex = nodes.indexOf(this.currentLockingElement); | ||
// Loop from root target to locking element (included). | ||
for (var i = 0; i <= lockingIndex; i++) { | ||
// Skip non-Element nodes. | ||
if (nodes[i].nodeType !== Node.ELEMENT_NODE) { | ||
continue; | ||
} | ||
var node = /** @type {!Element} */ (nodes[i]); | ||
// Check inline style before checking computed style. | ||
var style = node.style; | ||
if (style.overflow !== 'scroll' && style.overflow !== 'auto') { | ||
style = window.getComputedStyle(node); | ||
} | ||
if (style.overflow === 'scroll' || style.overflow === 'auto') { | ||
scrollables.push(node); | ||
} | ||
export function _getScrollableNodes(nodes) { | ||
var scrollables = []; | ||
var lockingIndex = nodes.indexOf(currentLockingElement); | ||
// Loop from root target to locking element (included). | ||
for (var i = 0; i <= lockingIndex; i++) { | ||
// Skip non-Element nodes. | ||
if (nodes[i].nodeType !== Node.ELEMENT_NODE) { | ||
continue; | ||
} | ||
return scrollables; | ||
}, | ||
/** | ||
* Returns the node that is scrolling. If there is no scrolling, | ||
* returns undefined. | ||
* @param {!Array<Node>} nodes | ||
* @param {number} deltaX Scroll delta on the x-axis | ||
* @param {number} deltaY Scroll delta on the y-axis | ||
* @return {Node|undefined} | ||
* @private | ||
*/ | ||
_getScrollingNode: function(nodes, deltaX, deltaY) { | ||
// No scroll. | ||
if (!deltaX && !deltaY) { | ||
return; | ||
var node = /** @type {!Element} */ (nodes[i]); | ||
// Check inline style before checking computed style. | ||
var style = node.style; | ||
if (style.overflow !== 'scroll' && style.overflow !== 'auto') { | ||
style = window.getComputedStyle(node); | ||
} | ||
// Check only one axis according to where there is more scroll. | ||
// Prefer vertical to horizontal. | ||
var verticalScroll = Math.abs(deltaY) >= Math.abs(deltaX); | ||
for (var i = 0; i < nodes.length; i++) { | ||
var node = nodes[i]; | ||
var canScroll = false; | ||
if (verticalScroll) { | ||
// delta < 0 is scroll up, delta > 0 is scroll down. | ||
canScroll = deltaY < 0 ? node.scrollTop > 0 : | ||
node.scrollTop < node.scrollHeight - node.clientHeight; | ||
} else { | ||
// delta < 0 is scroll left, delta > 0 is scroll right. | ||
canScroll = deltaX < 0 ? node.scrollLeft > 0 : | ||
node.scrollLeft < node.scrollWidth - node.clientWidth; | ||
} | ||
if (canScroll) { | ||
return node; | ||
} | ||
if (style.overflow === 'scroll' || style.overflow === 'auto') { | ||
scrollables.push(node); | ||
} | ||
}, | ||
} | ||
return scrollables; | ||
} | ||
/** | ||
* Returns scroll `deltaX` and `deltaY`. | ||
* @param {!Event} event The scroll event | ||
* @return {{deltaX: number, deltaY: number}} Object containing the | ||
* x-axis scroll delta (positive: scroll right, negative: scroll left, | ||
* 0: no scroll), and the y-axis scroll delta (positive: scroll down, | ||
* negative: scroll up, 0: no scroll). | ||
* @private | ||
*/ | ||
_getScrollInfo: function(event) { | ||
var info = { | ||
deltaX: event.deltaX, | ||
deltaY: event.deltaY | ||
}; | ||
// Already available. | ||
if ('deltaX' in event) { | ||
// do nothing, values are already good. | ||
export function _getScrollingNode(nodes, deltaX, deltaY) { | ||
// No scroll. | ||
if (!deltaX && !deltaY) { | ||
return; | ||
} | ||
// Check only one axis according to where there is more scroll. | ||
// Prefer vertical to horizontal. | ||
var verticalScroll = Math.abs(deltaY) >= Math.abs(deltaX); | ||
for (var i = 0; i < nodes.length; i++) { | ||
var node = nodes[i]; | ||
var canScroll = false; | ||
if (verticalScroll) { | ||
// delta < 0 is scroll up, delta > 0 is scroll down. | ||
canScroll = deltaY < 0 ? node.scrollTop > 0 : | ||
node.scrollTop < node.scrollHeight - node.clientHeight; | ||
} else { | ||
// delta < 0 is scroll left, delta > 0 is scroll right. | ||
canScroll = deltaX < 0 ? node.scrollLeft > 0 : | ||
node.scrollLeft < node.scrollWidth - node.clientWidth; | ||
} | ||
// Safari has scroll info in `wheelDeltaX/Y`. | ||
else if ('wheelDeltaX' in event && 'wheelDeltaY' in event) { | ||
info.deltaX = -event.wheelDeltaX; | ||
info.deltaY = -event.wheelDeltaY; | ||
if (canScroll) { | ||
return node; | ||
} | ||
// IE10 has only vertical scroll info in `wheelDelta`. | ||
else if ('wheelDelta' in event) { | ||
info.deltaX = 0; | ||
info.deltaY = -event.wheelDelta; | ||
} | ||
// Firefox has scroll info in `detail` and `axis`. | ||
else if ('axis' in event) { | ||
info.deltaX = event.axis === 1 ? event.detail : 0; | ||
info.deltaY = event.axis === 2 ? event.detail : 0; | ||
} | ||
// On mobile devices, calculate scroll direction. | ||
else if (event.targetTouches) { | ||
var touch = event.targetTouches[0]; | ||
// Touch moves from right to left => scrolling goes right. | ||
info.deltaX = lastTouchPosition.pageX - touch.pageX; | ||
// Touch moves from down to up => scrolling goes down. | ||
info.deltaY = lastTouchPosition.pageY - touch.pageY; | ||
} | ||
return info; | ||
} | ||
}; | ||
} | ||
export function _getScrollInfo(event) { | ||
var info = { | ||
deltaX: event.deltaX, | ||
deltaY: event.deltaY | ||
}; | ||
// Already available. | ||
if ('deltaX' in event) { | ||
// do nothing, values are already good. | ||
} | ||
// Safari has scroll info in `wheelDeltaX/Y`. | ||
else if ('wheelDeltaX' in event && 'wheelDeltaY' in event) { | ||
info.deltaX = -event.wheelDeltaX; | ||
info.deltaY = -event.wheelDeltaY; | ||
} | ||
// IE10 has only vertical scroll info in `wheelDelta`. | ||
else if ('wheelDelta' in event) { | ||
info.deltaX = 0; | ||
info.deltaY = -event.wheelDelta; | ||
} | ||
// Firefox has scroll info in `detail` and `axis`. | ||
else if ('axis' in event) { | ||
info.deltaX = event.axis === 1 ? event.detail : 0; | ||
info.deltaY = event.axis === 2 ? event.detail : 0; | ||
} | ||
// On mobile devices, calculate scroll direction. | ||
else if (event.targetTouches) { | ||
var touch = event.targetTouches[0]; | ||
// Touch moves from right to left => scrolling goes right. | ||
info.deltaX = lastTouchPosition.pageX - touch.pageX; | ||
// Touch moves from down to up => scrolling goes down. | ||
info.deltaY = lastTouchPosition.pageY - touch.pageY; | ||
} | ||
return info; | ||
} |
{ | ||
"name": "@polymer/iron-overlay-behavior", | ||
"flat": true, | ||
"version": "3.0.0-pre.8", | ||
"version": "3.0.0-pre.10", | ||
"description": "Provides a behavior for making an element an overlay", | ||
@@ -22,12 +22,12 @@ "contributors": [ | ||
"dependencies": { | ||
"@polymer/iron-a11y-keys-behavior": "^3.0.0-pre.7", | ||
"@polymer/iron-fit-behavior": "^3.0.0-pre.7", | ||
"@polymer/iron-resizable-behavior": "^3.0.0-pre.7", | ||
"@polymer/polymer": "^3.0.0-pre.7" | ||
"@polymer/iron-a11y-keys-behavior": "^3.0.0-pre.10", | ||
"@polymer/iron-fit-behavior": "^3.0.0-pre.10", | ||
"@polymer/iron-resizable-behavior": "^3.0.0-pre.10", | ||
"@polymer/polymer": "^3.0.0-pre.10" | ||
}, | ||
"devDependencies": { | ||
"@polymer/iron-component-page": "^3.0.0-pre.7", | ||
"@polymer/iron-demo-helpers": "^3.0.0-pre.7", | ||
"@polymer/iron-flex-layout": "^3.0.0-pre.7", | ||
"@polymer/iron-test-helpers": "^3.0.0-pre.7", | ||
"@polymer/iron-component-page": "^3.0.0-pre.10", | ||
"@polymer/iron-demo-helpers": "^3.0.0-pre.10", | ||
"@polymer/iron-flex-layout": "^3.0.0-pre.10", | ||
"@polymer/iron-test-helpers": "^3.0.0-pre.10", | ||
"wct-browser-legacy": "0.0.1-pre.11", | ||
@@ -34,0 +34,0 @@ "@webcomponents/webcomponentsjs": "^1.0.0" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1984
102386
20