1/*! iNoBounce - v0.1.6 2* https://github.com/lazd/iNoBounce/ 3* Copyright (c) 2013 Larry Davis <[email protected]>; Licensed BSD */ 4(function(global) { 5 // Stores the Y position where the touch started 6 var startY = 0; 7 8 // Store enabled status 9 var enabled = false; 10 11 var supportsPassiveOption = false; 12 try { 13 var opts = Object.defineProperty({}, 'passive', { 14 get: function() { 15 supportsPassiveOption = true; 16 } 17 }); 18 window.addEventListener('test', null, opts); 19 } catch (e) {} 20 21 var handleTouchmove = function(evt) { 22 // Get the element that was scrolled upon 23 var el = evt.target; 24 25 // Check all parent elements for scrollability 26 while (el !== document.body && el !== document) { 27 // Get some style properties 28 var style = window.getComputedStyle(el); 29 30 if (!style) { 31 // If we've encountered an element we can't compute the style for, get out 32 break; 33 } 34 35 // Ignore range input element 36 if (el.nodeName === 'INPUT' && el.getAttribute('type') === 'range') { 37 return; 38 } 39 40 var scrolling = style.getPropertyValue('-webkit-overflow-scrolling'); 41 var overflowY = style.getPropertyValue('overflow-y'); 42 var height = parseInt(style.getPropertyValue('height'), 10); 43 44 // Determine if the element should scroll 45 var isScrollable = scrolling === 'touch' && (overflowY === 'auto' || overflowY === 'scroll'); 46 var canScroll = el.scrollHeight > el.offsetHeight; 47 48 if (isScrollable && canScroll) { 49 // Get the current Y position of the touch 50 var curY = evt.touches ? evt.touches[0].screenY : evt.screenY; 51 52 // Determine if the user is trying to scroll past the top or bottom 53 // In this case, the window will bounce, so we have to prevent scrolling completely 54 var isAtTop = (startY <= curY && el.scrollTop === 0); 55 var isAtBottom = (startY >= curY && el.scrollHeight - el.scrollTop === height); 56 57 // Stop a bounce bug when at the bottom or top of the scrollable element 58 if (isAtTop || isAtBottom) { 59 evt.preventDefault(); 60 } 61 62 // No need to continue up the DOM, we've done our job 63 return; 64 } 65 66 // Test the next parent 67 el = el.parentNode; 68 } 69 70 // Stop the bouncing -- no parents are scrollable 71 evt.preventDefault(); 72 }; 73 74 var handleTouchstart = function(evt) { 75 // Store the first Y position of the touch 76 startY = evt.touches ? evt.touches[0].screenY : evt.screenY; 77 }; 78 79 var enable = function() { 80 // Listen to a couple key touch events 81 window.addEventListener('touchstart', handleTouchstart, supportsPassiveOption ? { passive : false } : false); 82 window.addEventListener('touchmove', handleTouchmove, supportsPassiveOption ? { passive : false } : false); 83 enabled = true; 84 }; 85 86 var disable = function() { 87 // Stop listening 88 window.removeEventListener('touchstart', handleTouchstart, false); 89 window.removeEventListener('touchmove', handleTouchmove, false); 90 enabled = false; 91 }; 92 93 var isEnabled = function() { 94 return enabled; 95 }; 96 97 // Enable by default if the browser supports -webkit-overflow-scrolling 98 // Test this by setting the property with JavaScript on an element that exists in the DOM 99 // Then, see if the property is reflected in the computed style 100 var testDiv = document.createElement('div'); 101 document.documentElement.appendChild(testDiv); 102 testDiv.style.WebkitOverflowScrolling = 'touch'; 103 var scrollSupport = 'getComputedStyle' in window && window.getComputedStyle(testDiv)['-webkit-overflow-scrolling'] === 'touch'; 104 document.documentElement.removeChild(testDiv); 105 106 if (scrollSupport) { 107 enable(); 108 } 109 110 // A module to support enabling/disabling iNoBounce 111 var iNoBounce = { 112 enable: enable, 113 disable: disable, 114 isEnabled: isEnabled 115 }; 116 117 if (typeof module !== 'undefined' && module.exports) { 118 // Node.js Support 119 module.exports = iNoBounce; 120 } 121 if (typeof global.define === 'function') { 122 // AMD Support 123 (function(define) { 124 define('iNoBounce', [], function() { return iNoBounce; }); 125 }(global.define)); 126 } 127 else { 128 // Browser support 129 global.iNoBounce = iNoBounce; 130 } 131}(this));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.