fckplugin.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  3. * Copyright (C) 2003-2010 Frederico Caldeira Knabben
  4. *
  5. * == BEGIN LICENSE ==
  6. *
  7. * Licensed under the terms of any of the following licenses at your
  8. * choice:
  9. *
  10. * - GNU General Public License Version 2 or later (the "GPL")
  11. * http://www.gnu.org/licenses/gpl.html
  12. *
  13. * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  14. * http://www.gnu.org/licenses/lgpl.html
  15. *
  16. * - Mozilla Public License Version 1.1 or later (the "MPL")
  17. * http://www.mozilla.org/MPL/MPL-1.1.html
  18. *
  19. * == END LICENSE ==
  20. *
  21. * Plugin: automatically resizes the editor until a configurable maximun
  22. * height (FCKConfig.AutoGrowMax), based on its contents.
  23. */
  24. var FCKAutoGrow = {
  25. MIN_HEIGHT : window.frameElement.offsetHeight,
  26. Check : function()
  27. {
  28. var delta = FCKAutoGrow.GetHeightDelta() ;
  29. if ( delta != 0 )
  30. {
  31. var newHeight = window.frameElement.offsetHeight + delta ;
  32. newHeight = FCKAutoGrow.GetEffectiveHeight( newHeight ) ;
  33. if ( newHeight != window.frameElement.height )
  34. {
  35. window.frameElement.style.height = newHeight + "px" ;
  36. // Gecko browsers use an onresize handler to update the innermost
  37. // IFRAME's height. If the document is modified before the onresize
  38. // is triggered, the plugin will miscalculate the new height. Thus,
  39. // forcibly trigger onresize. #1336
  40. if ( typeof window.onresize == 'function' )
  41. {
  42. window.onresize() ;
  43. }
  44. }
  45. }
  46. },
  47. CheckEditorStatus : function( sender, status )
  48. {
  49. if ( status == FCK_STATUS_COMPLETE )
  50. FCKAutoGrow.Check() ;
  51. },
  52. GetEffectiveHeight : function( height )
  53. {
  54. if ( height < FCKAutoGrow.MIN_HEIGHT )
  55. height = FCKAutoGrow.MIN_HEIGHT;
  56. else
  57. {
  58. var max = FCKConfig.AutoGrowMax;
  59. if ( max && max > 0 && height > max )
  60. height = max;
  61. }
  62. return height;
  63. },
  64. GetHeightDelta : function()
  65. {
  66. var oInnerDoc = FCK.EditorDocument ;
  67. var iFrameHeight ;
  68. var iInnerHeight ;
  69. if ( FCKBrowserInfo.IsIE )
  70. {
  71. iFrameHeight = FCK.EditorWindow.frameElement.offsetHeight ;
  72. iInnerHeight = oInnerDoc.body.scrollHeight ;
  73. }
  74. else
  75. {
  76. iFrameHeight = FCK.EditorWindow.innerHeight ;
  77. iInnerHeight = oInnerDoc.body.offsetHeight +
  78. ( parseInt( FCKDomTools.GetCurrentElementStyle( oInnerDoc.body, 'margin-top' ), 10 ) || 0 ) +
  79. ( parseInt( FCKDomTools.GetCurrentElementStyle( oInnerDoc.body, 'margin-bottom' ), 10 ) || 0 ) ;
  80. }
  81. return iInnerHeight - iFrameHeight ;
  82. },
  83. SetListeners : function()
  84. {
  85. if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
  86. return ;
  87. FCK.EditorWindow.attachEvent( 'onscroll', FCKAutoGrow.Check ) ;
  88. FCK.EditorDocument.attachEvent( 'onkeyup', FCKAutoGrow.Check ) ;
  89. }
  90. };
  91. FCK.AttachToOnSelectionChange( FCKAutoGrow.Check ) ;
  92. if ( FCKBrowserInfo.IsIE )
  93. FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKAutoGrow.SetListeners ) ;
  94. FCK.Events.AttachEvent( 'OnStatusChange', FCKAutoGrow.CheckEditorStatus ) ;