| 392 | /** |
| 393 | * |
| 394 | * Disable the publish button for a new post, re-enable once |
| 395 | * some content is entered. |
| 396 | * |
| 397 | */ |
| 398 | $( document ).on('tinymce-editor-init', function() { |
| 399 | /** |
| 400 | * Bail if the current page is not post-new.php. |
| 401 | */ |
| 402 | if ( ! window.adminpage || 'post-new-php' !== window.adminpage ) { |
| 403 | return; |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * Cached selectors for the publish button, editor, title and excerpt. |
| 408 | */ |
| 409 | var $button = $submitpost.find( ':submit, a.submitdelete, #post-preview' ), |
| 410 | $editor = tinymce.activeEditor, |
| 411 | $title = $( 'input#title' ), |
| 412 | $excerpt = $( 'textarea#excerpt' ), |
| 413 | |
| 414 | /** |
| 415 | * Only enable button once. |
| 416 | */ |
| 417 | stopMonitoringAndResetStatus = function() { |
| 418 | $editor.off( 'change' ); |
| 419 | $title.off( 'keyup' ); |
| 420 | $excerpt.off( 'keyup' ); |
| 421 | $button.removeClass( 'disabled' ); |
| 422 | }; |
| 423 | |
| 424 | /** |
| 425 | * Disable publish for new posts. |
| 426 | */ |
| 427 | $button.addClass( 'disabled' ); |
| 428 | |
| 429 | /** |
| 430 | * Monitor changes in the title, TinyMCE content and excerpt, enabling |
| 431 | * the publish button (by removing the 'disabled' class). |
| 432 | */ |
| 433 | $editor.on( 'change', function() { |
| 434 | stopMonitoringAndResetStatus(); |
| 435 | }); |
| 436 | $title.on( 'keyup', function() { |
| 437 | stopMonitoringAndResetStatus(); |
| 438 | }); |
| 439 | $excerpt.on( 'keyup', function() { |
| 440 | stopMonitoringAndResetStatus(); |
| 441 | }); |
| 442 | }); |
| 443 | |