resizer.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. Trex.module("new Trex.Resizer",
  2. function(editor, toolbar, sidebar, canvas, config){
  3. var _initializedId = config.initializedId || "";
  4. var cfg = TrexConfig.get("resizer", config);
  5. var _resizer = _NULL;
  6. editor.setMinHeight = function(h) {
  7. return _resizer.setMinHeight(h);
  8. };
  9. editor.restoreMinHeight = function() {
  10. return _resizer.restoreMinHeight();
  11. };
  12. if (Trex.available(cfg, "resizer" + _initializedId)) {
  13. _resizer = new Trex.Resizer(editor, cfg);
  14. }
  15. }
  16. );
  17. TrexConfig.add({
  18. 'resizer': {
  19. minHeight: 200
  20. }
  21. });
  22. Trex.Resizer = Trex.Class.create({
  23. $const: {
  24. __Identity: 'resizer'
  25. },
  26. $mixins: [
  27. Trex.I.JobObservable
  28. ],
  29. initialize: function(editor, config) {
  30. var _presentHeight = 0;
  31. if(!editor) {
  32. return;
  33. }
  34. this.config = config;
  35. var _initializedId = editor.getInitializedId();
  36. var _elBar = this.elBar = $tx("tx_resizer" + _initializedId);
  37. if(!_elBar) {
  38. return;
  39. }
  40. if($tx.msie_ver == '5.5'){
  41. _elBar.setAttribute('align', 'center');
  42. }
  43. this.resizeHeightAtService = function( height ) { //NOTE: 에디터를 리사이즈하고 나서 실행할 서비스 콜백
  44. if(typeof resizeHeight == "function") {
  45. resizeHeight( height );
  46. }
  47. };
  48. this.resizingHeightAtService = function( height ) { //NOTE: 에디터를 리사이즈하는 중에 실행할 서비스 콜백 ex) iframe 길이 늘리기
  49. if(typeof resizingEditorHeight == "function") {
  50. resizingEditorHeight( height );
  51. }
  52. };
  53. this.minDragHeight = config.minHeight;
  54. var _wysiwygDoc;
  55. this.startDrag = function(ev) {
  56. var _canvas = editor.getCanvas();
  57. var _panel = _canvas.getCurrentPanel();
  58. if(_panel == _NULL) {
  59. return;
  60. }
  61. var _position = _panel.getPosition();
  62. this.panelHeight = _position.height;
  63. this.dragStartPosY = ev.clientY;
  64. this.isDragging = _TRUE;
  65. $tx.observe(_DOC, 'mousemove', this.documentDraggingHandler);
  66. $tx.observe(_DOC, 'mouseup', this.stopDragHandler);
  67. if(_panel.getName() == Trex.Canvas.__WYSIWYG_MODE) {
  68. this.panelTop = _position.y;
  69. _wysiwygDoc = _panel.getDocument();
  70. if(_wysiwygDoc == _NULL) {
  71. return;
  72. }
  73. _canvas.fireJobs('canvas.height.beforechange');
  74. $tx.observe(_wysiwygDoc, 'mousemove', this.wysiwygDraggingHandler);
  75. $tx.observe(_wysiwygDoc, 'mouseup', this.stopDragHandler);
  76. }
  77. $tx.stop(ev);
  78. };
  79. this.stopDrag = function(ev){
  80. var _canvas = editor.getCanvas();
  81. var _panel = _canvas.getCurrentPanel();
  82. if(_panel == _NULL) {
  83. return;
  84. }
  85. this.isDragging = _FALSE;
  86. $tx.stopObserving(_DOC, 'mousemove', this.documentDraggingHandler);
  87. $tx.stopObserving(_DOC, 'mouseup', this.stopDragHandler);
  88. if(_wysiwygDoc == _NULL) {
  89. return;
  90. }
  91. $tx.stopObserving(_wysiwygDoc, 'mousemove', this.wysiwygDraggingHandler);
  92. $tx.stopObserving(_wysiwygDoc, 'mouseup', this.stopDragHandler);
  93. _wysiwygDoc = _NULL;
  94. this.resizeHeightAtService(_presentHeight);
  95. _canvas.fireJobs('canvas.height.afterchange');
  96. $tx.stop(ev);
  97. };
  98. this.dragingAtDocument = function(ev) {
  99. var _canvas = editor.getCanvas();
  100. if (this.isDragging) {
  101. var _panel = _canvas.getCurrentPanel();
  102. if(_panel == _NULL) {
  103. return;
  104. }
  105. try {
  106. var _height = Math.max((this.panelHeight + ev.clientY - this.dragStartPosY), this.minDragHeight.parsePx()).toPx();
  107. _panel.setPanelHeight(_height);
  108. _presentHeight = _height;
  109. _canvas.fireJobs('canvas.height.change', _height);
  110. this.resizingHeightAtService(_height);
  111. } catch(e) {
  112. console.log(e);
  113. }
  114. }
  115. $tx.stop(ev);
  116. };
  117. this.dragingAtWysiwyg = function(ev) {
  118. var _canvas = editor.getCanvas();
  119. if (this.isDragging) {
  120. var _panel = _canvas.getCurrentPanel();
  121. if(_panel == _NULL) {
  122. return;
  123. }
  124. try {
  125. var _scrollTop = _DOC.body.scrollTop || _DOC_EL.scrollTop || _WIN.pageYOffset;
  126. var canvasPos = _canvas.getCanvasPos(); // canvas 위치를 조정하지 않아서 높이 잘못 계산한 부분 수정 #FTDUEDTR-1317
  127. var _height = Math.max((this.panelHeight + ev.clientY + canvasPos.y - this.dragStartPosY + this.panelTop - _scrollTop), this.minDragHeight.parsePx()).toPx();
  128. _panel.setPanelHeight(_height);
  129. _canvas.fireJobs('canvas.height.change', _height);
  130. } catch (e) {
  131. console.log(e);
  132. }
  133. }
  134. $tx.stop(ev);
  135. };
  136. this.startDragHandler = this.startDrag.bindAsEventListener(this);
  137. this.stopDragHandler = this.stopDrag.bindAsEventListener(this);
  138. this.documentDraggingHandler = this.dragingAtDocument.bindAsEventListener(this);
  139. this.wysiwygDraggingHandler = this.dragingAtWysiwyg.bindAsEventListener(this);
  140. this.isDragging = _FALSE;
  141. $tx.observe(_elBar, 'mousedown', this.startDragHandler);
  142. var _canvas = editor.getCanvas();
  143. _canvas.observeJob(Trex.Ev.__CANVAS_FULL_SCREEN_CHANGE, function() {
  144. $tx.hide(_elBar);
  145. });
  146. _canvas.observeJob(Trex.Ev.__CANVAS_NORMAL_SCREEN_CHANGE, function() {
  147. $tx.show(_elBar);
  148. });
  149. },
  150. setMinHeight: function(height) {
  151. return this.minDragHeight = height.toPx();
  152. },
  153. restoreMinHeight: function() {
  154. return this.minDragHeight = this.config.minHeight || 200;
  155. }
  156. });