dimensions.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. define( [
  2. "./core",
  3. "./core/access",
  4. "./var/isWindow",
  5. "./css"
  6. ], function( jQuery, access, isWindow ) {
  7. "use strict";
  8. // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
  9. jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
  10. jQuery.each( {
  11. padding: "inner" + name,
  12. content: type,
  13. "": "outer" + name
  14. }, function( defaultExtra, funcName ) {
  15. // Margin is only for outerHeight, outerWidth
  16. jQuery.fn[ funcName ] = function( margin, value ) {
  17. var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
  18. extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
  19. return access( this, function( elem, type, value ) {
  20. var doc;
  21. if ( isWindow( elem ) ) {
  22. // $( window ).outerWidth/Height return w/h including scrollbars (gh-1729)
  23. return funcName.indexOf( "outer" ) === 0 ?
  24. elem[ "inner" + name ] :
  25. elem.document.documentElement[ "client" + name ];
  26. }
  27. // Get document width or height
  28. if ( elem.nodeType === 9 ) {
  29. doc = elem.documentElement;
  30. // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
  31. // whichever is greatest
  32. return Math.max(
  33. elem.body[ "scroll" + name ], doc[ "scroll" + name ],
  34. elem.body[ "offset" + name ], doc[ "offset" + name ],
  35. doc[ "client" + name ]
  36. );
  37. }
  38. return value === undefined ?
  39. // Get width or height on the element, requesting but not forcing parseFloat
  40. jQuery.css( elem, type, extra ) :
  41. // Set width or height on the element
  42. jQuery.style( elem, type, value, extra );
  43. }, type, chainable ? margin : undefined, chainable );
  44. };
  45. } );
  46. } );
  47. return jQuery;
  48. } );