diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..486043ae --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +## [bugfix keybaord not shown up instantly in ios 11.3](https://github.com/ant-ife/fastclick/pull/1) (2018-05-31) diff --git a/lib/fastclick.js b/lib/fastclick.js index 86bf83e0..61a8538a 100644 --- a/lib/fastclick.js +++ b/lib/fastclick.js @@ -203,6 +203,54 @@ */ var deviceIsIOS4 = deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent); + /** + * compareVersion + * returns: + * == 0: v1 = v2 + * > 0 : v1 > v2 + * < 0 : v1 < v2 + * + * @type number + */ + var compareVersion = function (v1, v2) { + var arr1 = v1.split('_') + var arr2 = v2.split('_') + var minLength = Math.min(arr1.length, arr2.length) + var position = 0 + var diff = 0 + + while (position < minLength) { + diff = parseInt(arr1[position]) - parseInt(arr2[position]) + + if (diff !== 0) { + break + } + + position++ + } + + diff = (diff !== 0) ? diff : (arr1.length - arr2.length) + + return diff + } + + /** + * above iOS 11_3 + * + * @type boolean + */ + var deviceAboveIOS11_3 = (function aboveIOS11_3 () { + if (!deviceIsIOS) { + return false + } + var version = '11_3' + var matches = navigator.userAgent.match(/CPU iPhone OS ([0-9_]+)/) + if (matches && matches[1]) { + return compareVersion(matches[1], version) >= 0 + } else { + return false + } + })() /** * iOS 6.0-7.* requires the target element to be manually derived @@ -327,6 +375,11 @@ // Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724. if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month' && targetElement.type !== 'email') { + /** + * bugfix: keybaord not shown up instantly in ios 11.3 + */ + deviceAboveIOS11_3 && targetElement.focus(); + length = targetElement.value.length; targetElement.setSelectionRange(length, length); } else { diff --git a/package.json b/package.json index ef62a337..d4baa1a3 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "fastclick", + "name": "ant-ife/fastclick", "version": "1.0.6", "description": "Polyfill to remove click delays on browsers with touch UIs.", "maintainers": [ @@ -21,12 +21,20 @@ { "name": "Matthew Caruana Galizia", "email": "m@m.cg" + }, + { + "name": "Bruce Jia", + "email": "bruce.jcw@gmail.com" + }, + { + "name": "David Tse", + "email": "xiekw2010@gmail.com" } ], "main": "lib/fastclick.js", "repository": { "type": "git", - "url": "git://github.com/ftlabs/fastclick.git" + "url": "git://github.com/ant-ife/fastclick.git" }, "keywords": [ "fastclick", @@ -45,5 +53,5 @@ "implements": [ "CommonJS/Modules/1.0" ], - "homepage": "https://github.com/ftlabs/fastclick" + "homepage": "https://github.com/ant-ife/fastclick" }