wp/wp-admin/js/post.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    66 
    66 
    67 					if ( 'object' == typeof r && r.responses[0] ) {
    67 					if ( 'object' == typeof r && r.responses[0] ) {
    68 						$('#the-comment-list').append( r.responses[0].data );
    68 						$('#the-comment-list').append( r.responses[0].data );
    69 
    69 
    70 						theList = theExtraList = null;
    70 						theList = theExtraList = null;
    71 						$( 'a[className*=\':\']' ).unbind();
    71 						$( 'a[className*=\':\']' ).off();
    72 
    72 
    73 						// If the offset is over the total number of comments we cannot fetch any more, so hide the button.
    73 						// If the offset is over the total number of comments we cannot fetch any more, so hide the button.
    74 						if ( commentsBox.st > commentsBox.total )
    74 						if ( commentsBox.st > commentsBox.total )
    75 							$('#show-comments').hide();
    75 							$('#show-comments').hide();
    76 						else
    76 						else
   211 						} );
   211 						} );
   212 						wrap.find('div.post-locked-avatar').empty().append( avatar );
   212 						wrap.find('div.post-locked-avatar').empty().append( avatar );
   213 					}
   213 					}
   214 
   214 
   215 					wrap.show().find('.currently-editing').text( received.lock_error.text );
   215 					wrap.show().find('.currently-editing').text( received.lock_error.text );
   216 					wrap.find('.wp-tab-first').focus();
   216 					wrap.find('.wp-tab-first').trigger( 'focus' );
   217 				}
   217 				}
   218 			} else if ( received.new_lock ) {
   218 			} else if ( received.new_lock ) {
   219 				$('#active_post_lock').val( received.new_lock );
   219 				$('#active_post_lock').val( received.new_lock );
   220 			}
   220 			}
   221 		}
   221 		}
   258 		check = false;
   258 		check = false;
   259 		window.clearTimeout( timeout );
   259 		window.clearTimeout( timeout );
   260 		timeout = window.setTimeout( function(){ check = true; }, 300000 );
   260 		timeout = window.setTimeout( function(){ check = true; }, 300000 );
   261 	}
   261 	}
   262 
   262 
   263 	$(document).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) {
   263 	$( function() {
       
   264 		schedule();
       
   265 	}).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) {
   264 		var post_id,
   266 		var post_id,
   265 			$authCheck = $('#wp-auth-check-wrap');
   267 			$authCheck = $('#wp-auth-check-wrap');
   266 
   268 
   267 		if ( check || ( $authCheck.length && ! $authCheck.hasClass( 'hidden' ) ) ) {
   269 		if ( check || ( $authCheck.length && ! $authCheck.hasClass( 'hidden' ) ) ) {
   268 			if ( ( post_id = $('#post_ID').val() ) && $('#_wpnonce').val() ) {
   270 			if ( ( post_id = $('#post_ID').val() ) && $('#_wpnonce').val() ) {
   284 			}
   286 			}
   285 
   287 
   286 			if ( nonces.heartbeatNonce )
   288 			if ( nonces.heartbeatNonce )
   287 				window.heartbeatSettings.nonce = nonces.heartbeatNonce;
   289 				window.heartbeatSettings.nonce = nonces.heartbeatNonce;
   288 		}
   290 		}
   289 	}).ready( function() {
       
   290 		schedule();
       
   291 	});
   291 	});
   292 }(jQuery));
   292 }(jQuery));
   293 
   293 
   294 /**
   294 /**
   295  * All post and postbox controls and functionality.
   295  * All post and postbox controls and functionality.
   296  */
   296  */
   297 jQuery(document).ready( function($) {
   297 jQuery( function($) {
   298 	var stamp, visibility, $submitButtons, updateVisibility, updateText,
   298 	var stamp, visibility, $submitButtons, updateVisibility, updateText,
   299 		$textarea = $('#content'),
   299 		$textarea = $('#content'),
   300 		$document = $(document),
   300 		$document = $(document),
   301 		postId = $('#post_ID').val() || 0,
   301 		postId = $('#post_ID').val() || 0,
   302 		$submitpost = $('#submitpost'),
   302 		$submitpost = $('#submitpost'),
   325 
   325 
   326 		var target = $(e.target);
   326 		var target = $(e.target);
   327 
   327 
   328 		// [Shift] + [Tab] on first tab cycles back to last tab.
   328 		// [Shift] + [Tab] on first tab cycles back to last tab.
   329 		if ( target.hasClass('wp-tab-first') && e.shiftKey ) {
   329 		if ( target.hasClass('wp-tab-first') && e.shiftKey ) {
   330 			$(this).find('.wp-tab-last').focus();
   330 			$(this).find('.wp-tab-last').trigger( 'focus' );
   331 			e.preventDefault();
   331 			e.preventDefault();
   332 		// [Tab] on last tab cycles back to first tab.
   332 		// [Tab] on last tab cycles back to first tab.
   333 		} else if ( target.hasClass('wp-tab-last') && ! e.shiftKey ) {
   333 		} else if ( target.hasClass('wp-tab-last') && ! e.shiftKey ) {
   334 			$(this).find('.wp-tab-first').focus();
   334 			$(this).find('.wp-tab-first').trigger( 'focus' );
   335 			e.preventDefault();
   335 			e.preventDefault();
   336 		}
   336 		}
   337 	}).filter(':visible').find('.wp-tab-first').focus();
   337 	}).filter(':visible').find('.wp-tab-first').trigger( 'focus' );
   338 
   338 
   339 	// Set the heartbeat interval to 15 seconds if post lock dialogs are enabled.
   339 	// Set the heartbeat interval to 15 seconds if post lock dialogs are enabled.
   340 	if ( wp.heartbeat && $('#post-lock-dialog').length ) {
   340 	if ( wp.heartbeat && $('#post-lock-dialog').length ) {
   341 		wp.heartbeat.interval( 15 );
   341 		wp.heartbeat.interval( 15 );
   342 	}
   342 	}
   412 		if ( wp.autosave ) {
   412 		if ( wp.autosave ) {
   413 			wp.autosave.server.tempBlockSave();
   413 			wp.autosave.server.tempBlockSave();
   414 		}
   414 		}
   415 
   415 
   416 		$previewField.val('dopreview');
   416 		$previewField.val('dopreview');
   417 		$form.attr( 'target', target ).submit().attr( 'target', '' );
   417 		$form.attr( 'target', target ).trigger( 'submit' ).attr( 'target', '' );
   418 
   418 
   419 		// Workaround for WebKit bug preventing a form submitting twice to the same action.
   419 		// Workaround for WebKit bug preventing a form submitting twice to the same action.
   420 		// https://bugs.webkit.org/show_bug.cgi?id=28633
   420 		// https://bugs.webkit.org/show_bug.cgi?id=28633
   421 		if ( ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1 ) {
   421 		if ( ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1 ) {
   422 			$form.attr( 'action', function( index, value ) {
   422 			$form.attr( 'action', function( index, value ) {
   435 			editor = typeof tinymce != 'undefined' && tinymce.get('content');
   435 			editor = typeof tinymce != 'undefined' && tinymce.get('content');
   436 
   436 
   437 			if ( editor && ! editor.isHidden() ) {
   437 			if ( editor && ! editor.isHidden() ) {
   438 				editor.focus();
   438 				editor.focus();
   439 			} else if ( $textarea.length ) {
   439 			} else if ( $textarea.length ) {
   440 				$textarea.focus();
   440 				$textarea.trigger( 'focus' );
   441 			} else {
   441 			} else {
   442 				return;
   442 				return;
   443 			}
   443 			}
   444 
   444 
   445 			event.preventDefault();
   445 			event.preventDefault();
   446 		}
   446 		}
   447 	});
   447 	});
   448 
   448 
   449 	// Auto save new posts after a title is typed.
   449 	// Auto save new posts after a title is typed.
   450 	if ( $( '#auto_draft' ).val() ) {
   450 	if ( $( '#auto_draft' ).val() ) {
   451 		$( '#title' ).blur( function() {
   451 		$( '#title' ).on( 'blur', function() {
   452 			var cancel;
   452 			var cancel;
   453 
   453 
   454 			if ( ! this.value || $('#edit-slug-box > *').length ) {
   454 			if ( ! this.value || $('#edit-slug-box > *').length ) {
   455 				return;
   455 				return;
   456 			}
   456 			}
   486 
   486 
   487 	/*
   487 	/*
   488 	 * When the user is trying to load another page, or reloads current page
   488 	 * When the user is trying to load another page, or reloads current page
   489 	 * show a confirmation dialog when there are unsaved changes.
   489 	 * show a confirmation dialog when there are unsaved changes.
   490 	 */
   490 	 */
   491 	$(window).on( 'beforeunload.edit-post', function() {
   491 	$( window ).on( 'beforeunload.edit-post', function( event ) {
   492 		var editor = typeof tinymce !== 'undefined' && tinymce.get('content');
   492 		var editor  = window.tinymce && window.tinymce.get( 'content' );
   493 
   493 		var changed = false;
   494 		if ( ( editor && ! editor.isHidden() && editor.isDirty() ) ||
   494 
   495 			( wp.autosave && wp.autosave.server.postChanged() ) ) {
   495 		if ( wp.autosave ) {
   496 
   496 			changed = wp.autosave.server.postChanged();
       
   497 		} else if ( editor ) {
       
   498 			changed = ( ! editor.isHidden() && editor.isDirty() );
       
   499 		}
       
   500 
       
   501 		if ( changed ) {
       
   502 			event.preventDefault();
       
   503 			// The return string is needed for browser compat.
       
   504 			// See https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event.
   497 			return __( 'The changes you made will be lost if you navigate away from this page.' );
   505 			return __( 'The changes you made will be lost if you navigate away from this page.' );
   498 		}
   506 		}
   499 	}).on( 'unload.edit-post', function( event ) {
   507 	}).on( 'unload.edit-post', function( event ) {
   500 		if ( ! releaseLock ) {
   508 		if ( ! releaseLock ) {
   501 			return;
   509 			return;
   568 		if ( taxonomy == 'category' ) {
   576 		if ( taxonomy == 'category' ) {
   569 			settingName = 'cats';
   577 			settingName = 'cats';
   570 		}
   578 		}
   571 
   579 
   572 		// @todo Move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js.
   580 		// @todo Move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js.
   573 		$('a', '#' + taxonomy + '-tabs').click( function( e ) {
   581 		$('a', '#' + taxonomy + '-tabs').on( 'click', function( e ) {
   574 			e.preventDefault();
   582 			e.preventDefault();
   575 			var t = $(this).attr('href');
   583 			var t = $(this).attr('href');
   576 			$(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
   584 			$(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
   577 			$('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide();
   585 			$('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide();
   578 			$(t).show();
   586 			$(t).show();
   582 				setUserSetting( settingName, 'pop' );
   590 				setUserSetting( settingName, 'pop' );
   583 			}
   591 			}
   584 		});
   592 		});
   585 
   593 
   586 		if ( getUserSetting( settingName ) )
   594 		if ( getUserSetting( settingName ) )
   587 			$('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').click();
   595 			$('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').trigger( 'click' );
   588 
   596 
   589 		// Add category button controls.
   597 		// Add category button controls.
   590 		$('#new' + taxonomy).one( 'focus', function() {
   598 		$('#new' + taxonomy).one( 'focus', function() {
   591 			$( this ).val( '' ).removeClass( 'form-input-tip' );
   599 			$( this ).val( '' ).removeClass( 'form-input-tip' );
   592 		});
   600 		});
   593 
   601 
   594 		// On [Enter] submit the taxonomy.
   602 		// On [Enter] submit the taxonomy.
   595 		$('#new' + taxonomy).keypress( function(event){
   603 		$('#new' + taxonomy).on( 'keypress', function(event){
   596 			if( 13 === event.keyCode ) {
   604 			if( 13 === event.keyCode ) {
   597 				event.preventDefault();
   605 				event.preventDefault();
   598 				$('#' + taxonomy + '-add-submit').click();
   606 				$('#' + taxonomy + '-add-submit').trigger( 'click' );
   599 			}
   607 			}
   600 		});
   608 		});
   601 
   609 
   602 		// After submitting a new taxonomy, re-focus the input field.
   610 		// After submitting a new taxonomy, re-focus the input field.
   603 		$('#' + taxonomy + '-add-submit').click( function() {
   611 		$('#' + taxonomy + '-add-submit').on( 'click', function() {
   604 			$('#new' + taxonomy).focus();
   612 			$('#new' + taxonomy).trigger( 'focus' );
   605 		});
   613 		});
   606 
   614 
   607 		/**
   615 		/**
   608 		 * Before adding a new taxonomy, disable submit button.
   616 		 * Before adding a new taxonomy, disable submit button.
   609 		 *
   617 		 *
   648 			addBefore: catAddBefore,
   656 			addBefore: catAddBefore,
   649 			addAfter: catAddAfter
   657 			addAfter: catAddAfter
   650 		});
   658 		});
   651 
   659 
   652 		// Add new taxonomy button toggles input form visibility.
   660 		// Add new taxonomy button toggles input form visibility.
   653 		$('#' + taxonomy + '-add-toggle').click( function( e ) {
   661 		$('#' + taxonomy + '-add-toggle').on( 'click', function( e ) {
   654 			e.preventDefault();
   662 			e.preventDefault();
   655 			$('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' );
   663 			$('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' );
   656 			$('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').click();
   664 			$('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').trigger( 'click' );
   657 			$('#new'+taxonomy).focus();
   665 			$('#new'+taxonomy).trigger( 'focus' );
   658 		});
   666 		});
   659 
   667 
   660 		// Sync checked items between "All {taxonomy}" and "Most used" lists.
   668 		// Sync checked items between "All {taxonomy}" and "Most used" lists.
   661 		$('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on( 'click', 'li.popular-category > label input[type="checkbox"]', function() {
   669 		$('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on( 'click', 'li.popular-category > label input[type="checkbox"]', function() {
   662 			var t = $(this), c = t.is(':checked'), id = t.val();
   670 			var t = $(this), c = t.is(':checked'), id = t.val();
   824 			}
   832 			}
   825 			return true;
   833 			return true;
   826 		};
   834 		};
   827 
   835 
   828 		// Show the visibility options and hide the toggle button when opened.
   836 		// Show the visibility options and hide the toggle button when opened.
   829 		$( '#visibility .edit-visibility').click( function( e ) {
   837 		$( '#visibility .edit-visibility').on( 'click', function( e ) {
   830 			e.preventDefault();
   838 			e.preventDefault();
   831 			if ( $postVisibilitySelect.is(':hidden') ) {
   839 			if ( $postVisibilitySelect.is(':hidden') ) {
   832 				updateVisibility();
   840 				updateVisibility();
   833 				$postVisibilitySelect.slideDown( 'fast', function() {
   841 				$postVisibilitySelect.slideDown( 'fast', function() {
   834 					$postVisibilitySelect.find( 'input[type="radio"]' ).first().focus();
   842 					$postVisibilitySelect.find( 'input[type="radio"]' ).first().trigger( 'focus' );
   835 				} );
   843 				} );
   836 				$(this).hide();
   844 				$(this).hide();
   837 			}
   845 			}
   838 		});
   846 		});
   839 
   847 
   840 		// Cancel visibility selection area and hide it from view.
   848 		// Cancel visibility selection area and hide it from view.
   841 		$postVisibilitySelect.find('.cancel-post-visibility').click( function( event ) {
   849 		$postVisibilitySelect.find('.cancel-post-visibility').on( 'click', function( event ) {
   842 			$postVisibilitySelect.slideUp('fast');
   850 			$postVisibilitySelect.slideUp('fast');
   843 			$('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true);
   851 			$('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true);
   844 			$('#post_password').val($('#hidden-post-password').val());
   852 			$('#post_password').val($('#hidden-post-password').val());
   845 			$('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked'));
   853 			$('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked'));
   846 			$('#post-visibility-display').html(visibility);
   854 			$('#post-visibility-display').html(visibility);
   847 			$('#visibility .edit-visibility').show().focus();
   855 			$('#visibility .edit-visibility').show().trigger( 'focus' );
   848 			updateText();
   856 			updateText();
   849 			event.preventDefault();
   857 			event.preventDefault();
   850 		});
   858 		});
   851 
   859 
   852 		// Set the selected visibility as current.
   860 		// Set the selected visibility as current.
   853 		$postVisibilitySelect.find('.save-post-visibility').click( function( event ) { // Crazyhorse - multiple OK cancels.
   861 		$postVisibilitySelect.find('.save-post-visibility').on( 'click', function( event ) { // Crazyhorse - multiple OK cancels.
   854 			var visibilityLabel = '', selectedVisibility = $postVisibilitySelect.find('input:radio:checked').val();
   862 			var visibilityLabel = '', selectedVisibility = $postVisibilitySelect.find('input:radio:checked').val();
   855 
   863 
   856 			$postVisibilitySelect.slideUp('fast');
   864 			$postVisibilitySelect.slideUp('fast');
   857 			$('#visibility .edit-visibility').show().focus();
   865 			$('#visibility .edit-visibility').show().trigger( 'focus' );
   858 			updateText();
   866 			updateText();
   859 
   867 
   860 			if ( 'public' !== selectedVisibility ) {
   868 			if ( 'public' !== selectedVisibility ) {
   861 				$('#sticky').prop('checked', false);
   869 				$('#sticky').prop('checked', false);
   862 			}
   870 			}
   876 			$('#post-visibility-display').text( visibilityLabel );
   884 			$('#post-visibility-display').text( visibilityLabel );
   877 			event.preventDefault();
   885 			event.preventDefault();
   878 		});
   886 		});
   879 
   887 
   880 		// When the selection changes, update labels.
   888 		// When the selection changes, update labels.
   881 		$postVisibilitySelect.find('input:radio').change( function() {
   889 		$postVisibilitySelect.find('input:radio').on( 'change', function() {
   882 			updateVisibility();
   890 			updateVisibility();
   883 		});
   891 		});
   884 
   892 
   885 		// Edit publish time click.
   893 		// Edit publish time click.
   886 		$timestampdiv.siblings('a.edit-timestamp').click( function( event ) {
   894 		$timestampdiv.siblings('a.edit-timestamp').on( 'click', function( event ) {
   887 			if ( $timestampdiv.is( ':hidden' ) ) {
   895 			if ( $timestampdiv.is( ':hidden' ) ) {
   888 				$timestampdiv.slideDown( 'fast', function() {
   896 				$timestampdiv.slideDown( 'fast', function() {
   889 					$( 'input, select', $timestampdiv.find( '.timestamp-wrap' ) ).first().focus();
   897 					$( 'input, select', $timestampdiv.find( '.timestamp-wrap' ) ).first().trigger( 'focus' );
   890 				} );
   898 				} );
   891 				$(this).hide();
   899 				$(this).hide();
   892 			}
   900 			}
   893 			event.preventDefault();
   901 			event.preventDefault();
   894 		});
   902 		});
   895 
   903 
   896 		// Cancel editing the publish time and hide the settings.
   904 		// Cancel editing the publish time and hide the settings.
   897 		$timestampdiv.find('.cancel-timestamp').click( function( event ) {
   905 		$timestampdiv.find('.cancel-timestamp').on( 'click', function( event ) {
   898 			$timestampdiv.slideUp('fast').siblings('a.edit-timestamp').show().focus();
   906 			$timestampdiv.slideUp('fast').siblings('a.edit-timestamp').show().trigger( 'focus' );
   899 			$('#mm').val($('#hidden_mm').val());
   907 			$('#mm').val($('#hidden_mm').val());
   900 			$('#jj').val($('#hidden_jj').val());
   908 			$('#jj').val($('#hidden_jj').val());
   901 			$('#aa').val($('#hidden_aa').val());
   909 			$('#aa').val($('#hidden_aa').val());
   902 			$('#hh').val($('#hidden_hh').val());
   910 			$('#hh').val($('#hidden_hh').val());
   903 			$('#mn').val($('#hidden_mn').val());
   911 			$('#mn').val($('#hidden_mn').val());
   904 			updateText();
   912 			updateText();
   905 			event.preventDefault();
   913 			event.preventDefault();
   906 		});
   914 		});
   907 
   915 
   908 		// Save the changed timestamp.
   916 		// Save the changed timestamp.
   909 		$timestampdiv.find('.save-timestamp').click( function( event ) { // Crazyhorse - multiple OK cancels.
   917 		$timestampdiv.find('.save-timestamp').on( 'click', function( event ) { // Crazyhorse - multiple OK cancels.
   910 			if ( updateText() ) {
   918 			if ( updateText() ) {
   911 				$timestampdiv.slideUp('fast');
   919 				$timestampdiv.slideUp('fast');
   912 				$timestampdiv.siblings('a.edit-timestamp').show().focus();
   920 				$timestampdiv.siblings('a.edit-timestamp').show().trigger( 'focus' );
   913 			}
   921 			}
   914 			event.preventDefault();
   922 			event.preventDefault();
   915 		});
   923 		});
   916 
   924 
   917 		// Cancel submit when an invalid timestamp has been selected.
   925 		// Cancel submit when an invalid timestamp has been selected.
   927 				$( '#publishing-action .spinner' ).removeClass( 'is-active' );
   935 				$( '#publishing-action .spinner' ).removeClass( 'is-active' );
   928 			}
   936 			}
   929 		});
   937 		});
   930 
   938 
   931 		// Post Status edit click.
   939 		// Post Status edit click.
   932 		$postStatusSelect.siblings('a.edit-post-status').click( function( event ) {
   940 		$postStatusSelect.siblings('a.edit-post-status').on( 'click', function( event ) {
   933 			if ( $postStatusSelect.is( ':hidden' ) ) {
   941 			if ( $postStatusSelect.is( ':hidden' ) ) {
   934 				$postStatusSelect.slideDown( 'fast', function() {
   942 				$postStatusSelect.slideDown( 'fast', function() {
   935 					$postStatusSelect.find('select').focus();
   943 					$postStatusSelect.find('select').trigger( 'focus' );
   936 				} );
   944 				} );
   937 				$(this).hide();
   945 				$(this).hide();
   938 			}
   946 			}
   939 			event.preventDefault();
   947 			event.preventDefault();
   940 		});
   948 		});
   941 
   949 
   942 		// Save the Post Status changes and hide the options.
   950 		// Save the Post Status changes and hide the options.
   943 		$postStatusSelect.find('.save-post-status').click( function( event ) {
   951 		$postStatusSelect.find('.save-post-status').on( 'click', function( event ) {
   944 			$postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().focus();
   952 			$postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().trigger( 'focus' );
   945 			updateText();
   953 			updateText();
   946 			event.preventDefault();
   954 			event.preventDefault();
   947 		});
   955 		});
   948 
   956 
   949 		// Cancel Post Status editing and hide the options.
   957 		// Cancel Post Status editing and hide the options.
   950 		$postStatusSelect.find('.cancel-post-status').click( function( event ) {
   958 		$postStatusSelect.find('.cancel-post-status').on( 'click', function( event ) {
   951 			$postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().focus();
   959 			$postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().trigger( 'focus' );
   952 			$('#post_status').val( $('#hidden_post_status').val() );
   960 			$('#post_status').val( $('#hidden_post_status').val() );
   953 			updateText();
   961 			updateText();
   954 			event.preventDefault();
   962 			event.preventDefault();
   955 		});
   963 		});
   956 	}
   964 	}
   987 		revert_e = $el.html();
   995 		revert_e = $el.html();
   988 
   996 
   989 		buttons.html( '<button type="button" class="save button button-small">' + __( 'OK' ) + '</button> <button type="button" class="cancel button-link">' + __( 'Cancel' ) + '</button>' );
   997 		buttons.html( '<button type="button" class="save button button-small">' + __( 'OK' ) + '</button> <button type="button" class="cancel button-link">' + __( 'Cancel' ) + '</button>' );
   990 
   998 
   991 		// Save permalink changes.
   999 		// Save permalink changes.
   992 		buttons.children( '.save' ).click( function() {
  1000 		buttons.children( '.save' ).on( 'click', function() {
   993 			var new_slug = $el.children( 'input' ).val();
  1001 			var new_slug = $el.children( 'input' ).val();
   994 
  1002 
   995 			if ( new_slug == $('#editable-post-name-full').text() ) {
  1003 			if ( new_slug == $('#editable-post-name-full').text() ) {
   996 				buttons.children('.cancel').click();
  1004 				buttons.children('.cancel').trigger( 'click' );
   997 				return;
  1005 				return;
   998 			}
  1006 			}
   999 
  1007 
  1000 			$.post(
  1008 			$.post(
  1001 				ajaxurl,
  1009 				ajaxurl,
  1016 					}
  1024 					}
  1017 
  1025 
  1018 					buttons.html(buttonsOrig);
  1026 					buttons.html(buttonsOrig);
  1019 					permalink.html(permalinkOrig);
  1027 					permalink.html(permalinkOrig);
  1020 					real_slug.val(new_slug);
  1028 					real_slug.val(new_slug);
  1021 					$( '.edit-slug' ).focus();
  1029 					$( '.edit-slug' ).trigger( 'focus' );
  1022 					wp.a11y.speak( __( 'Permalink saved' ) );
  1030 					wp.a11y.speak( __( 'Permalink saved' ) );
  1023 				}
  1031 				}
  1024 			);
  1032 			);
  1025 		});
  1033 		});
  1026 
  1034 
  1027 		// Cancel editing of permalink.
  1035 		// Cancel editing of permalink.
  1028 		buttons.children( '.cancel' ).click( function() {
  1036 		buttons.children( '.cancel' ).on( 'click', function() {
  1029 			$('#view-post-btn').show();
  1037 			$('#view-post-btn').show();
  1030 			$el.html(revert_e);
  1038 			$el.html(revert_e);
  1031 			buttons.html(buttonsOrig);
  1039 			buttons.html(buttonsOrig);
  1032 			permalink.html(permalinkOrig);
  1040 			permalink.html(permalinkOrig);
  1033 			real_slug.val(revert_slug);
  1041 			real_slug.val(revert_slug);
  1034 			$( '.edit-slug' ).focus();
  1042 			$( '.edit-slug' ).trigger( 'focus' );
  1035 		});
  1043 		});
  1036 
  1044 
  1037 		// If more than 1/4th of 'full' is '%', make it empty.
  1045 		// If more than 1/4th of 'full' is '%', make it empty.
  1038 		for ( i = 0; i < full.length; ++i ) {
  1046 		for ( i = 0; i < full.length; ++i ) {
  1039 			if ( '%' == full.charAt(i) )
  1047 			if ( '%' == full.charAt(i) )
  1040 				c++;
  1048 				c++;
  1041 		}
  1049 		}
  1042 		slug_value = ( c > full.length / 4 ) ? '' : full;
  1050 		slug_value = ( c > full.length / 4 ) ? '' : full;
  1043 
  1051 
  1044 		$el.html( '<input type="text" id="new-post-slug" value="' + slug_value + '" autocomplete="off" />' ).children( 'input' ).keydown( function( e ) {
  1052 		$el.html( '<input type="text" id="new-post-slug" value="' + slug_value + '" autocomplete="off" />' ).children( 'input' ).on( 'keydown', function( e ) {
  1045 			var key = e.which;
  1053 			var key = e.which;
  1046 			// On [Enter], just save the new slug, don't save the post.
  1054 			// On [Enter], just save the new slug, don't save the post.
  1047 			if ( 13 === key ) {
  1055 			if ( 13 === key ) {
  1048 				e.preventDefault();
  1056 				e.preventDefault();
  1049 				buttons.children( '.save' ).click();
  1057 				buttons.children( '.save' ).trigger( 'click' );
  1050 			}
  1058 			}
  1051 			// On [Esc] cancel the editing.
  1059 			// On [Esc] cancel the editing.
  1052 			if ( 27 === key ) {
  1060 			if ( 27 === key ) {
  1053 				buttons.children( '.cancel' ).click();
  1061 				buttons.children( '.cancel' ).trigger( 'click' );
  1054 			}
  1062 			}
  1055 		} ).keyup( function() {
  1063 		} ).on( 'keyup', function() {
  1056 			real_slug.val( this.value );
  1064 			real_slug.val( this.value );
  1057 		}).focus();
  1065 		}).trigger( 'focus' );
  1058 	}
  1066 	}
  1059 
  1067 
  1060 	$( '#titlediv' ).on( 'click', '.edit-slug', function() {
  1068 	$( '#titlediv' ).on( 'click', '.edit-slug', function() {
  1061 		editPermalink();
  1069 		editPermalink();
  1062 	});
  1070 	});
  1144 					toolbarHeight = 30;
  1152 					toolbarHeight = 30;
  1145 				}
  1153 				}
  1146 
  1154 
  1147 				height = parseInt( $('#content_ifr').css('height'), 10 ) + toolbarHeight - 28;
  1155 				height = parseInt( $('#content_ifr').css('height'), 10 ) + toolbarHeight - 28;
  1148 			} else {
  1156 			} else {
  1149 				$textarea.focus();
  1157 				$textarea.trigger( 'focus' );
  1150 				height = parseInt( $textarea.css('height'), 10 );
  1158 				height = parseInt( $textarea.css('height'), 10 );
  1151 			}
  1159 			}
  1152 
  1160 
  1153 			$document.off( '.wp-editor-resize' );
  1161 			$document.off( '.wp-editor-resize' );
  1154 
  1162 
  1167 				mce = true;
  1175 				mce = true;
  1168 				offset = $('#content_ifr').height() - event.pageY;
  1176 				offset = $('#content_ifr').height() - event.pageY;
  1169 			} else {
  1177 			} else {
  1170 				mce = false;
  1178 				mce = false;
  1171 				offset = $textarea.height() - event.pageY;
  1179 				offset = $textarea.height() - event.pageY;
  1172 				$textarea.blur();
  1180 				$textarea.trigger( 'blur' );
  1173 			}
  1181 			}
  1174 
  1182 
  1175 			$document.on( 'mousemove.wp-editor-resize', dragging )
  1183 			$document.on( 'mousemove.wp-editor-resize', dragging )
  1176 				.on( 'mouseup.wp-editor-resize mouseleave.wp-editor-resize', endDrag );
  1184 				.on( 'mouseup.wp-editor-resize mouseleave.wp-editor-resize', endDrag );
  1177 
  1185 
  1251 			successElement = $( '.success', triggerElement.closest( '.copy-to-clipboard-container' ) );
  1259 			successElement = $( '.success', triggerElement.closest( '.copy-to-clipboard-container' ) );
  1252 
  1260 
  1253 		// Clear the selection and move focus back to the trigger.
  1261 		// Clear the selection and move focus back to the trigger.
  1254 		event.clearSelection();
  1262 		event.clearSelection();
  1255 		// Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680
  1263 		// Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680
  1256 		triggerElement.focus();
  1264 		triggerElement.trigger( 'focus' );
  1257 
  1265 
  1258 		// Show success visual feedback.
  1266 		// Show success visual feedback.
  1259 		clearTimeout( copyAttachmentURLSuccessTimeout );
  1267 		clearTimeout( copyAttachmentURLSuccessTimeout );
  1260 		successElement.removeClass( 'hidden' );
  1268 		successElement.removeClass( 'hidden' );
  1261 
  1269