0
|
1 |
/** |
|
2 |
* WP Fullscreen TinyMCE plugin |
|
3 |
* |
|
4 |
* Contains code from Moxiecode Systems AB released under LGPL http://tinymce.moxiecode.com/license |
|
5 |
*/ |
|
6 |
|
|
7 |
(function() { |
|
8 |
tinymce.create('tinymce.plugins.wpFullscreenPlugin', { |
|
9 |
resize_timeout: false, |
|
10 |
|
|
11 |
init : function(ed, url) { |
|
12 |
var t = this, oldHeight = 0, s = {}, DOM = tinymce.DOM; |
|
13 |
|
|
14 |
// Register commands |
|
15 |
ed.addCommand('wpFullScreenClose', function() { |
|
16 |
// this removes the editor, content has to be saved first with tinyMCE.execCommand('wpFullScreenSave'); |
|
17 |
if ( ed.getParam('wp_fullscreen_is_enabled') ) { |
|
18 |
DOM.win.setTimeout(function() { |
|
19 |
tinyMCE.remove(ed); |
|
20 |
DOM.remove('wp_mce_fullscreen_parent'); |
|
21 |
tinyMCE.settings = tinyMCE.oldSettings; // Restore old settings |
|
22 |
}, 10); |
|
23 |
} |
|
24 |
}); |
|
25 |
|
|
26 |
ed.addCommand('wpFullScreenSave', function() { |
|
27 |
var ed = tinyMCE.get('wp_mce_fullscreen'), edd; |
|
28 |
|
|
29 |
ed.focus(); |
|
30 |
edd = tinyMCE.get( ed.getParam('wp_fullscreen_editor_id') ); |
|
31 |
|
|
32 |
edd.setContent( ed.getContent({format : 'raw'}), {format : 'raw'} ); |
|
33 |
}); |
|
34 |
|
|
35 |
ed.addCommand('wpFullScreenInit', function() { |
|
36 |
var d, b, fsed; |
|
37 |
|
|
38 |
ed = tinyMCE.activeEditor; |
|
39 |
d = ed.getDoc(); |
|
40 |
b = d.body; |
|
41 |
|
|
42 |
tinyMCE.oldSettings = tinyMCE.settings; // Store old settings |
|
43 |
|
|
44 |
tinymce.each(ed.settings, function(v, n) { |
|
45 |
s[n] = v; |
|
46 |
}); |
|
47 |
|
|
48 |
s.id = 'wp_mce_fullscreen'; |
|
49 |
s.wp_fullscreen_is_enabled = true; |
|
50 |
s.wp_fullscreen_editor_id = ed.id; |
|
51 |
s.theme_advanced_resizing = false; |
|
52 |
s.theme_advanced_statusbar_location = 'none'; |
|
53 |
s.content_css = s.content_css ? s.content_css + ',' + s.wp_fullscreen_content_css : s.wp_fullscreen_content_css; |
|
54 |
s.height = tinymce.isIE ? b.scrollHeight : b.offsetHeight; |
|
55 |
|
|
56 |
tinymce.each(ed.getParam('wp_fullscreen_settings'), function(v, k) { |
|
57 |
s[k] = v; |
|
58 |
}); |
|
59 |
|
|
60 |
fsed = new tinymce.Editor('wp_mce_fullscreen', s); |
|
61 |
fsed.onInit.add(function(edd) { |
|
62 |
var DOM = tinymce.DOM, buttons = DOM.select('a.mceButton', DOM.get('wp-fullscreen-buttons')); |
|
63 |
|
|
64 |
if ( !ed.isHidden() ) |
|
65 |
edd.setContent( ed.getContent() ); |
|
66 |
else |
|
67 |
edd.setContent( switchEditors.wpautop( edd.getElement().value ) ); |
|
68 |
|
|
69 |
setTimeout(function(){ // add last |
|
70 |
edd.onNodeChange.add(function(ed, cm, e){ |
|
71 |
tinymce.each(buttons, function(c) { |
|
72 |
var btn, cls; |
|
73 |
|
|
74 |
if ( btn = DOM.get( 'wp_mce_fullscreen_' + c.id.substr(6) ) ) { |
|
75 |
cls = btn.className; |
|
76 |
|
|
77 |
if ( cls ) |
|
78 |
c.className = cls; |
|
79 |
} |
|
80 |
}); |
|
81 |
}); |
|
82 |
}, 1000); |
|
83 |
|
|
84 |
edd.dom.addClass(edd.getBody(), 'wp-fullscreen-editor'); |
|
85 |
edd.focus(); |
|
86 |
}); |
|
87 |
|
|
88 |
fsed.render(); |
|
89 |
|
|
90 |
if ( 'undefined' != fullscreen ) { |
|
91 |
fsed.dom.bind( fsed.dom.doc, 'mousemove', function(e){ |
|
92 |
fullscreen.bounder( 'showToolbar', 'hideToolbar', 2000, e ); |
|
93 |
}); |
|
94 |
} |
|
95 |
}); |
|
96 |
|
|
97 |
ed.addCommand('wpFullScreen', function() { |
|
98 |
if ( typeof(fullscreen) == 'undefined' ) |
|
99 |
return; |
|
100 |
|
|
101 |
if ( 'wp_mce_fullscreen' == ed.id ) |
|
102 |
fullscreen.off(); |
|
103 |
else |
|
104 |
fullscreen.on(); |
|
105 |
}); |
|
106 |
|
|
107 |
// Register buttons |
|
108 |
ed.addButton('wp_fullscreen', { |
|
109 |
title : 'wordpress.wp_fullscreen_desc', |
|
110 |
cmd : 'wpFullScreen' |
|
111 |
}); |
|
112 |
|
|
113 |
// END fullscreen |
|
114 |
//---------------------------------------------------------------- |
|
115 |
// START autoresize |
|
116 |
|
|
117 |
if ( ed.getParam('fullscreen_is_enabled') || !ed.getParam('wp_fullscreen_is_enabled') ) |
|
118 |
return; |
|
119 |
|
|
120 |
/** |
|
121 |
* This method gets executed each time the editor needs to resize. |
|
122 |
*/ |
|
123 |
function resize(editor, e) { |
|
124 |
var DOM = tinymce.DOM, body = ed.getBody(), ifr = DOM.get(ed.id + '_ifr'), height, y = ed.dom.win.scrollY; |
|
125 |
|
|
126 |
if ( t.resize_timeout ) |
|
127 |
return; |
|
128 |
|
|
129 |
// sometimes several events are fired few ms apart, trottle down resizing a little |
|
130 |
t.resize_timeout = true; |
|
131 |
setTimeout(function(){ |
|
132 |
t.resize_timeout = false; |
|
133 |
}, 500); |
|
134 |
|
|
135 |
height = body.scrollHeight > 300 ? body.scrollHeight : 300; |
|
136 |
|
|
137 |
if ( height != ifr.scrollHeight ) { |
|
138 |
DOM.setStyle(ifr, 'height', height + 'px'); |
|
139 |
ed.getWin().scrollTo(0, 0); // iframe window object, make sure there's no scrolling |
|
140 |
} |
|
141 |
|
|
142 |
// WebKit scrolls to top on paste... |
|
143 |
if ( e && e.type == 'paste' && tinymce.isWebKit ) { |
|
144 |
setTimeout(function(){ |
|
145 |
ed.dom.win.scrollTo(0, y); |
|
146 |
}, 40); |
|
147 |
} |
|
148 |
}; |
|
149 |
|
|
150 |
// Add appropriate listeners for resizing content area |
|
151 |
ed.onInit.add(function(ed, l) { |
|
152 |
ed.onChange.add(resize); |
|
153 |
ed.onSetContent.add(resize); |
|
154 |
ed.onPaste.add(resize); |
|
155 |
ed.onKeyUp.add(resize); |
|
156 |
ed.onPostRender.add(resize); |
|
157 |
|
|
158 |
ed.getBody().style.overflowY = "hidden"; |
|
159 |
}); |
|
160 |
|
|
161 |
if ( ed.getParam('autoresize_on_init', true) ) { |
|
162 |
ed.onLoadContent.add(function(ed, l) { |
|
163 |
// Because the content area resizes when its content CSS loads, |
|
164 |
// and we can't easily add a listener to its onload event, |
|
165 |
// we'll just trigger a resize after a short loading period |
|
166 |
setTimeout(function() { |
|
167 |
resize(); |
|
168 |
}, 1200); |
|
169 |
}); |
|
170 |
} |
|
171 |
|
|
172 |
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample'); |
|
173 |
ed.addCommand('wpAutoResize', resize); |
|
174 |
}, |
|
175 |
|
|
176 |
getInfo : function() { |
|
177 |
return { |
|
178 |
longname : 'WP Fullscreen', |
|
179 |
author : 'WordPress', |
|
180 |
authorurl : 'http://wordpress.org', |
|
181 |
infourl : '', |
|
182 |
version : '1.0' |
|
183 |
}; |
|
184 |
} |
|
185 |
}); |
|
186 |
|
|
187 |
// Register plugin |
|
188 |
tinymce.PluginManager.add('wpfullscreen', tinymce.plugins.wpFullscreenPlugin); |
|
189 |
})(); |