| | 361 | |
| | 362 | function autosave_prepare_data_to_save( ) { |
| | 363 | |
| | 364 | var post_data = { |
| | 365 | action: "autosave", |
| | 366 | post_ID: jQuery("#post_ID").val() || 0, |
| | 367 | post_type: jQuery('#post_type').val() || "" |
| | 368 | }; |
| | 369 | |
| | 370 | if ( fullscreen && fullscreen.settings.visible ) { |
| | 371 | post_data["post_title"] = jQuery('#wp-fullscreen-title').val() || ''; |
| | 372 | post_data["content"] = jQuery("#wp_mce_fullscreen").val() || ''; |
| | 373 | } else { |
| | 374 | post_data["post_title"] = jQuery("#title").val() || ''; |
| | 375 | post_data["content"] = jQuery("#content").val() || ''; |
| | 376 | } |
| | 377 | |
| | 378 | if ( jQuery('#post_name').val() ) |
| | 379 | post_data["post_name"] = jQuery('#post_name').val(); |
| | 380 | |
| | 381 | var cats = ([]); |
| | 382 | |
| | 383 | jQuery("[name='post_category[]']:checked").each( function(i) { |
| | 384 | cats.push(this.value); |
| | 385 | } ); |
| | 386 | post_data["catslist"] = cats.join(","); |
| | 387 | |
| | 388 | if ( jQuery("#comment_status").prop("checked") ) |
| | 389 | post_data["comment_status"] = 'open'; |
| | 390 | if ( jQuery("#ping_status").prop("checked") ) |
| | 391 | post_data["ping_status"] = 'open'; |
| | 392 | if ( jQuery("#excerpt").size() ) |
| | 393 | post_data["excerpt"] = jQuery("#excerpt").val(); |
| | 394 | if ( jQuery("#post_author").size() ) |
| | 395 | post_data["post_author"] = jQuery("#post_author").val(); |
| | 396 | if ( jQuery("#parent_id").val() ) |
| | 397 | post_data["parent_id"] = jQuery("#parent_id").val(); |
| | 398 | post_data["user_ID"] = jQuery("#user-id").val(); |
| | 399 | if ( jQuery('#auto_draft').val() == '1' ) |
| | 400 | post_data["auto_draft"] = '1'; |
| | 401 | |
| | 402 | return post_data; |
| | 403 | |
| | 404 | } |
| | 405 | |
| | 406 | function autosave_set_local_storage( ) { |
| | 407 | |
| | 408 | if ( window.localStorage ) { |
| | 409 | |
| | 410 | var post_id = jQuery("#post_ID").val() || 0; |
| | 411 | |
| | 412 | if( 0 < post_id ) { |
| | 413 | |
| | 414 | var post_data = autosave_prepare_data_to_save(); |
| | 415 | |
| | 416 | //if the content and title did not change from last server save,dont keep data in local storage |
| | 417 | if ( ( post_data["post_title"].length == 0 && post_data["content"].length == 0 ) || post_data["post_title"] + post_data["content"] == autosaveLast ) { |
| | 418 | autosave_delete_local_storage( post_id ) |
| | 419 | } else { |
| | 420 | localStorage.setItem( autosaveL10n.blog_id+'_'+post_id, JSON.stringify( post_data ) ); |
| | 421 | } |
| | 422 | } |
| | 423 | } |
| | 424 | |
| | 425 | } |
| | 426 | |
| | 427 | function autosave_get_local_storage( post_id ) { |
| | 428 | |
| | 429 | if ( window.localStorage ) { |
| | 430 | return JSON.parse( localStorage.getItem( autosaveL10n.blog_id+'_'+post_id ) ); |
| | 431 | } |
| | 432 | |
| | 433 | } |
| | 434 | |
| | 435 | function autosave_delete_local_storage( post_id ) { |
| | 436 | |
| | 437 | if ( window.localStorage ) { |
| | 438 | localStorage.removeItem( autosaveL10n.blog_id+'_'+post_id ); |
| | 439 | } |
| | 440 | |
| | 441 | } |