Skip to content
This repository was archived by the owner on Jun 9, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## [bugfix keybaord not shown up instantly in ios 11.3](https://github.com/ant-ife/fastclick/pull/1) (2018-05-31)
53 changes: 53 additions & 0 deletions lib/fastclick.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -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",
Expand All @@ -45,5 +53,5 @@
"implements": [
"CommonJS/Modules/1.0"
],
"homepage": "https://github.com/ftlabs/fastclick"
"homepage": "https://github.com/ant-ife/fastclick"
}