- md5
- dd83030fdd725c148b2b7a4aded9da13
- sha1
- a090b6f3d047fd754530da0f38706b5c9e9a69ae
- sha256
- c81af8106f5fa5f373e0d007b46f89870d148e09e3b805d6896c93a56e811508
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
/* global tinymce */
/**
* WP Fullscreen (Distraction-Free Writing) TinyMCE plugin
*/
tinymce.PluginManager.add( 'wpfullscreen', function( editor ) {
var settings = editor.settings;
function fullscreenOn() {
settings.wp_fullscreen = true;
editor.dom.addClass( editor.getDoc().documentElement, 'wp-fullscreen' );
// Start auto-resizing
editor.execCommand( 'wpAutoResizeOn' );
}
function fullscreenOff() {
settings.wp_fullscreen = false;
editor.dom.removeClass( editor.getDoc().documentElement, 'wp-fullscreen' );
// Stop auto-resizing
editor.execCommand( 'wpAutoResizeOff' );
}
// For use from outside the editor.
editor.addCommand( 'wpFullScreenOn', fullscreenOn );
editor.addCommand( 'wpFullScreenOff', fullscreenOff );
function getExtAPI() {
return ( typeof wp !== 'undefined' && wp.editor && wp.editor.fullscreen );
}
// Toggle DFW mode. For use from inside the editor.
function toggleFullscreen() {
var fullscreen = getExtAPI();
if ( fullscreen ) {
if ( editor.getParam('wp_fullscreen') ) {
fullscreen.off();
} else {
fullscreen.on();
}
}
}
editor.addCommand( 'wpFullScreen', toggleFullscreen );
editor.on( 'keydown', function( event ) {
var fullscreen;
// Turn fullscreen off when Esc is pressed.
if ( event.keyCode === 27 && ( fullscreen = getExtAPI() ) && fullscreen.settings.visible ) {
fullscreen.off();
}
});
editor.on( 'init', function() {
// Set the editor when initializing from whitin DFW
if ( editor.getParam('wp_fullscreen') ) {
fullscreenOn();
}
});
// Register buttons
editor.addButton( 'wp_fullscreen', {
tooltip: 'Distraction-free writing mode',
shortcut: 'Alt+Shift+W',
onclick: toggleFullscreen,
classes: 'wp-fullscreen btn widget' // This overwrites all classes on the container!
});
editor.addMenuItem( 'wp_fullscreen', {
text: 'Distraction-free writing mode',
icon: 'wp_fullscreen',
shortcut: 'Alt+Shift+W',
context: 'view',
onclick: toggleFullscreen
});
});
The same content is in 94 releases, WordPress 4.1-RC2 to 4.2.39. See them all, or every version of this file.