support.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. define([
  2. "../core",
  3. "../var/support"
  4. ], function( jQuery, support ) {
  5. (function() {
  6. var pixelPositionVal, boxSizingReliableVal,
  7. docElem = document.documentElement,
  8. container = document.createElement( "div" ),
  9. div = document.createElement( "div" );
  10. if ( !div.style ) {
  11. return;
  12. }
  13. // Support: IE9-11+
  14. // Style of cloned element affects source element cloned (#8908)
  15. div.style.backgroundClip = "content-box";
  16. div.cloneNode( true ).style.backgroundClip = "";
  17. support.clearCloneStyle = div.style.backgroundClip === "content-box";
  18. container.style.cssText = "border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;" +
  19. "position:absolute";
  20. container.appendChild( div );
  21. // Executing both pixelPosition & boxSizingReliable tests require only one layout
  22. // so they're executed at the same time to save the second computation.
  23. function computePixelPositionAndBoxSizingReliable() {
  24. div.style.cssText =
  25. // Support: Firefox<29, Android 2.3
  26. // Vendor-prefix box-sizing
  27. "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
  28. "box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
  29. "border:1px;padding:1px;width:4px;position:absolute";
  30. div.innerHTML = "";
  31. docElem.appendChild( container );
  32. var divStyle = window.getComputedStyle( div, null );
  33. pixelPositionVal = divStyle.top !== "1%";
  34. boxSizingReliableVal = divStyle.width === "4px";
  35. docElem.removeChild( container );
  36. }
  37. // Support: node.js jsdom
  38. // Don't assume that getComputedStyle is a property of the global object
  39. if ( window.getComputedStyle ) {
  40. jQuery.extend( support, {
  41. pixelPosition: function() {
  42. // This test is executed only once but we still do memoizing
  43. // since we can use the boxSizingReliable pre-computing.
  44. // No need to check if the test was already performed, though.
  45. computePixelPositionAndBoxSizingReliable();
  46. return pixelPositionVal;
  47. },
  48. boxSizingReliable: function() {
  49. if ( boxSizingReliableVal == null ) {
  50. computePixelPositionAndBoxSizingReliable();
  51. }
  52. return boxSizingReliableVal;
  53. },
  54. reliableMarginRight: function() {
  55. // Support: Android 2.3
  56. // Check if div with explicit width and no margin-right incorrectly
  57. // gets computed margin-right based on width of container. (#3333)
  58. // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
  59. // This support function is only executed once so no memoizing is needed.
  60. var ret,
  61. marginDiv = div.appendChild( document.createElement( "div" ) );
  62. // Reset CSS: box-sizing; display; margin; border; padding
  63. marginDiv.style.cssText = div.style.cssText =
  64. // Support: Firefox<29, Android 2.3
  65. // Vendor-prefix box-sizing
  66. "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
  67. "box-sizing:content-box;display:block;margin:0;border:0;padding:0";
  68. marginDiv.style.marginRight = marginDiv.style.width = "0";
  69. div.style.width = "1px";
  70. docElem.appendChild( container );
  71. ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
  72. docElem.removeChild( container );
  73. div.removeChild( marginDiv );
  74. return ret;
  75. }
  76. });
  77. }
  78. })();
  79. return support;
  80. });