forms-inputnumber-l10n.js 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. // input[type="number"] localized input/output
  2. // // Detects whether input type="number" is capable of receiving and
  3. // // displaying localized numbers, e.g. with comma separator
  4. // // https://bugs.webkit.org/show_bug.cgi?id=42484
  5. // // Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/forms/script-tests/input-number-keyoperation.js?rev=80096#L9
  6. // // By Peter Janes
  7. Modernizr.addTest('localizedNumber', function() {
  8. var doc = document,
  9. el = document.createElement('div'),
  10. fake,
  11. root,
  12. input,
  13. diff;
  14. root = doc.body || (function() {
  15. var de = doc.documentElement;
  16. fake = true;
  17. return de.insertBefore(doc.createElement('body'), de.firstElementChild || de.firstChild);
  18. }());
  19. el.innerHTML = '<input type="number" value="1.0" step="0.1"/>';
  20. input = el.childNodes[0];
  21. root.appendChild(el);
  22. input.focus();
  23. try {
  24. doc.execCommand('InsertText', false, '1,1');
  25. } catch(e) { // prevent warnings in IE
  26. }
  27. diff = input.type === 'number' && input.valueAsNumber === 1.1 && input.checkValidity();
  28. root.removeChild(el);
  29. fake && root.parentNode.removeChild(root);
  30. return diff;
  31. });