support.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. define( [
  2. "../core",
  3. "../var/document",
  4. "../var/documentElement",
  5. "../var/support"
  6. ], function( jQuery, document, documentElement, support ) {
  7. ( function() {
  8. var pixelPositionVal, boxSizingReliableVal, pixelMarginRightVal, reliableMarginLeftVal,
  9. container = document.createElement( "div" ),
  10. div = document.createElement( "div" );
  11. // Finish early in limited (non-browser) environments
  12. if ( !div.style ) {
  13. return;
  14. }
  15. // Support: IE9-11+
  16. // Style of cloned element affects source element cloned (#8908)
  17. div.style.backgroundClip = "content-box";
  18. div.cloneNode( true ).style.backgroundClip = "";
  19. support.clearCloneStyle = div.style.backgroundClip === "content-box";
  20. container.style.cssText = "border:0;width:8px;height:0;top:0;left:-9999px;" +
  21. "padding:0;margin-top:1px;position:absolute";
  22. container.appendChild( div );
  23. // Executing both pixelPosition & boxSizingReliable tests require only one layout
  24. // so they're executed at the same time to save the second computation.
  25. function computeStyleTests() {
  26. div.style.cssText =
  27. // Support: Firefox<29, Android 2.3
  28. // Vendor-prefix box-sizing
  29. "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;" +
  30. "position:relative;display:block;" +
  31. "margin:auto;border:1px;padding:1px;" +
  32. "top:1%;width:50%";
  33. div.innerHTML = "";
  34. documentElement.appendChild( container );
  35. var divStyle = window.getComputedStyle( div );
  36. pixelPositionVal = divStyle.top !== "1%";
  37. reliableMarginLeftVal = divStyle.marginLeft === "2px";
  38. boxSizingReliableVal = divStyle.width === "4px";
  39. // Support: Android 4.0 - 4.3 only
  40. // Some styles come back with percentage values, even though they shouldn't
  41. div.style.marginRight = "50%";
  42. pixelMarginRightVal = divStyle.marginRight === "4px";
  43. documentElement.removeChild( container );
  44. }
  45. jQuery.extend( support, {
  46. pixelPosition: function() {
  47. // This test is executed only once but we still do memoizing
  48. // since we can use the boxSizingReliable pre-computing.
  49. // No need to check if the test was already performed, though.
  50. computeStyleTests();
  51. return pixelPositionVal;
  52. },
  53. boxSizingReliable: function() {
  54. if ( boxSizingReliableVal == null ) {
  55. computeStyleTests();
  56. }
  57. return boxSizingReliableVal;
  58. },
  59. pixelMarginRight: function() {
  60. // Support: Android 4.0-4.3
  61. // We're checking for boxSizingReliableVal here instead of pixelMarginRightVal
  62. // since that compresses better and they're computed together anyway.
  63. if ( boxSizingReliableVal == null ) {
  64. computeStyleTests();
  65. }
  66. return pixelMarginRightVal;
  67. },
  68. reliableMarginLeft: function() {
  69. // Support: IE <=8 only, Android 4.0 - 4.3 only, Firefox <=3 - 37
  70. if ( boxSizingReliableVal == null ) {
  71. computeStyleTests();
  72. }
  73. return reliableMarginLeftVal;
  74. },
  75. reliableMarginRight: function() {
  76. // Support: Android 2.3
  77. // Check if div with explicit width and no margin-right incorrectly
  78. // gets computed margin-right based on width of container. (#3333)
  79. // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
  80. // This support function is only executed once so no memoizing is needed.
  81. var ret,
  82. marginDiv = div.appendChild( document.createElement( "div" ) );
  83. // Reset CSS: box-sizing; display; margin; border; padding
  84. marginDiv.style.cssText = div.style.cssText =
  85. // Support: Android 2.3
  86. // Vendor-prefix box-sizing
  87. "-webkit-box-sizing:content-box;box-sizing:content-box;" +
  88. "display:block;margin:0;border:0;padding:0";
  89. marginDiv.style.marginRight = marginDiv.style.width = "0";
  90. div.style.width = "1px";
  91. documentElement.appendChild( container );
  92. ret = !parseFloat( window.getComputedStyle( marginDiv ).marginRight );
  93. documentElement.removeChild( container );
  94. div.removeChild( marginDiv );
  95. return ret;
  96. }
  97. } );
  98. } )();
  99. return support;
  100. } );