3 * WP Fullscreen (Distraction Free Writing) TinyMCE plugin
5 tinymce.PluginManager.add( 'wpfullscreen', function( editor ) {
6 var settings = editor.settings;
8 function fullscreenOn() {
9 settings.wp_fullscreen = true;
10 editor.dom.addClass( editor.getDoc().documentElement, 'wp-fullscreen' );
11 // Start auto-resizing
12 editor.execCommand( 'wpAutoResizeOn' );
15 function fullscreenOff() {
16 settings.wp_fullscreen = false;
17 editor.dom.removeClass( editor.getDoc().documentElement, 'wp-fullscreen' );
19 editor.execCommand( 'wpAutoResizeOff' );
22 // For use from outside the editor.
23 editor.addCommand( 'wpFullScreenOn', fullscreenOn );
24 editor.addCommand( 'wpFullScreenOff', fullscreenOff );
26 function getExtAPI() {
27 return ( typeof wp !== 'undefined' && wp.editor && wp.editor.fullscreen );
30 // Toggle DFW mode. For use from inside the editor.
31 function toggleFullscreen() {
32 var fullscreen = getExtAPI();
35 if ( editor.getParam('wp_fullscreen') ) {
43 editor.addCommand( 'wpFullScreen', toggleFullscreen );
45 editor.on( 'keydown', function( event ) {
48 // Turn fullscreen off when Esc is pressed.
49 if ( event.keyCode === 27 && ( fullscreen = getExtAPI() ) && fullscreen.settings.visible ) {
54 editor.on( 'init', function() {
55 // Set the editor when initializing from whitin DFW
56 if ( editor.getParam('wp_fullscreen') ) {
60 editor.addShortcut( 'alt+shift+w', '', 'wpFullScreen' );
64 editor.addButton( 'wp_fullscreen', {
65 tooltip: 'Distraction Free Writing',
66 shortcut: 'Alt+Shift+W',
67 onclick: toggleFullscreen,
68 classes: 'wp-fullscreen btn widget' // This overwrites all classes on the container!
71 editor.addMenuItem( 'wp_fullscreen', {
72 text: 'Distraction Free Writing',
73 icon: 'wp_fullscreen',
74 shortcut: 'Alt+Shift+W',
76 onclick: toggleFullscreen