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, oldSize = 0; |
---|
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 | // Bottom margin |
---|
44 | myHeight = t.bottom_margin + myHeight; |
---|
45 | |
---|
46 | // Don't make it smaller than the minimum height |
---|
47 | if (myHeight > t.autoresize_min_height) |
---|
48 | resizeHeight = myHeight; |
---|
49 | |
---|
50 | // Resize content element |
---|
51 | if ( resizeHeight !== oldSize ) { |
---|
52 | DOM.setStyle(DOM.get(ed.id + '_ifr'), 'height', resizeHeight + 'px'); |
---|
53 | oldSize = resizeHeight; |
---|
54 | } |
---|
55 | |
---|
56 | // if we're throbbing, we'll re-throb to match the new size |
---|
57 | if (t.throbbing) { |
---|
58 | ed.setProgressState(false); |
---|
59 | ed.setProgressState(true); |
---|
60 | } |
---|
61 | }; |
---|
62 | |
---|
63 | t.editor = ed; |
---|
64 | |
---|
65 | // Define minimum height |
---|
66 | t.autoresize_min_height = ed.getElement().offsetHeight; |
---|
67 | |
---|
68 | // Add margin at the bottom for better UX |
---|
69 | t.bottom_margin = parseInt( ed.getParam('autoresize_bottom_margin', 50) ); |
---|
70 | |
---|
71 | // Add appropriate listeners for resizing content area |
---|
72 | ed.onChange.add(resize); |
---|
73 | ed.onSetContent.add(resize); |
---|
74 | ed.onPaste.add(resize); |
---|
75 | ed.onKeyUp.add(resize); |
---|
76 | ed.onPostRender.add(resize); |
---|
77 | |
---|
78 | if (ed.getParam('autoresize_on_init', true)) { |
---|
79 | // Things to do when the editor is ready |
---|
80 | ed.onInit.add(function(ed, l) { |
---|
81 | // Show throbber until content area is resized properly |
---|
82 | ed.setProgressState(true); |
---|
83 | t.throbbing = true; |
---|
84 | |
---|
85 | // Hide scrollbars |
---|
86 | ed.getBody().style.overflowY = "hidden"; |
---|
87 | }); |
---|
88 | |
---|
89 | ed.onLoadContent.add(function(ed, l) { |
---|
90 | resize(); |
---|
91 | |
---|
92 | // Because the content area resizes when its content CSS loads, |
---|
93 | // and we can't easily add a listener to its onload event, |
---|
94 | // we'll just trigger a resize after a short loading period |
---|
95 | setTimeout(function() { |
---|
96 | resize(); |
---|
97 | |
---|
98 | // Disable throbber |
---|
99 | ed.setProgressState(false); |
---|
100 | t.throbbing = false; |
---|
101 | }, 1250); |
---|
102 | }); |
---|
103 | } |
---|
104 | |
---|
105 | // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample'); |
---|
106 | ed.addCommand('mceAutoResize', resize); |
---|
107 | }, |
---|
108 | |
---|
109 | /** |
---|
110 | * Returns information about the plugin as a name/value array. |
---|
111 | * The current keys are longname, author, authorurl, infourl and version. |
---|
112 | * |
---|
113 | * @return {Object} Name/value array containing information about the plugin. |
---|
114 | */ |
---|
115 | getInfo : function() { |
---|
116 | return { |
---|
117 | longname : 'Auto Resize', |
---|
118 | author : 'Moxiecode Systems AB', |
---|
119 | authorurl : 'http://tinymce.moxiecode.com', |
---|
120 | infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/autoresize', |
---|
121 | version : tinymce.majorVersion + "." + tinymce.minorVersion |
---|
122 | }; |
---|
123 | } |
---|
124 | }); |
---|
125 | |
---|
126 | // Register plugin |
---|
127 | tinymce.PluginManager.add('autoresize', tinymce.plugins.AutoResizePlugin); |
---|
128 | })(); |
---|