wysiwygrelative.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. (function() {
  2. var __SCROLL_WIDTH = 16;
  3. /**
  4. * wysiwyg 영역에서의 특정 노드의 상대 위치를 계산하기 위한 클래스로 WysiwygPanel 내부에서만 사용된다.
  5. * @private
  6. * @class
  7. */
  8. Trex.WysiwygRelative = Trex.Class.create({
  9. initialize: function(iframe) {
  10. this.iframe = iframe;
  11. },
  12. getRelative: function(node) {
  13. var _relatives = { x:0, y:0, width:0, height:0 };
  14. var doc = this.iframe.contentWindow.document;
  15. if (node) {
  16. var _position = $tom.getPosition(node, _TRUE);
  17. var _frameHeight = $tom.getHeight(this.iframe);
  18. var _scrollTop = $tom.getScrollTop(doc);
  19. if (_position.y + _position.height < _scrollTop || _position.y > _scrollTop + _frameHeight) {
  20. return _relatives;
  21. } else {
  22. var _frameLeft = 0; //Holder 기준
  23. var _frameTop = 0; //Holder 기준
  24. var _frameWidth = $tom.getWidth(this.iframe);
  25. var _scrollLeft = $tom.getScrollLeft(doc);
  26. _relatives.x = _frameLeft + ((_scrollLeft > 0) ? 0 : _position.x);
  27. _relatives.width = Math.min(_frameWidth - _position.x - __SCROLL_WIDTH, _position.width - ((_scrollLeft > 0) ? _scrollLeft - _position.x : 0));
  28. _relatives.height = _position.height;
  29. _relatives.y = _position.y - _scrollTop + _frameTop;
  30. }
  31. }
  32. return _relatives;
  33. }
  34. });
  35. })();