includes/clientside/tinymce/plugins/autoresize/editor_plugin_src.js
changeset 1344 dc96d6c5cd1e
parent 1343 2a31905a567d
child 1345 1de01205143b
equal deleted inserted replaced
1343:2a31905a567d 1344:dc96d6c5cd1e
     1 /**
       
     2  * $Id: editor_plugin_src.js 539 2008-01-14 19:08:58Z spocke $
       
     3  *
       
     4  * @author Moxiecode
       
     5  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
       
     6  */
       
     7 
       
     8 (function() {
       
     9 	/**
       
    10 	 * Auto Resize
       
    11 	 * 
       
    12 	 * This plugin automatically resizes the content area to fit its content height.
       
    13 	 * It will retain a minimum height, which is the height of the content area when
       
    14 	 * it's initialized.
       
    15 	 */
       
    16 	tinymce.create('tinymce.plugins.AutoResizePlugin', {
       
    17 		/**
       
    18 		 * Initializes the plugin, this will be executed after the plugin has been created.
       
    19 		 * This call is done before the editor instance has finished it's initialization so use the onInit event
       
    20 		 * of the editor instance to intercept that event.
       
    21 		 *
       
    22 		 * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
       
    23 		 * @param {string} url Absolute URL to where the plugin is located.
       
    24 		 */
       
    25 		init : function(ed, url) {
       
    26 			var t = this;
       
    27 
       
    28 			if (ed.getParam('fullscreen_is_enabled'))
       
    29 				return;
       
    30 
       
    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 
       
    37 				// Get height differently depending on the browser used
       
    38 				myHeight = tinymce.isIE ? b.scrollHeight : de.offsetHeight;
       
    39 
       
    40 				// Don't make it smaller than the minimum height
       
    41 				if (myHeight > t.autoresize_min_height)
       
    42 					resizeHeight = myHeight;
       
    43 
       
    44 				// Resize content element
       
    45 				DOM.setStyle(DOM.get(ed.id + '_ifr'), 'height', resizeHeight + 'px');
       
    46 
       
    47 				// if we're throbbing, we'll re-throb to match the new size
       
    48 				if (t.throbbing) {
       
    49 					ed.setProgressState(false);
       
    50 					ed.setProgressState(true);
       
    51 				}
       
    52 			};
       
    53 
       
    54 			t.editor = ed;
       
    55 
       
    56 			// Define minimum height
       
    57 			t.autoresize_min_height = ed.getElement().offsetHeight;
       
    58 
       
    59 			// Things to do when the editor is ready
       
    60 			ed.onInit.add(function(ed, l) {
       
    61 				// Show throbber until content area is resized properly
       
    62 				ed.setProgressState(true);
       
    63 				t.throbbing = true;
       
    64 
       
    65 				// Hide scrollbars
       
    66 				ed.getBody().style.overflowY = "hidden";
       
    67 			});
       
    68 
       
    69 			// Add appropriate listeners for resizing content area
       
    70 			ed.onChange.add(resize);
       
    71 			ed.onSetContent.add(resize);
       
    72 			ed.onPaste.add(resize);
       
    73 			ed.onKeyUp.add(resize);
       
    74 			ed.onPostRender.add(resize);
       
    75 
       
    76 			ed.onLoadContent.add(function(ed, l) {
       
    77 				resize();
       
    78 
       
    79 				// Because the content area resizes when its content CSS loads,
       
    80 				// and we can't easily add a listener to its onload event,
       
    81 				// we'll just trigger a resize after a short loading period
       
    82 				setTimeout(function() {
       
    83 					resize();
       
    84 
       
    85 					// Disable throbber
       
    86 					ed.setProgressState(false);
       
    87 					t.throbbing = false;
       
    88 				}, 1250);
       
    89 			});
       
    90 
       
    91 			// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample');
       
    92 			ed.addCommand('mceAutoResize', resize);
       
    93 		},
       
    94 
       
    95 		/**
       
    96 		 * Returns information about the plugin as a name/value array.
       
    97 		 * The current keys are longname, author, authorurl, infourl and version.
       
    98 		 *
       
    99 		 * @return {Object} Name/value array containing information about the plugin.
       
   100 		 */
       
   101 		getInfo : function() {
       
   102 			return {
       
   103 				longname : 'Auto Resize',
       
   104 				author : 'Moxiecode Systems AB',
       
   105 				authorurl : 'http://tinymce.moxiecode.com',
       
   106 				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/autoresize',
       
   107 				version : tinymce.majorVersion + "." + tinymce.minorVersion
       
   108 			};
       
   109 		}
       
   110 	});
       
   111 
       
   112 	// Register plugin
       
   113 	tinymce.PluginManager.add('autoresize', tinymce.plugins.AutoResizePlugin);
       
   114 })();