Don't load autosave.js on the attachment editing screen, add simple AYS on unload if there are changes, props helenyhou, fixes #22491

git-svn-id: http://core.svn.wordpress.org/trunk@22725 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2012-11-20 19:46:38 +00:00
parent 0bc99fe9f5
commit 0e38402629
3 changed files with 23 additions and 2 deletions

View File

@ -418,3 +418,21 @@ if ( post_type_supports( $post_type, 'comments' ) )
try{document.post.title.focus();}catch(e){}
</script>
<?php endif; ?>
<?php if ( 'attachment' == $post_type ) { ?>
<script type="text/javascript">
(function($){
function getFieldsContent() {
return ($('#title').val() || '') + ($('#attachment_caption').val() || '') +
($('#attachment_alt').val() || '') + ($('#attachment_content').val() || '') + ($('#post_name').val() || '');
}
var initial = getFieldsContent();
window.onbeforeunload = function() {
if ( initial != getFieldsContent() )
return '<?php _e('The changes you made will be lost if you navigate away from this page.'); ?>';
};
})(jQuery);
</script>
<?php } ?>

View File

@ -43,7 +43,8 @@ if ( ! current_user_can( $post_type_object->cap->edit_posts ) || ! current_user_
if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) )
wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
wp_enqueue_script('autosave');
if ( 'attachment' !== $post_type )
wp_enqueue_script('autosave');
// Show post form.
$post = get_default_post_to_edit( $post_type, true );

View File

@ -169,7 +169,9 @@ case 'edit':
add_action('admin_notices', '_admin_notice_post_locked' );
} else {
$active_post_lock = wp_set_post_lock( $post->ID );
wp_enqueue_script('autosave');
if ( 'attachment' !== $post_type )
wp_enqueue_script('autosave');
}
$title = $post_type_object->labels->edit_item;