Requires

Provides

Dimensions.js

Get and set dimensions of widget

License:
Public domain (http://unlicense.org).
Authors:
Yaroslaff Fedin
  1. 23
  2. 24
  3. 25
  4. 26
  5. 27
  6. 28
  7. 29
  8. 30
  9. 31
  10. 32
  11. 33
  12. 34
  13. 35
  14. 36
  15. 37
  16. 38
  17. 39
  18. 40
  19. 41
  20. 42
  21. 43
  22. 44
  23. 45
  24. 46
  25. 47
  26. 48
  27. 49
  28. 50
  29. 51
  30. 52
  31. 53
  32. 54
  33. 55
  34. 56
  35. 57
  36. 58
  37. 59
  38. 60
  39. 61
  40. 62
  41. 63
  42. 64
  43. 65
  44. 66
  45. 67
  46. 68
  47. 69
  48. 70
  49. 71
  50. 72
  51. 73
  52. 74
  53. 75
  54. 76
  55. 77
  56. 78
  57. 79
  58. 80
  59. 81
  60. 82
  61. 83
  62. 84
  63. 85
  64. 86
  65. 87
  66. 88
  67. 89
  68. 90
  69. 91
  70. 92
  71. 93
  72. 94
  73. 95
  74. 96
  75. 97
  76. 98
  77. 99
  78. 100
  79. 101
  80. 102
  81. 103
  82. 104
  83. 105
  84. 106
  85. 107
  86. 108
  87. 109
  88. 110
  89. 111
  90. 112
  91. 113
  92. 114
  93. 115
  94. 116
  95. 117
  96. 118
  97. 119
LSD.Trait.Dimensions = new Class({ options: { events: { _dimensions: { 'render': 'setSize' } } }, initialize: function() { this.size = {}; this.parent.apply(this, arguments); }, setSize: function(size) { if (!size || !(size.width || size.width)) size = {height: this.getStyle('height'), width: this.getStyle('width')} if (!(this.setHeight(size.height, true) + this.setWidth(size.width, true))) return false; var element = this.element, padding = this.offset.padding; if (size.height && this.style.expressed.height) element.style.height = size.height - padding.top - padding.bottom + 'px' if (size.width && this.style.expressed.width) element.style.width = size.width - padding.left - padding.right + 'px'; }, setHeight: function(value, light) { value = Math.min(this.style.current.maxHeight || 1500, Math.max(this.style.current.minHeight || 0, value)); if (this.size.height == value) return false; this.size.height = value; if (!light) this.setStyle('height', value); return value; }, setWidth: function(value, light) { value = Math.min(this.style.current.maxWidth || 3500, Math.max(this.style.current.minWidth || 0, value)); if (this.size.width == value) return false; this.size.width = value; if (!light) this.setStyle('width', value); return value; }, getClientHeight: function() { var style = this.style.current, height = style.height, offset = this.offset, padding = offset.padding; if (!height || (height == "auto")) { height = this.element.clientHeight; var inner = offset.inner || padding; if (height > 0 && inner) height -= inner.top + inner.bottom; } if (height != 'auto' && padding) height += padding.top + padding.bottom; return height; }, getClientWidth: function() { var style = this.style.current, offset = this.offset, padding = offset.padding, width = style.width; if (typeof width != 'number') { //auto, inherit, undefined var inside = offset.inside, outside = offset.outside, shape = offset.shape; width = this.element.clientWidth; if (width > 0) { if (shape) width -= shape.left + shape.right; if (inside) width -= inside.left + inside.right; if (outside) width -= outside.left + outside.right; } } if (style.display != 'block' && padding && inside) width += padding.left + padding.right; return width; }, getOffsetHeight: function(height) { var style = this.style.current, inside = this.offset.inside, bottom = style.borderBottomWidth, top = style.borderTopWidth; if (!height) height = this.getClientHeight(); if (inside) height += inside.top + inside.bottom; if (top) height += top; if (bottom) height += bottom; return height; }, getOffsetWidth: function(width) { var style = this.style.current, inside = this.offset.inside, left = style.borderLeftWidth, right = style.borderRightWidth; if (!width) width = this.getClientWidth(); if (inside) width += inside.left + inside.right; if (left) width += left; if (right) width += right return width; }, getLayoutHeight: function(height) { height = this.getOffsetHeight(height); if (this.offset.margin) height += this.offset.margin.top + this.offset.margin.bottom; if (this.offset.outside) height += this.offset.outside.top + this.offset.outside.bottom; return height; }, getLayoutWidth: function(width) { var width = this.getOffsetWidth(width), offset = this.offset, margin = offset.margin, outside = offset.outside if (margin) width += margin.right + margin.left; if (outside) width += outside.right + outside.left; return width; } });