mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-27 03:27:46 +01:00
5e4a020ff8
Built from https://develop.svn.wordpress.org/trunk@29049 git-svn-id: http://core.svn.wordpress.org/trunk@28837 1a063a9b-81f0-0310-95a4-ce76da25c4cd
79 lines
2.0 KiB
JavaScript
79 lines
2.0 KiB
JavaScript
/* 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();
|
|
}
|
|
|
|
editor.addShortcut( 'alt+shift+w', '', 'wpFullScreen' );
|
|
});
|
|
|
|
// Register buttons
|
|
editor.addButton( 'wp_fullscreen', {
|
|
tooltip: 'Distraction Free Writing',
|
|
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',
|
|
icon: 'wp_fullscreen',
|
|
shortcut: 'Alt+Shift+W',
|
|
context: 'view',
|
|
onclick: toggleFullscreen
|
|
});
|
|
});
|