support.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. jQuery.support = (function( support ) {
  2. var input = document.createElement("input"),
  3. fragment = document.createDocumentFragment(),
  4. div = document.createElement("div"),
  5. select = document.createElement("select"),
  6. opt = select.appendChild( document.createElement("option") );
  7. // Finish early in limited environments
  8. if ( !input.type ) {
  9. return support;
  10. }
  11. input.type = "checkbox";
  12. // Support: Safari 5.1, iOS 5.1, Android 4.x, Android 2.3
  13. // Check the default checkbox/radio value ("" on old WebKit; "on" elsewhere)
  14. support.checkOn = input.value !== "";
  15. // Must access the parent to make an option select properly
  16. // Support: IE9, IE10
  17. support.optSelected = opt.selected;
  18. // Will be defined later
  19. support.reliableMarginRight = true;
  20. support.boxSizingReliable = true;
  21. support.pixelPosition = false;
  22. // Make sure checked status is properly cloned
  23. // Support: IE9, IE10
  24. input.checked = true;
  25. support.noCloneChecked = input.cloneNode( true ).checked;
  26. // Make sure that the options inside disabled selects aren't marked as disabled
  27. // (WebKit marks them as disabled)
  28. select.disabled = true;
  29. support.optDisabled = !opt.disabled;
  30. // Check if an input maintains its value after becoming a radio
  31. // Support: IE9, IE10
  32. input = document.createElement("input");
  33. input.value = "t";
  34. input.type = "radio";
  35. support.radioValue = input.value === "t";
  36. // #11217 - WebKit loses check when the name is after the checked attribute
  37. input.setAttribute( "checked", "t" );
  38. input.setAttribute( "name", "t" );
  39. fragment.appendChild( input );
  40. // Support: Safari 5.1, Android 4.x, Android 2.3
  41. // old WebKit doesn't clone checked state correctly in fragments
  42. support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked;
  43. // Support: Firefox, Chrome, Safari
  44. // Beware of CSP restrictions (https://developer.mozilla.org/en/Security/CSP)
  45. support.focusinBubbles = "onfocusin" in window;
  46. div.style.backgroundClip = "content-box";
  47. div.cloneNode( true ).style.backgroundClip = "";
  48. support.clearCloneStyle = div.style.backgroundClip === "content-box";
  49. // Run tests that need a body at doc ready
  50. jQuery(function() {
  51. var container, marginDiv,
  52. // Support: Firefox, Android 2.3 (Prefixed box-sizing versions).
  53. divReset = "padding:0;margin:0;border:0;display:block;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box",
  54. body = document.getElementsByTagName("body")[ 0 ];
  55. if ( !body ) {
  56. // Return for frameset docs that don't have a body
  57. return;
  58. }
  59. container = document.createElement("div");
  60. container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px";
  61. // Check box-sizing and margin behavior.
  62. body.appendChild( container ).appendChild( div );
  63. div.innerHTML = "";
  64. // Support: Firefox, Android 2.3 (Prefixed box-sizing versions).
  65. div.style.cssText = "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%";
  66. // Workaround failing boxSizing test due to offsetWidth returning wrong value
  67. // with some non-1 values of body zoom, ticket #13543
  68. jQuery.swap( body, body.style.zoom != null ? { zoom: 1 } : {}, function() {
  69. support.boxSizing = div.offsetWidth === 4;
  70. });
  71. // Use window.getComputedStyle because jsdom on node.js will break without it.
  72. if ( window.getComputedStyle ) {
  73. support.pixelPosition = ( window.getComputedStyle( div, null ) || {} ).top !== "1%";
  74. support.boxSizingReliable = ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px";
  75. // Support: Android 2.3
  76. // Check if div with explicit width and no margin-right incorrectly
  77. // gets computed margin-right based on width of container. (#3333)
  78. // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
  79. marginDiv = div.appendChild( document.createElement("div") );
  80. marginDiv.style.cssText = div.style.cssText = divReset;
  81. marginDiv.style.marginRight = marginDiv.style.width = "0";
  82. div.style.width = "1px";
  83. support.reliableMarginRight =
  84. !parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight );
  85. }
  86. body.removeChild( container );
  87. });
  88. return support;
  89. })( {} );