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

http://hdbc.googlecode.com/ · JavaScript · 157 lines · 126 code · 25 blank · 6 comment · 39 complexity · 4abf10f9d33099c8389c3eed3c851833 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. (function(){
  8. var doc = document,
  9. isCSS1 = doc.compatMode == "CSS1Compat",
  10. MAX = Math.max,
  11. PARSEINT = parseInt;
  12. Ext.lib.Dom = {
  13. isAncestor : function(p, c) {
  14. var ret = false;
  15. p = Ext.getDom(p);
  16. c = Ext.getDom(c);
  17. if (p && c) {
  18. if (p.contains) {
  19. return p.contains(c);
  20. } else if (p.compareDocumentPosition) {
  21. return !!(p.compareDocumentPosition(c) & 16);
  22. } else {
  23. while (c = c.parentNode) {
  24. ret = c == p || ret;
  25. }
  26. }
  27. }
  28. return ret;
  29. },
  30. getViewWidth : function(full) {
  31. return full ? this.getDocumentWidth() : this.getViewportWidth();
  32. },
  33. getViewHeight : function(full) {
  34. return full ? this.getDocumentHeight() : this.getViewportHeight();
  35. },
  36. getDocumentHeight: function() {
  37. return MAX(!isCSS1 ? doc.body.scrollHeight : doc.documentElement.scrollHeight, this.getViewportHeight());
  38. },
  39. getDocumentWidth: function() {
  40. return MAX(!isCSS1 ? doc.body.scrollWidth : doc.documentElement.scrollWidth, this.getViewportWidth());
  41. },
  42. getViewportHeight: function(){
  43. return Ext.isIE ?
  44. (Ext.isStrict ? doc.documentElement.clientHeight : doc.body.clientHeight) :
  45. self.innerHeight;
  46. },
  47. getViewportWidth : function() {
  48. return !Ext.isStrict && !Ext.isOpera ? doc.body.clientWidth :
  49. Ext.isIE ? doc.documentElement.clientWidth : self.innerWidth;
  50. },
  51. getY : function(el) {
  52. return this.getXY(el)[1];
  53. },
  54. getX : function(el) {
  55. return this.getXY(el)[0];
  56. },
  57. getXY : function(el) {
  58. var p,
  59. pe,
  60. b,
  61. bt,
  62. bl,
  63. dbd,
  64. x = 0,
  65. y = 0,
  66. scroll,
  67. hasAbsolute,
  68. bd = (doc.body || doc.documentElement),
  69. ret = [0,0];
  70. el = Ext.getDom(el);
  71. if(el != bd){
  72. if (el.getBoundingClientRect) {
  73. b = el.getBoundingClientRect();
  74. scroll = fly(document).getScroll();
  75. ret = [b.left + scroll.left, b.top + scroll.top];
  76. } else {
  77. p = el;
  78. hasAbsolute = fly(el).isStyle("position", "absolute");
  79. while (p) {
  80. pe = fly(p);
  81. x += p.offsetLeft;
  82. y += p.offsetTop;
  83. hasAbsolute = hasAbsolute || pe.isStyle("position", "absolute");
  84. if (Ext.isGecko) {
  85. y += bt = PARSEINT(pe.getStyle("borderTopWidth"), 10) || 0;
  86. x += bl = PARSEINT(pe.getStyle("borderLeftWidth"), 10) || 0;
  87. if (p != el && !pe.isStyle('overflow','visible')) {
  88. x += bl;
  89. y += bt;
  90. }
  91. }
  92. p = p.offsetParent;
  93. }
  94. if (Ext.isSafari && hasAbsolute) {
  95. x -= bd.offsetLeft;
  96. y -= bd.offsetTop;
  97. }
  98. if (Ext.isGecko && !hasAbsolute) {
  99. dbd = fly(bd);
  100. x += PARSEINT(dbd.getStyle("borderLeftWidth"), 10) || 0;
  101. y += PARSEINT(dbd.getStyle("borderTopWidth"), 10) || 0;
  102. }
  103. p = el.parentNode;
  104. while (p && p != bd) {
  105. if (!Ext.isOpera || (p.tagName != 'TR' && !fly(p).isStyle("display", "inline"))) {
  106. x -= p.scrollLeft;
  107. y -= p.scrollTop;
  108. }
  109. p = p.parentNode;
  110. }
  111. ret = [x,y];
  112. }
  113. }
  114. return ret
  115. },
  116. setXY : function(el, xy) {
  117. (el = Ext.fly(el, '_setXY')).position();
  118. var pts = el.translatePoints(xy),
  119. style = el.dom.style,
  120. pos;
  121. for (pos in pts) {
  122. if(!isNaN(pts[pos])) style[pos] = pts[pos] + "px"
  123. }
  124. },
  125. setX : function(el, x) {
  126. this.setXY(el, [x, false]);
  127. },
  128. setY : function(el, y) {
  129. this.setXY(el, [false, y]);
  130. }
  131. };
  132. })();