]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/js/tinymce/plugins/wpfullscreen/plugin.js
WordPress 4.0
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / wpfullscreen / plugin.js
1 /* global tinymce */
2 /**
3  * WP Fullscreen (Distraction Free Writing) TinyMCE plugin
4  */
5 tinymce.PluginManager.add( 'wpfullscreen', function( editor ) {
6         var settings = editor.settings;
7
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' );
13         }
14
15         function fullscreenOff() {
16                 settings.wp_fullscreen = false;
17                 editor.dom.removeClass( editor.getDoc().documentElement, 'wp-fullscreen' );
18                 // Stop auto-resizing
19                 editor.execCommand( 'wpAutoResizeOff' );
20         }
21
22         // For use from outside the editor.
23         editor.addCommand( 'wpFullScreenOn', fullscreenOn );
24         editor.addCommand( 'wpFullScreenOff', fullscreenOff );
25
26         function getExtAPI() {
27                 return ( typeof wp !== 'undefined' && wp.editor && wp.editor.fullscreen );
28         }
29
30         // Toggle DFW mode. For use from inside the editor.
31         function toggleFullscreen() {
32                 var fullscreen = getExtAPI();
33
34                 if ( fullscreen ) {
35                         if ( editor.getParam('wp_fullscreen') ) {
36                                 fullscreen.off();
37                         } else {
38                                 fullscreen.on();
39                         }
40                 }
41         }
42
43         editor.addCommand( 'wpFullScreen', toggleFullscreen );
44
45         editor.on( 'keydown', function( event ) {
46                 var fullscreen;
47
48                 // Turn fullscreen off when Esc is pressed.
49                 if ( event.keyCode === 27 && ( fullscreen = getExtAPI() ) && fullscreen.settings.visible ) {
50                         fullscreen.off();
51                 }
52         });
53
54         editor.on( 'init', function() {
55                 // Set the editor when initializing from whitin DFW
56                 if ( editor.getParam('wp_fullscreen') ) {
57                         fullscreenOn();
58                 }
59
60                 editor.addShortcut( 'alt+shift+w', '', 'wpFullScreen' );
61         });
62
63         // Register buttons
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!
69         });
70
71         editor.addMenuItem( 'wp_fullscreen', {
72                 text: 'Distraction Free Writing',
73                 icon: 'wp_fullscreen',
74                 shortcut: 'Alt+Shift+W',
75                 context: 'view',
76                 onclick: toggleFullscreen
77         });
78 });