Make WordPress Core

Ticket #17115: 17115.4.diff

File 17115.4.diff, 1.8 KB (added by adamsilverstein, 10 years ago)

disable publish button on load, re-enable on change

  • src/wp-admin/js/post.js

     
    389389
    390390        postboxes.add_postbox_toggles(pagenow);
    391391
     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
    392444        // Clear the window name. Otherwise if this is a former preview window where the user navigated to edit another post,
    393445        // and the first post is still being edited, clicking Preview there will use this window to show the preview.
    394446        window.name = '';