3 * WP Fullscreen (Distraction Free Writing) TinyMCE plugin
5 tinymce.PluginManager.add( 'wpfullscreen', function( editor ) {
6 var settings = editor.settings,
10 var deltaSize, myHeight,
16 if ( ( e && e.type === 'setcontent' && e.initial ) || editor.settings.inline ) {
20 // Get height differently depending on the browser used
21 myHeight = tinymce.Env.ie ? body.scrollHeight : ( tinymce.Env.webkit && body.clientHeight === 0 ? 0 : body.offsetHeight );
23 // Don't make it smaller than 250px
24 if ( myHeight > 250 ) {
25 resizeHeight = myHeight;
30 // Resize content element
31 if ( resizeHeight !== oldSize ) {
32 deltaSize = resizeHeight - oldSize;
33 DOM.setStyle( DOM.get( editor.id + '_ifr' ), 'height', resizeHeight + 'px' );
34 oldSize = resizeHeight;
36 // WebKit doesn't decrease the size of the body element until the iframe gets resized
37 // So we need to continue to resize the iframe down until the size gets fixed
38 if ( tinymce.isWebKit && deltaSize < 0 ) {
44 // Register the command
45 editor.addCommand( 'wpAutoResize', resize );
47 function fullscreenOn() {
48 settings.wp_fullscreen = true;
49 editor.dom.addClass( editor.getDoc().documentElement, 'wp-fullscreen' );
50 // Add listeners for auto-resizing
51 editor.on( 'change setcontent paste keyup', resize );
54 function fullscreenOff() {
55 settings.wp_fullscreen = false;
56 editor.dom.removeClass( editor.getDoc().documentElement, 'wp-fullscreen' );
57 // Remove listeners for auto-resizing
58 editor.off( 'change setcontent paste keyup', resize );
62 // For use from outside the editor.
63 editor.addCommand( 'wpFullScreenOn', fullscreenOn );
64 editor.addCommand( 'wpFullScreenOff', fullscreenOff );
66 function toggleFullscreen() {
67 // Toggle DFW mode. For use from inside the editor.
68 if ( typeof wp === 'undefined' || ! wp.editor || ! wp.editor.fullscreen ) {
72 if ( editor.getParam('wp_fullscreen') ) {
73 wp.editor.fullscreen.off();
75 wp.editor.fullscreen.on();
79 editor.addCommand( 'wpFullScreen', toggleFullscreen );
81 editor.on( 'init', function() {
82 // Set the editor when initializing from whitin DFW
83 if ( editor.getParam('wp_fullscreen') ) {
87 editor.addShortcut( 'alt+shift+w', '', 'wpFullScreen' );
91 editor.addButton( 'wp_fullscreen', {
92 tooltip: 'Distraction Free Writing',
93 shortcut: 'Alt+Shift+W',
94 onclick: toggleFullscreen,
95 classes: 'wp-fullscreen btn widget' // This overwrites all classes on the container!
98 editor.addMenuItem( 'wp_fullscreen', {
99 text: 'Distraction Free Writing',
100 icon: 'wp_fullscreen',
101 shortcut: 'Alt+Shift+W',
103 onclick: toggleFullscreen