forked from Modernizr/Modernizr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detects localized input/output for input[type="number"]
- Loading branch information
1 parent
6f2d295
commit 9b6f02a
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// input[type="number"] localized input/output | ||
// // Detects whether input type="number" is capable of receiving and | ||
// // displaying localized numbers, e.g. with comma separator | ||
// // https://bugs.webkit.org/show_bug.cgi?id=42484 | ||
// // Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/forms/script-tests/input-number-keyoperation.js?rev=80096#L9 | ||
// // By Peter Janes | ||
|
||
Modernizr.addTest('localizedNumber', function() { | ||
var doc = document, | ||
el = document.createElement('div'), | ||
fake, | ||
root, | ||
input, | ||
diff; | ||
root = doc.body || (function() { | ||
var de = doc.documentElement; | ||
fake = true; | ||
return de.insertBefore(doc.createElement('body'), de.firstElementChild || de.firstChild); | ||
}()); | ||
el.innerHTML = '<input type="number" value="1.0" step="0.1"/>'; | ||
input = el.childNodes[0]; | ||
root.appendChild(el); | ||
input.focus(); | ||
doc.execCommand('InsertText', false, '1,1'); | ||
diff = input.type === 'number' && input.valueAsNumber === 1.1 && input.checkValidity(); | ||
root.removeChild(el); | ||
fake && root.parentNode.removeChild(root); | ||
console.log(diff); | ||
return diff; | ||
}); |