Make WordPress Core

Ticket #24756: 24756-4.patch

File 24756-4.patch, 4.4 KB (added by azaozz, 12 years ago)
  • wp-includes/js/autosave.js

     
    524524        init: function( settings ) {
    525525                var self = this;
    526526
    527                 // Check if the browser supports sessionStorage and editor.js is loaded
    528                 if ( ! this.checkStorage() || typeof switchEditors == 'undefined' )
     527                // Check if the browser supports sessionStorage and it's not disabled
     528                if ( ! this.checkStorage() )
    529529                        return;
    530530
    531531                // Don't run if the post type supports neither 'editor' (textarea#content) nor 'excerpt'.
     
    538538                if ( !this.blog_id )
    539539                        this.blog_id = typeof window.autosaveL10n != 'undefined' ? window.autosaveL10n.blog_id : 0;
    540540
    541                 this.checkPost();
    542541                $(document).ready( function(){ self.run(); } );
    543542        },
    544543
    545544        // Run on DOM ready
    546545        run: function() {
    547                 var self = this, post_data;
     546                var self = this;
    548547
    549                 // Set the comparison string
    550                 if ( !this.lastsaveddata ) {
    551                         post_data = wp.autosave.getPostData();
     548                // Check if the local post data is different than the loaded post data.
     549                this.checkPost();
    552550
    553                         if ( post_data.content && $('#wp-content-wrap').hasClass('tmce-active') )
    554                                 this.lastsaveddata = post_data.post_title + ': ' + switchEditors.pre_wpautop( post_data.content );
    555                         else
    556                                 this.lastsaveddata = post_data.post_title + ': ' + post_data.content;
    557                 }
    558 
    559551                // Set the schedule
    560552                this.schedule = $.schedule({
    561553                        time: 15 * 1000,
     
    605597         * @return void
    606598         */
    607599        checkPost: function() {
    608                 var self = this, post_data = this.getData(), content, check_data, strip_tags = false, notice,
     600                var self = this, post_data = this.getData(), content, post_title, excerpt, notice,
    609601                        post_id = $('#post_ID').val() || 0, cookie = wpCookies.get( 'wp-saving-post-' + post_id );
    610602
    611603                if ( ! post_data )
     
    625617                if ( $('#has-newer-autosave').length )
    626618                        return;
    627619
    628                 // cookie == 'check' means the post was not saved properly, always show #local-storage-notice
    629                 if ( cookie != 'check' ) {
    630                         content = $('#content').val();
    631                         check_data = $.extend( {}, post_data );
     620                content = $('#content').val() || '';
     621                post_title = $('#title').val() || '';
     622                excerpt = $('#excerpt').val() || '';
    632623
    633                         if ( $('#wp-content-wrap').hasClass('tmce-active') )
    634                                 content = switchEditors.pre_wpautop( content );
     624                if ( $('#wp-content-wrap').hasClass('tmce-active') && typeof switchEditors != 'undefined' )
     625                        content = switchEditors.pre_wpautop( content );
    635626
    636                         if ( this.compare( content, check_data.content ) && this.compare( $('#title').val(), check_data.post_title ) && this.compare( $('#excerpt').val(), check_data.excerpt ) )
    637                                 return;
     627                // cookie == 'check' means the post was not saved properly, always show #local-storage-notice
     628                if ( cookie != 'check' && this.compare( content, post_data.content ) && this.compare( title, post_data.post_title ) && this.compare( excerpt, post_data.excerpt ) ) {
     629                        return;
    638630                }
    639631
    640632                this.restore_post_data = post_data;
    641                 this.undo_post_data = wp.autosave.getPostData();
     633                this.undo_post_data = {
     634                        content: content,
     635                        post_title: post_title,
     636                        excerpt: excerpt
     637                };
    642638
    643639                notice = $('#local-storage-notice');
    644640                $('.wrap h2').first().after( notice.addClass('updated').show() );
     
    674670                        $('#excerpt').val( post_data.excerpt || '' );
    675671                        editor = typeof tinymce != 'undefined' && tinymce.get('content');
    676672
    677                         if ( editor && ! editor.isHidden() ) {
     673                        if ( editor && ! editor.isHidden() && typeof switchEditors != 'undefined' ) {
    678674                                // Make sure there's an undo level in the editor
    679675                                editor.undoManager.add();
    680676                                editor.setContent( post_data.content ? switchEditors.wpautop( post_data.content ) : '' );
  • wp-includes/script-loader.php

     
    103103                'dismiss' => __('Dismiss'),
    104104        ) );
    105105
    106         $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response', 'editor'), false, 1 );
     106        $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), false, 1 );
    107107
    108108        $scripts->add( 'heartbeat', "/wp-includes/js/heartbeat$suffix.js", array('jquery'), false, 1 );
    109109        did_action( 'init' ) && $scripts->localize( 'heartbeat', 'heartbeatSettings',