Edit File by line
/home/barbar84/public_h.../wp-admin/js
File: post.js
/**
[0] Fix | Delete
* @file Contains all dynamic functionality needed on post and term pages.
[1] Fix | Delete
*
[2] Fix | Delete
* @output wp-admin/js/post.js
[3] Fix | Delete
*/
[4] Fix | Delete
[5] Fix | Delete
/* global ajaxurl, wpAjax, postboxes, pagenow, tinymce, alert, deleteUserSetting, ClipboardJS */
[6] Fix | Delete
/* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply, commentsBox */
[7] Fix | Delete
/* global WPSetThumbnailHTML, wptitlehint */
[8] Fix | Delete
[9] Fix | Delete
// Backward compatibility: prevent fatal errors.
[10] Fix | Delete
window.makeSlugeditClickable = window.editPermalink = function(){};
[11] Fix | Delete
[12] Fix | Delete
// Make sure the wp object exists.
[13] Fix | Delete
window.wp = window.wp || {};
[14] Fix | Delete
[15] Fix | Delete
( function( $ ) {
[16] Fix | Delete
var titleHasFocus = false,
[17] Fix | Delete
__ = wp.i18n.__;
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Control loading of comments on the post and term edit pages.
[21] Fix | Delete
*
[22] Fix | Delete
* @type {{st: number, get: commentsBox.get, load: commentsBox.load}}
[23] Fix | Delete
*
[24] Fix | Delete
* @namespace commentsBox
[25] Fix | Delete
*/
[26] Fix | Delete
window.commentsBox = {
[27] Fix | Delete
// Comment offset to use when fetching new comments.
[28] Fix | Delete
st : 0,
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Fetch comments using Ajax and display them in the box.
[32] Fix | Delete
*
[33] Fix | Delete
* @memberof commentsBox
[34] Fix | Delete
*
[35] Fix | Delete
* @param {number} total Total number of comments for this post.
[36] Fix | Delete
* @param {number} num Optional. Number of comments to fetch, defaults to 20.
[37] Fix | Delete
* @return {boolean} Always returns false.
[38] Fix | Delete
*/
[39] Fix | Delete
get : function(total, num) {
[40] Fix | Delete
var st = this.st, data;
[41] Fix | Delete
if ( ! num )
[42] Fix | Delete
num = 20;
[43] Fix | Delete
[44] Fix | Delete
this.st += num;
[45] Fix | Delete
this.total = total;
[46] Fix | Delete
$( '#commentsdiv .spinner' ).addClass( 'is-active' );
[47] Fix | Delete
[48] Fix | Delete
data = {
[49] Fix | Delete
'action' : 'get-comments',
[50] Fix | Delete
'mode' : 'single',
[51] Fix | Delete
'_ajax_nonce' : $('#add_comment_nonce').val(),
[52] Fix | Delete
'p' : $('#post_ID').val(),
[53] Fix | Delete
'start' : st,
[54] Fix | Delete
'number' : num
[55] Fix | Delete
};
[56] Fix | Delete
[57] Fix | Delete
$.post(
[58] Fix | Delete
ajaxurl,
[59] Fix | Delete
data,
[60] Fix | Delete
function(r) {
[61] Fix | Delete
r = wpAjax.parseAjaxResponse(r);
[62] Fix | Delete
$('#commentsdiv .widefat').show();
[63] Fix | Delete
$( '#commentsdiv .spinner' ).removeClass( 'is-active' );
[64] Fix | Delete
[65] Fix | Delete
if ( 'object' == typeof r && r.responses[0] ) {
[66] Fix | Delete
$('#the-comment-list').append( r.responses[0].data );
[67] Fix | Delete
[68] Fix | Delete
theList = theExtraList = null;
[69] Fix | Delete
$( 'a[className*=\':\']' ).off();
[70] Fix | Delete
[71] Fix | Delete
// If the offset is over the total number of comments we cannot fetch any more, so hide the button.
[72] Fix | Delete
if ( commentsBox.st > commentsBox.total )
[73] Fix | Delete
$('#show-comments').hide();
[74] Fix | Delete
else
[75] Fix | Delete
$('#show-comments').show().children('a').text( __( 'Show more comments' ) );
[76] Fix | Delete
[77] Fix | Delete
return;
[78] Fix | Delete
} else if ( 1 == r ) {
[79] Fix | Delete
$('#show-comments').text( __( 'No more comments found.' ) );
[80] Fix | Delete
return;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
$('#the-comment-list').append('<tr><td colspan="2">'+wpAjax.broken+'</td></tr>');
[84] Fix | Delete
}
[85] Fix | Delete
);
[86] Fix | Delete
[87] Fix | Delete
return false;
[88] Fix | Delete
},
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* Load the next batch of comments.
[92] Fix | Delete
*
[93] Fix | Delete
* @memberof commentsBox
[94] Fix | Delete
*
[95] Fix | Delete
* @param {number} total Total number of comments to load.
[96] Fix | Delete
*/
[97] Fix | Delete
load: function(total){
[98] Fix | Delete
this.st = jQuery('#the-comment-list tr.comment:visible').length;
[99] Fix | Delete
this.get(total);
[100] Fix | Delete
}
[101] Fix | Delete
};
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Overwrite the content of the Featured Image postbox
[105] Fix | Delete
*
[106] Fix | Delete
* @param {string} html New HTML to be displayed in the content area of the postbox.
[107] Fix | Delete
*
[108] Fix | Delete
* @global
[109] Fix | Delete
*/
[110] Fix | Delete
window.WPSetThumbnailHTML = function(html){
[111] Fix | Delete
$('.inside', '#postimagediv').html(html);
[112] Fix | Delete
};
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* Set the Image ID of the Featured Image
[116] Fix | Delete
*
[117] Fix | Delete
* @param {number} id The post_id of the image to use as Featured Image.
[118] Fix | Delete
*
[119] Fix | Delete
* @global
[120] Fix | Delete
*/
[121] Fix | Delete
window.WPSetThumbnailID = function(id){
[122] Fix | Delete
var field = $('input[value="_thumbnail_id"]', '#list-table');
[123] Fix | Delete
if ( field.length > 0 ) {
[124] Fix | Delete
$('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id);
[125] Fix | Delete
}
[126] Fix | Delete
};
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Remove the Featured Image
[130] Fix | Delete
*
[131] Fix | Delete
* @param {string} nonce Nonce to use in the request.
[132] Fix | Delete
*
[133] Fix | Delete
* @global
[134] Fix | Delete
*/
[135] Fix | Delete
window.WPRemoveThumbnail = function(nonce){
[136] Fix | Delete
$.post(ajaxurl, {
[137] Fix | Delete
action: 'set-post-thumbnail', post_id: $( '#post_ID' ).val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie )
[138] Fix | Delete
},
[139] Fix | Delete
/**
[140] Fix | Delete
* Handle server response
[141] Fix | Delete
*
[142] Fix | Delete
* @param {string} str Response, will be '0' when an error occurred otherwise contains link to add Featured Image.
[143] Fix | Delete
*/
[144] Fix | Delete
function(str){
[145] Fix | Delete
if ( str == '0' ) {
[146] Fix | Delete
alert( __( 'Could not set that as the thumbnail image. Try a different attachment.' ) );
[147] Fix | Delete
} else {
[148] Fix | Delete
WPSetThumbnailHTML(str);
[149] Fix | Delete
}
[150] Fix | Delete
}
[151] Fix | Delete
);
[152] Fix | Delete
};
[153] Fix | Delete
[154] Fix | Delete
/**
[155] Fix | Delete
* Heartbeat locks.
[156] Fix | Delete
*
[157] Fix | Delete
* Used to lock editing of an object by only one user at a time.
[158] Fix | Delete
*
[159] Fix | Delete
* When the user does not send a heartbeat in a heartbeat-time
[160] Fix | Delete
* the user is no longer editing and another user can start editing.
[161] Fix | Delete
*/
[162] Fix | Delete
$(document).on( 'heartbeat-send.refresh-lock', function( e, data ) {
[163] Fix | Delete
var lock = $('#active_post_lock').val(),
[164] Fix | Delete
post_id = $('#post_ID').val(),
[165] Fix | Delete
send = {};
[166] Fix | Delete
[167] Fix | Delete
if ( ! post_id || ! $('#post-lock-dialog').length )
[168] Fix | Delete
return;
[169] Fix | Delete
[170] Fix | Delete
send.post_id = post_id;
[171] Fix | Delete
[172] Fix | Delete
if ( lock )
[173] Fix | Delete
send.lock = lock;
[174] Fix | Delete
[175] Fix | Delete
data['wp-refresh-post-lock'] = send;
[176] Fix | Delete
[177] Fix | Delete
}).on( 'heartbeat-tick.refresh-lock', function( e, data ) {
[178] Fix | Delete
// Post locks: update the lock string or show the dialog if somebody has taken over editing.
[179] Fix | Delete
var received, wrap, avatar;
[180] Fix | Delete
[181] Fix | Delete
if ( data['wp-refresh-post-lock'] ) {
[182] Fix | Delete
received = data['wp-refresh-post-lock'];
[183] Fix | Delete
[184] Fix | Delete
if ( received.lock_error ) {
[185] Fix | Delete
// Show "editing taken over" message.
[186] Fix | Delete
wrap = $('#post-lock-dialog');
[187] Fix | Delete
[188] Fix | Delete
if ( wrap.length && ! wrap.is(':visible') ) {
[189] Fix | Delete
if ( wp.autosave ) {
[190] Fix | Delete
// Save the latest changes and disable.
[191] Fix | Delete
$(document).one( 'heartbeat-tick', function() {
[192] Fix | Delete
wp.autosave.server.suspend();
[193] Fix | Delete
wrap.removeClass('saving').addClass('saved');
[194] Fix | Delete
$(window).off( 'beforeunload.edit-post' );
[195] Fix | Delete
});
[196] Fix | Delete
[197] Fix | Delete
wrap.addClass('saving');
[198] Fix | Delete
wp.autosave.server.triggerSave();
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
if ( received.lock_error.avatar_src ) {
[202] Fix | Delete
avatar = $( '<img />', {
[203] Fix | Delete
'class': 'avatar avatar-64 photo',
[204] Fix | Delete
width: 64,
[205] Fix | Delete
height: 64,
[206] Fix | Delete
alt: '',
[207] Fix | Delete
src: received.lock_error.avatar_src,
[208] Fix | Delete
srcset: received.lock_error.avatar_src_2x ? received.lock_error.avatar_src_2x + ' 2x' : undefined
[209] Fix | Delete
} );
[210] Fix | Delete
wrap.find('div.post-locked-avatar').empty().append( avatar );
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
wrap.show().find('.currently-editing').text( received.lock_error.text );
[214] Fix | Delete
wrap.find('.wp-tab-first').trigger( 'focus' );
[215] Fix | Delete
}
[216] Fix | Delete
} else if ( received.new_lock ) {
[217] Fix | Delete
$('#active_post_lock').val( received.new_lock );
[218] Fix | Delete
}
[219] Fix | Delete
}
[220] Fix | Delete
}).on( 'before-autosave.update-post-slug', function() {
[221] Fix | Delete
titleHasFocus = document.activeElement && document.activeElement.id === 'title';
[222] Fix | Delete
}).on( 'after-autosave.update-post-slug', function() {
[223] Fix | Delete
[224] Fix | Delete
/*
[225] Fix | Delete
* Create slug area only if not already there
[226] Fix | Delete
* and the title field was not focused (user was not typing a title) when autosave ran.
[227] Fix | Delete
*/
[228] Fix | Delete
if ( ! $('#edit-slug-box > *').length && ! titleHasFocus ) {
[229] Fix | Delete
$.post( ajaxurl, {
[230] Fix | Delete
action: 'sample-permalink',
[231] Fix | Delete
post_id: $('#post_ID').val(),
[232] Fix | Delete
new_title: $('#title').val(),
[233] Fix | Delete
samplepermalinknonce: $('#samplepermalinknonce').val()
[234] Fix | Delete
},
[235] Fix | Delete
function( data ) {
[236] Fix | Delete
if ( data != '-1' ) {
[237] Fix | Delete
$('#edit-slug-box').html(data);
[238] Fix | Delete
}
[239] Fix | Delete
}
[240] Fix | Delete
);
[241] Fix | Delete
}
[242] Fix | Delete
});
[243] Fix | Delete
[244] Fix | Delete
}(jQuery));
[245] Fix | Delete
[246] Fix | Delete
/**
[247] Fix | Delete
* Heartbeat refresh nonces.
[248] Fix | Delete
*/
[249] Fix | Delete
(function($) {
[250] Fix | Delete
var check, timeout;
[251] Fix | Delete
[252] Fix | Delete
/**
[253] Fix | Delete
* Only allow to check for nonce refresh every 30 seconds.
[254] Fix | Delete
*/
[255] Fix | Delete
function schedule() {
[256] Fix | Delete
check = false;
[257] Fix | Delete
window.clearTimeout( timeout );
[258] Fix | Delete
timeout = window.setTimeout( function(){ check = true; }, 300000 );
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
$(document).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) {
[262] Fix | Delete
var post_id,
[263] Fix | Delete
$authCheck = $('#wp-auth-check-wrap');
[264] Fix | Delete
[265] Fix | Delete
if ( check || ( $authCheck.length && ! $authCheck.hasClass( 'hidden' ) ) ) {
[266] Fix | Delete
if ( ( post_id = $('#post_ID').val() ) && $('#_wpnonce').val() ) {
[267] Fix | Delete
data['wp-refresh-post-nonces'] = {
[268] Fix | Delete
post_id: post_id
[269] Fix | Delete
};
[270] Fix | Delete
}
[271] Fix | Delete
}
[272] Fix | Delete
}).on( 'heartbeat-tick.wp-refresh-nonces', function( e, data ) {
[273] Fix | Delete
var nonces = data['wp-refresh-post-nonces'];
[274] Fix | Delete
[275] Fix | Delete
if ( nonces ) {
[276] Fix | Delete
schedule();
[277] Fix | Delete
[278] Fix | Delete
if ( nonces.replace ) {
[279] Fix | Delete
$.each( nonces.replace, function( selector, value ) {
[280] Fix | Delete
$( '#' + selector ).val( value );
[281] Fix | Delete
});
[282] Fix | Delete
}
[283] Fix | Delete
[284] Fix | Delete
if ( nonces.heartbeatNonce )
[285] Fix | Delete
window.heartbeatSettings.nonce = nonces.heartbeatNonce;
[286] Fix | Delete
}
[287] Fix | Delete
}).ready( function() {
[288] Fix | Delete
schedule();
[289] Fix | Delete
});
[290] Fix | Delete
}(jQuery));
[291] Fix | Delete
[292] Fix | Delete
/**
[293] Fix | Delete
* All post and postbox controls and functionality.
[294] Fix | Delete
*/
[295] Fix | Delete
jQuery(document).ready( function($) {
[296] Fix | Delete
var stamp, visibility, $submitButtons, updateVisibility, updateText,
[297] Fix | Delete
$textarea = $('#content'),
[298] Fix | Delete
$document = $(document),
[299] Fix | Delete
postId = $('#post_ID').val() || 0,
[300] Fix | Delete
$submitpost = $('#submitpost'),
[301] Fix | Delete
releaseLock = true,
[302] Fix | Delete
$postVisibilitySelect = $('#post-visibility-select'),
[303] Fix | Delete
$timestampdiv = $('#timestampdiv'),
[304] Fix | Delete
$postStatusSelect = $('#post-status-select'),
[305] Fix | Delete
isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false,
[306] Fix | Delete
copyAttachmentURLClipboard = new ClipboardJS( '.copy-attachment-url.edit-media' ),
[307] Fix | Delete
copyAttachmentURLSuccessTimeout,
[308] Fix | Delete
__ = wp.i18n.__, _x = wp.i18n._x;
[309] Fix | Delete
[310] Fix | Delete
postboxes.add_postbox_toggles(pagenow);
[311] Fix | Delete
[312] Fix | Delete
/*
[313] Fix | Delete
* Clear the window name. Otherwise if this is a former preview window where the user navigated to edit another post,
[314] Fix | Delete
* and the first post is still being edited, clicking Preview there will use this window to show the preview.
[315] Fix | Delete
*/
[316] Fix | Delete
window.name = '';
[317] Fix | Delete
[318] Fix | Delete
// Post locks: contain focus inside the dialog. If the dialog is shown, focus the first item.
[319] Fix | Delete
$('#post-lock-dialog .notification-dialog').on( 'keydown', function(e) {
[320] Fix | Delete
// Don't do anything when [Tab] is pressed.
[321] Fix | Delete
if ( e.which != 9 )
[322] Fix | Delete
return;
[323] Fix | Delete
[324] Fix | Delete
var target = $(e.target);
[325] Fix | Delete
[326] Fix | Delete
// [Shift] + [Tab] on first tab cycles back to last tab.
[327] Fix | Delete
if ( target.hasClass('wp-tab-first') && e.shiftKey ) {
[328] Fix | Delete
$(this).find('.wp-tab-last').trigger( 'focus' );
[329] Fix | Delete
e.preventDefault();
[330] Fix | Delete
// [Tab] on last tab cycles back to first tab.
[331] Fix | Delete
} else if ( target.hasClass('wp-tab-last') && ! e.shiftKey ) {
[332] Fix | Delete
$(this).find('.wp-tab-first').trigger( 'focus' );
[333] Fix | Delete
e.preventDefault();
[334] Fix | Delete
}
[335] Fix | Delete
}).filter(':visible').find('.wp-tab-first').trigger( 'focus' );
[336] Fix | Delete
[337] Fix | Delete
// Set the heartbeat interval to 15 seconds if post lock dialogs are enabled.
[338] Fix | Delete
if ( wp.heartbeat && $('#post-lock-dialog').length ) {
[339] Fix | Delete
wp.heartbeat.interval( 15 );
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
// The form is being submitted by the user.
[343] Fix | Delete
$submitButtons = $submitpost.find( ':submit, a.submitdelete, #post-preview' ).on( 'click.edit-post', function( event ) {
[344] Fix | Delete
var $button = $(this);
[345] Fix | Delete
[346] Fix | Delete
if ( $button.hasClass('disabled') ) {
[347] Fix | Delete
event.preventDefault();
[348] Fix | Delete
return;
[349] Fix | Delete
}
[350] Fix | Delete
[351] Fix | Delete
if ( $button.hasClass('submitdelete') || $button.is( '#post-preview' ) ) {
[352] Fix | Delete
return;
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
// The form submission can be blocked from JS or by using HTML 5.0 validation on some fields.
[356] Fix | Delete
// Run this only on an actual 'submit'.
[357] Fix | Delete
$('form#post').off( 'submit.edit-post' ).on( 'submit.edit-post', function( event ) {
[358] Fix | Delete
if ( event.isDefaultPrevented() ) {
[359] Fix | Delete
return;
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
// Stop auto save.
[363] Fix | Delete
if ( wp.autosave ) {
[364] Fix | Delete
wp.autosave.server.suspend();
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
if ( typeof commentReply !== 'undefined' ) {
[368] Fix | Delete
/*
[369] Fix | Delete
* Warn the user they have an unsaved comment before submitting
[370] Fix | Delete
* the post data for update.
[371] Fix | Delete
*/
[372] Fix | Delete
if ( ! commentReply.discardCommentChanges() ) {
[373] Fix | Delete
return false;
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
/*
[377] Fix | Delete
* Close the comment edit/reply form if open to stop the form
[378] Fix | Delete
* action from interfering with the post's form action.
[379] Fix | Delete
*/
[380] Fix | Delete
commentReply.close();
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
releaseLock = false;
[384] Fix | Delete
$(window).off( 'beforeunload.edit-post' );
[385] Fix | Delete
[386] Fix | Delete
$submitButtons.addClass( 'disabled' );
[387] Fix | Delete
[388] Fix | Delete
if ( $button.attr('id') === 'publish' ) {
[389] Fix | Delete
$submitpost.find( '#major-publishing-actions .spinner' ).addClass( 'is-active' );
[390] Fix | Delete
} else {
[391] Fix | Delete
$submitpost.find( '#minor-publishing .spinner' ).addClass( 'is-active' );
[392] Fix | Delete
}
[393] Fix | Delete
});
[394] Fix | Delete
});
[395] Fix | Delete
[396] Fix | Delete
// Submit the form saving a draft or an autosave, and show a preview in a new tab.
[397] Fix | Delete
$('#post-preview').on( 'click.post-preview', function( event ) {
[398] Fix | Delete
var $this = $(this),
[399] Fix | Delete
$form = $('form#post'),
[400] Fix | Delete
$previewField = $('input#wp-preview'),
[401] Fix | Delete
target = $this.attr('target') || 'wp-preview',
[402] Fix | Delete
ua = navigator.userAgent.toLowerCase();
[403] Fix | Delete
[404] Fix | Delete
event.preventDefault();
[405] Fix | Delete
[406] Fix | Delete
if ( $this.hasClass('disabled') ) {
[407] Fix | Delete
return;
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
if ( wp.autosave ) {
[411] Fix | Delete
wp.autosave.server.tempBlockSave();
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
$previewField.val('dopreview');
[415] Fix | Delete
$form.attr( 'target', target ).trigger( 'submit' ).attr( 'target', '' );
[416] Fix | Delete
[417] Fix | Delete
// Workaround for WebKit bug preventing a form submitting twice to the same action.
[418] Fix | Delete
// https://bugs.webkit.org/show_bug.cgi?id=28633
[419] Fix | Delete
if ( ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1 ) {
[420] Fix | Delete
$form.attr( 'action', function( index, value ) {
[421] Fix | Delete
return value + '?t=' + ( new Date() ).getTime();
[422] Fix | Delete
});
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
$previewField.val('');
[426] Fix | Delete
});
[427] Fix | Delete
[428] Fix | Delete
// This code is meant to allow tabbing from Title to Post content.
[429] Fix | Delete
$('#title').on( 'keydown.editor-focus', function( event ) {
[430] Fix | Delete
var editor;
[431] Fix | Delete
[432] Fix | Delete
if ( event.keyCode === 9 && ! event.ctrlKey && ! event.altKey && ! event.shiftKey ) {
[433] Fix | Delete
editor = typeof tinymce != 'undefined' && tinymce.get('content');
[434] Fix | Delete
[435] Fix | Delete
if ( editor && ! editor.isHidden() ) {
[436] Fix | Delete
editor.focus();
[437] Fix | Delete
} else if ( $textarea.length ) {
[438] Fix | Delete
$textarea.trigger( 'focus' );
[439] Fix | Delete
} else {
[440] Fix | Delete
return;
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
event.preventDefault();
[444] Fix | Delete
}
[445] Fix | Delete
});
[446] Fix | Delete
[447] Fix | Delete
// Auto save new posts after a title is typed.
[448] Fix | Delete
if ( $( '#auto_draft' ).val() ) {
[449] Fix | Delete
$( '#title' ).on( 'blur', function() {
[450] Fix | Delete
var cancel;
[451] Fix | Delete
[452] Fix | Delete
if ( ! this.value || $('#edit-slug-box > *').length ) {
[453] Fix | Delete
return;
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
// Cancel the auto save when the blur was triggered by the user submitting the form.
[457] Fix | Delete
$('form#post').one( 'submit', function() {
[458] Fix | Delete
cancel = true;
[459] Fix | Delete
});
[460] Fix | Delete
[461] Fix | Delete
window.setTimeout( function() {
[462] Fix | Delete
if ( ! cancel && wp.autosave ) {
[463] Fix | Delete
wp.autosave.server.triggerSave();
[464] Fix | Delete
}
[465] Fix | Delete
}, 200 );
[466] Fix | Delete
});
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
$document.on( 'autosave-disable-buttons.edit-post', function() {
[470] Fix | Delete
$submitButtons.addClass( 'disabled' );
[471] Fix | Delete
}).on( 'autosave-enable-buttons.edit-post', function() {
[472] Fix | Delete
if ( ! wp.heartbeat || ! wp.heartbeat.hasConnectionError() ) {
[473] Fix | Delete
$submitButtons.removeClass( 'disabled' );
[474] Fix | Delete
}
[475] Fix | Delete
}).on( 'before-autosave.edit-post', function() {
[476] Fix | Delete
$( '.autosave-message' ).text( __( 'Saving Draft…' ) );
[477] Fix | Delete
}).on( 'after-autosave.edit-post', function( event, data ) {
[478] Fix | Delete
$( '.autosave-message' ).text( data.message );
[479] Fix | Delete
[480] Fix | Delete
if ( $( document.body ).hasClass( 'post-new-php' ) ) {
[481] Fix | Delete
$( '.submitbox .submitdelete' ).show();
[482] Fix | Delete
}
[483] Fix | Delete
});
[484] Fix | Delete
[485] Fix | Delete
/*
[486] Fix | Delete
* When the user is trying to load another page, or reloads current page
[487] Fix | Delete
* show a confirmation dialog when there are unsaved changes.
[488] Fix | Delete
*/
[489] Fix | Delete
$( window ).on( 'beforeunload.edit-post', function( event ) {
[490] Fix | Delete
var editor = window.tinymce && window.tinymce.get( 'content' );
[491] Fix | Delete
var changed = false;
[492] Fix | Delete
[493] Fix | Delete
if ( wp.autosave ) {
[494] Fix | Delete
changed = wp.autosave.server.postChanged();
[495] Fix | Delete
} else if ( editor ) {
[496] Fix | Delete
changed = ( ! editor.isHidden() && editor.isDirty() );
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function