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