/hippo/src/main/webapp/ext/src/adapter/core/ext-base-region.js

http://hdbc.googlecode.com/ · JavaScript · 81 lines · 64 code · 11 blank · 6 comment · 2 complexity · b3a0f3d506b61c6ad15c86bf9b5ea441 MD5 · raw file

  1. /*!
  2. * Ext JS Library 3.0.0
  3. * Copyright(c) 2006-2009 Ext JS, LLC
  4. * licensing@extjs.com
  5. * http://www.extjs.com/license
  6. */
  7. Ext.lib.Region = function(t, r, b, l) {
  8. var me = this;
  9. me.top = t;
  10. me[1] = t;
  11. me.right = r;
  12. me.bottom = b;
  13. me.left = l;
  14. me[0] = l;
  15. };
  16. Ext.lib.Region.prototype = {
  17. contains : function(region) {
  18. var me = this;
  19. return ( region.left >= me.left &&
  20. region.right <= me.right &&
  21. region.top >= me.top &&
  22. region.bottom <= me.bottom );
  23. },
  24. getArea : function() {
  25. var me = this;
  26. return ( (me.bottom - me.top) * (me.right - me.left) );
  27. },
  28. intersect : function(region) {
  29. var me = this,
  30. t = Math.max(me.top, region.top),
  31. r = Math.min(me.right, region.right),
  32. b = Math.min(me.bottom, region.bottom),
  33. l = Math.max(me.left, region.left);
  34. if (b >= t && r >= l) {
  35. return new Ext.lib.Region(t, r, b, l);
  36. }
  37. },
  38. union : function(region) {
  39. var me = this,
  40. t = Math.min(me.top, region.top),
  41. r = Math.max(me.right, region.right),
  42. b = Math.max(me.bottom, region.bottom),
  43. l = Math.min(me.left, region.left);
  44. return new Ext.lib.Region(t, r, b, l);
  45. },
  46. constrainTo : function(r) {
  47. var me = this;
  48. me.top = me.top.constrain(r.top, r.bottom);
  49. me.bottom = me.bottom.constrain(r.top, r.bottom);
  50. me.left = me.left.constrain(r.left, r.right);
  51. me.right = me.right.constrain(r.left, r.right);
  52. return me;
  53. },
  54. adjust : function(t, l, b, r) {
  55. var me = this;
  56. me.top += t;
  57. me.left += l;
  58. me.right += r;
  59. me.bottom += b;
  60. return me;
  61. }
  62. };
  63. Ext.lib.Region.getRegion = function(el) {
  64. var p = Ext.lib.Dom.getXY(el),
  65. t = p[1],
  66. r = p[0] + el.offsetWidth,
  67. b = p[1] + el.offsetHeight,
  68. l = p[0];
  69. return new Ext.lib.Region(t, r, b, l);
  70. };