+ function toggleViaKeyboard( event ) {
+ if ( event.altKey && event.shiftKey && 87 === event.keyCode ) {
+ toggle();
+ }
+ }
+
+ if ( $( '#postdivrich' ).hasClass( 'wp-editor-expand' ) ) {
+ $content.on( 'keydown.focus-shortcut', toggleViaKeyboard );
+ }
+
+ $document.on( 'tinymce-editor-setup.focus', function( event, editor ) {
+ editor.addButton( 'dfw', {
+ active: _isOn,
+ classes: 'wp-dfw btn widget',
+ disabled: ! _isActive,
+ onclick: toggle,
+ onPostRender: function() {
+ var button = this;
+
+ $document
+ .on( 'dfw-activate.focus', function() {
+ button.disabled( false );
+ } )
+ .on( 'dfw-deactivate.focus', function() {
+ button.disabled( true );
+ } )
+ .on( 'dfw-on.focus', function() {
+ button.active( true );
+ } )
+ .on( 'dfw-off.focus', function() {
+ button.active( false );
+ } );
+ },
+ tooltip: 'Distraction-free writing mode',
+ shortcut: 'Alt+Shift+W'
+ } );
+
+ editor.addCommand( 'wpToggleDFW', toggle );
+ editor.addShortcut( 'access+w', '', 'wpToggleDFW' );
+ } );
+
+ $document.on( 'tinymce-editor-init.focus', function( event, editor ) {
+ var mceBind, mceUnbind;
+
+ function focus() {
+ editorHasFocus = true;
+ }
+
+ function blur() {
+ editorHasFocus = false;
+ }
+
+ if ( editor.id === 'content' ) {
+ $editorWindow = $( editor.getWin() );
+ $editorIframe = $( editor.getContentAreaContainer() ).find( 'iframe' );
+
+ mceBind = function() {
+ editor.on( 'keydown', fadeOut );
+ editor.on( 'blur', maybeFadeIn );
+ editor.on( 'focus', focus );
+ editor.on( 'blur', blur );
+ editor.on( 'wp-autoresize', recalcEditorRect );
+ };
+
+ mceUnbind = function() {
+ editor.off( 'keydown', fadeOut );
+ editor.off( 'blur', maybeFadeIn );
+ editor.off( 'focus', focus );
+ editor.off( 'blur', blur );
+ editor.off( 'wp-autoresize', recalcEditorRect );
+ };
+
+ if ( _isOn ) {
+ mceBind();
+ }
+
+ $document.on( 'dfw-on.focus', mceBind ).on( 'dfw-off.focus', mceUnbind );
+
+ // Make sure the body focuses when clicking outside it.
+ editor.on( 'click', function( event ) {
+ if ( event.target === editor.getDoc().documentElement ) {
+ editor.focus();
+ }
+ } );
+ }
+ } );
+
+ $document.on( 'quicktags-init', function( event, editor ) {
+ var $button;
+
+ if ( editor.settings.buttons && ( ',' + editor.settings.buttons + ',' ).indexOf( ',dfw,' ) !== -1 ) {
+ $button = $( '#' + editor.name + '_dfw' );
+
+ $( document )
+ .on( 'dfw-activate', function() {
+ $button.prop( 'disabled', false );
+ } )
+ .on( 'dfw-deactivate', function() {
+ $button.prop( 'disabled', true );
+ } )
+ .on( 'dfw-on', function() {
+ $button.addClass( 'active' );
+ } )
+ .on( 'dfw-off', function() {
+ $button.removeClass( 'active' );
+ } );
+ }
+ } );
+
+ $document.on( 'editor-expand-on.focus', activate ).on( 'editor-expand-off.focus', deactivate );
+
+ if ( _isOn ) {
+ $content.on( 'keydown.focus', fadeOut );
+
+ $title.add( $content ).on( 'blur.focus', maybeFadeIn );