support.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. define( [
  2. "../core",
  3. "../var/document",
  4. "../var/documentElement",
  5. "../var/support"
  6. ], function( jQuery, document, documentElement, support ) {
  7. "use strict";
  8. ( function() {
  9. // Executing both pixelPosition & boxSizingReliable tests require only one layout
  10. // so they're executed at the same time to save the second computation.
  11. function computeStyleTests() {
  12. // This is a singleton, we need to execute it only once
  13. if ( !div ) {
  14. return;
  15. }
  16. div.style.cssText =
  17. "box-sizing:border-box;" +
  18. "position:relative;display:block;" +
  19. "margin:auto;border:1px;padding:1px;" +
  20. "top:1%;width:50%";
  21. div.innerHTML = "";
  22. documentElement.appendChild( container );
  23. var divStyle = window.getComputedStyle( div );
  24. pixelPositionVal = divStyle.top !== "1%";
  25. // Support: Android 4.0 - 4.3 only, Firefox <=3 - 44
  26. reliableMarginLeftVal = divStyle.marginLeft === "2px";
  27. boxSizingReliableVal = divStyle.width === "4px";
  28. // Support: Android 4.0 - 4.3 only
  29. // Some styles come back with percentage values, even though they shouldn't
  30. div.style.marginRight = "50%";
  31. pixelMarginRightVal = divStyle.marginRight === "4px";
  32. documentElement.removeChild( container );
  33. // Nullify the div so it wouldn't be stored in the memory and
  34. // it will also be a sign that checks already performed
  35. div = null;
  36. }
  37. var pixelPositionVal, boxSizingReliableVal, pixelMarginRightVal, reliableMarginLeftVal,
  38. container = document.createElement( "div" ),
  39. div = document.createElement( "div" );
  40. // Finish early in limited (non-browser) environments
  41. if ( !div.style ) {
  42. return;
  43. }
  44. // Support: IE <=9 - 11 only
  45. // Style of cloned element affects source element cloned (#8908)
  46. div.style.backgroundClip = "content-box";
  47. div.cloneNode( true ).style.backgroundClip = "";
  48. support.clearCloneStyle = div.style.backgroundClip === "content-box";
  49. container.style.cssText = "border:0;width:8px;height:0;top:0;left:-9999px;" +
  50. "padding:0;margin-top:1px;position:absolute";
  51. container.appendChild( div );
  52. jQuery.extend( support, {
  53. pixelPosition: function() {
  54. computeStyleTests();
  55. return pixelPositionVal;
  56. },
  57. boxSizingReliable: function() {
  58. computeStyleTests();
  59. return boxSizingReliableVal;
  60. },
  61. pixelMarginRight: function() {
  62. computeStyleTests();
  63. return pixelMarginRightVal;
  64. },
  65. reliableMarginLeft: function() {
  66. computeStyleTests();
  67. return reliableMarginLeftVal;
  68. }
  69. } );
  70. } )();
  71. return support;
  72. } );