input.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*!
  2. {
  3. "name": "Input attributes",
  4. "property": "input",
  5. "tags": ["forms"],
  6. "authors": ["Mike Taylor"],
  7. "notes": [{
  8. "name": "WHATWG Spec",
  9. "href": "https://html.spec.whatwg.org/multipage/input.html#input-type-attr-summary"
  10. }],
  11. "knownBugs": ["Some blackberry devices report false positive for input.multiple"]
  12. }
  13. !*/
  14. /* DOC
  15. Detects support for HTML5 `<input>` element attributes and exposes Boolean subproperties with the results:
  16. ```javascript
  17. Modernizr.input.autocomplete
  18. Modernizr.input.autofocus
  19. Modernizr.input.list
  20. Modernizr.input.max
  21. Modernizr.input.min
  22. Modernizr.input.multiple
  23. Modernizr.input.pattern
  24. Modernizr.input.placeholder
  25. Modernizr.input.required
  26. Modernizr.input.step
  27. ```
  28. */
  29. define(['Modernizr', 'createElement', 'inputElem'], function(Modernizr, createElement, inputElem) {
  30. // Run through HTML5's new input attributes to see if the UA understands any.
  31. // Mike Taylr has created a comprehensive resource for testing these attributes
  32. // when applied to all input types:
  33. // miketaylr.com/code/input-type-attr.html
  34. // Only input placeholder is tested while textarea's placeholder is not.
  35. // Currently Safari 4 and Opera 11 have support only for the input placeholder
  36. // Both tests are available in feature-detects/forms-placeholder.js
  37. var inputattrs = 'autocomplete autofocus list placeholder max min multiple pattern required step'.split(' ');
  38. var attrs = {};
  39. Modernizr.input = (function(props) {
  40. for (var i = 0, len = props.length; i < len; i++) {
  41. attrs[ props[i] ] = !!(props[i] in inputElem);
  42. }
  43. if (attrs.list) {
  44. // safari false positive's on datalist: webk.it/74252
  45. // see also github.com/Modernizr/Modernizr/issues/146
  46. attrs.list = !!(createElement('datalist') && window.HTMLDataListElement);
  47. }
  48. return attrs;
  49. })(inputattrs);
  50. });