/** * Windows Phone 8.1 fakes user agent string to look like Android and iPhone. * * @type boolean */ var deviceIsWindowsPhone = navigator.userAgent.indexOf("Windows Phone") >= 0;
/** * iOS 4 requires an exception for select elements. * * @type boolean */ var deviceIsIOS4 = deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent);
/** * iOS 6.0-7.* requires the target element to be manually derived * * @type boolean */ var deviceIsIOSWithBadTarget = deviceIsIOS && (/OS [6-7]_\d/).test(navigator.userAgent);
//判断给定元素是否需要通过合成click事件来模拟聚焦 FastClick.prototype.needsFocus = function(target) { switch(target.nodeName.toLowerCase()) { case 'textarea': return true; case 'select': return !deviceIsAndroid; //iOS下的select得走穿透点击才行 case 'input': switch(target.type) { case 'button': case 'checkbox': case 'file': case 'image': case 'radio': case 'submit': return false; }
// Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the // target element was moved to another parent. if(!scrollParent || !scrollParent.contains(targetElement)) { parentElement = targetElement; do { if(parentElement.scrollHeight > parentElement.offsetHeight) { scrollParent = parentElement; targetElement.fastClickScrollParent = parentElement; break; }
parentElement = parentElement.parentElement; } while (parentElement); }