PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/plugins/autoresize/editor_plugin_src.js

#
JavaScript | 137 lines | 65 code | 21 blank | 51 comment | 7 complexity | 05046c505c39c3d1d827dc6b5ff13c7c MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. /**
  2. * editor_plugin_src.js
  3. *
  4. * Copyright 2009, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://tinymce.moxiecode.com/license
  8. * Contributing: http://tinymce.moxiecode.com/contributing
  9. */
  10. (function() {
  11. /**
  12. * Auto Resize
  13. *
  14. * This plugin automatically resizes the content area to fit its content height.
  15. * It will retain a minimum height, which is the height of the content area when
  16. * it's initialized.
  17. */
  18. tinymce.create('tinymce.plugins.AutoResizePlugin', {
  19. /**
  20. * Initializes the plugin, this will be executed after the plugin has been created.
  21. * This call is done before the editor instance has finished it's initialization so use the onInit event
  22. * of the editor instance to intercept that event.
  23. *
  24. * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
  25. * @param {string} url Absolute URL to where the plugin is located.
  26. */
  27. init : function(ed, url) {
  28. var t = this, oldSize = 0;
  29. if (ed.getParam('fullscreen_is_enabled'))
  30. return;
  31. /**
  32. * This method gets executed each time the editor needs to resize.
  33. */
  34. function resize() {
  35. var d = ed.getDoc(), b = d.body, de = d.documentElement, DOM = tinymce.DOM, resizeHeight = t.autoresize_min_height, myHeight;
  36. // Get height differently depending on the browser used
  37. myHeight = tinymce.isIE ? b.scrollHeight : d.body.offsetHeight;
  38. // Don't make it smaller than the minimum height
  39. if (myHeight > t.autoresize_min_height)
  40. resizeHeight = myHeight;
  41. // If a maximum height has been defined don't exceed this height
  42. if (t.autoresize_max_height && myHeight > t.autoresize_max_height) {
  43. resizeHeight = t.autoresize_max_height;
  44. ed.getBody().style.overflowY = "auto";
  45. } else
  46. ed.getBody().style.overflowY = "hidden";
  47. // Resize content element
  48. if (resizeHeight !== oldSize) {
  49. DOM.setStyle(DOM.get(ed.id + '_ifr'), 'height', resizeHeight + 'px');
  50. oldSize = resizeHeight;
  51. }
  52. // if we're throbbing, we'll re-throb to match the new size
  53. if (t.throbbing) {
  54. ed.setProgressState(false);
  55. ed.setProgressState(true);
  56. }
  57. };
  58. t.editor = ed;
  59. // Define minimum height
  60. t.autoresize_min_height = parseInt( ed.getParam('autoresize_min_height', ed.getElement().offsetHeight) );
  61. // Define maximum height
  62. t.autoresize_max_height = parseInt( ed.getParam('autoresize_max_height', 0) );
  63. // Add padding at the bottom for better UX
  64. ed.onInit.add(function(ed){
  65. ed.dom.setStyle(ed.getBody(), 'paddingBottom', ed.getParam('autoresize_bottom_margin', 50) + 'px');
  66. });
  67. // Add appropriate listeners for resizing content area
  68. ed.onChange.add(resize);
  69. ed.onSetContent.add(resize);
  70. ed.onPaste.add(resize);
  71. ed.onKeyUp.add(resize);
  72. ed.onPostRender.add(resize);
  73. if (ed.getParam('autoresize_on_init', true)) {
  74. // Things to do when the editor is ready
  75. ed.onInit.add(function(ed, l) {
  76. // Show throbber until content area is resized properly
  77. ed.setProgressState(true);
  78. t.throbbing = true;
  79. // Hide scrollbars
  80. ed.getBody().style.overflowY = "hidden";
  81. });
  82. ed.onLoadContent.add(function(ed, l) {
  83. resize();
  84. // Because the content area resizes when its content CSS loads,
  85. // and we can't easily add a listener to its onload event,
  86. // we'll just trigger a resize after a short loading period
  87. setTimeout(function() {
  88. resize();
  89. // Disable throbber
  90. ed.setProgressState(false);
  91. t.throbbing = false;
  92. }, 1250);
  93. });
  94. }
  95. // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample');
  96. ed.addCommand('mceAutoResize', resize);
  97. },
  98. /**
  99. * Returns information about the plugin as a name/value array.
  100. * The current keys are longname, author, authorurl, infourl and version.
  101. *
  102. * @return {Object} Name/value array containing information about the plugin.
  103. */
  104. getInfo : function() {
  105. return {
  106. longname : 'Auto Resize',
  107. author : 'Moxiecode Systems AB',
  108. authorurl : 'http://tinymce.moxiecode.com',
  109. infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/autoresize',
  110. version : tinymce.majorVersion + "." + tinymce.minorVersion
  111. };
  112. }
  113. });
  114. // Register plugin
  115. tinymce.PluginManager.add('autoresize', tinymce.plugins.AutoResizePlugin);
  116. })();