/* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting */
-/* global theList:true, theExtraList:true, getUserSetting, setUserSetting */
+/* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply */
var commentsBox, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint, makeSlugeditClickable, editPermalink;
// Back-compat: prevent fatal errors
}
$(document).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) {
- var nonce, post_id;
+ var post_id,
+ $authCheck = $('#wp-auth-check-wrap');
- if ( check ) {
- if ( ( post_id = $('#post_ID').val() ) && ( nonce = $('#_wpnonce').val() ) ) {
+ if ( check || ( $authCheck.length && ! $authCheck.hasClass( 'hidden' ) ) ) {
+ if ( ( post_id = $('#post_ID').val() ) && $('#_wpnonce').val() ) {
data['wp-refresh-post-nonces'] = {
- post_id: post_id,
- post_nonce: nonce
+ post_id: post_id
};
}
}
jQuery(document).ready( function($) {
var stamp, visibility, $submitButtons, updateVisibility, updateText,
sticky = '',
- last = 0,
- co = $('#content'),
+ $textarea = $('#content'),
$document = $(document),
$editSlugWrap = $('#edit-slug-box'),
postId = $('#post_ID').val() || 0,
releaseLock = true,
$postVisibilitySelect = $('#post-visibility-select'),
$timestampdiv = $('#timestampdiv'),
- $postStatusSelect = $('#post-status-select');
+ $postStatusSelect = $('#post-status-select'),
+ isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false;
postboxes.add_postbox_toggles(pagenow);
wp.autosave.server.suspend();
}
+ if ( typeof commentReply !== 'undefined' ) {
+ /*
+ * Close the comment edit/reply form if open to stop the form
+ * action from interfering with the post's form action.
+ */
+ commentReply.close();
+ }
+
releaseLock = false;
$(window).off( 'beforeunload.edit-post' );
// This code is meant to allow tabbing from Title to Post content.
$('#title').on( 'keydown.editor-focus', function( event ) {
- var editor, $textarea;
+ var editor;
if ( event.keyCode === 9 && ! event.ctrlKey && ! event.altKey && ! event.shiftKey ) {
editor = typeof tinymce != 'undefined' && tinymce.get('content');
- $textarea = $('#content');
if ( editor && ! editor.isHidden() ) {
editor.focus();
$('#timestamp').html(stamp);
} else {
$('#timestamp').html(
- publishOn + ' <b>' +
- postL10n.dateFormat.replace( '%1$s', $('option[value="' + $('#mm').val() + '"]', '#mm').text() )
- .replace( '%2$s', jj )
+ '\n' + publishOn + ' <b>' +
+ postL10n.dateFormat
+ .replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) )
+ .replace( '%2$s', parseInt( jj, 10 ) )
.replace( '%3$s', aa )
- .replace( '%4$s', hh )
- .replace( '%5$s', mn ) +
+ .replace( '%4$s', ( '00' + hh ).slice( -2 ) )
+ .replace( '%5$s', ( '00' + mn ).slice( -2 ) ) +
'</b> '
);
}
$( '#visibility .edit-visibility').click( function () {
if ( $postVisibilitySelect.is(':hidden') ) {
updateVisibility();
- $postVisibilitySelect.slideDown('fast').find('input[type="radio"]').first().focus();
+ $postVisibilitySelect.slideDown( 'fast', function() {
+ $postVisibilitySelect.find( 'input[type="radio"]' ).first().focus();
+ } );
$(this).hide();
}
return false;
$postVisibilitySelect.find('.save-post-visibility').click( function( event ) { // crazyhorse - multiple ok cancels
$postVisibilitySelect.slideUp('fast');
- $('#visibility .edit-visibility').show();
+ $('#visibility .edit-visibility').show().focus();
updateText();
if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) {
$timestampdiv.siblings('a.edit-timestamp').click( function( event ) {
if ( $timestampdiv.is( ':hidden' ) ) {
- $timestampdiv.slideDown('fast');
- $('#mm').focus();
+ $timestampdiv.slideDown( 'fast', function() {
+ $( 'input, select', $timestampdiv.find( '.timestamp-wrap' ) ).first().focus();
+ } );
$(this).hide();
}
event.preventDefault();
$timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - multiple ok cancels
if ( updateText() ) {
$timestampdiv.slideUp('fast');
- $timestampdiv.siblings('a.edit-timestamp').show();
+ $timestampdiv.siblings('a.edit-timestamp').show().focus();
}
event.preventDefault();
});
$postStatusSelect.siblings('a.edit-post-status').click( function( event ) {
if ( $postStatusSelect.is( ':hidden' ) ) {
- $postStatusSelect.slideDown('fast').find('select').focus();
+ $postStatusSelect.slideDown( 'fast', function() {
+ $postStatusSelect.find('select').focus();
+ } );
$(this).hide();
}
event.preventDefault();
});
$postStatusSelect.find('.save-post-status').click( function( event ) {
- $postStatusSelect.slideUp('fast').siblings('a.edit-post-status').show();
+ $postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().focus();
updateText();
event.preventDefault();
});
$postStatusSelect.find('.cancel-post-status').click( function( event ) {
- $('#post-status-select').slideUp('fast').siblings( 'a.edit-post-status' ).show().focus();
+ $postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().focus();
$('#post_status').val( $('#hidden_post_status').val() );
updateText();
event.preventDefault();
});
}
- // word count
- if ( typeof(wpWordCount) != 'undefined' ) {
- $document.triggerHandler('wpcountwords', [ co.val() ]);
-
- co.keyup( function(e) {
- var k = e.keyCode || e.charCode;
-
- if ( k == last )
- return true;
-
- if ( 13 == k || 8 == last || 46 == last )
- $document.triggerHandler('wpcountwords', [ co.val() ]);
-
- last = k;
- return true;
- });
- }
-
wptitlehint = function(id) {
id = id || 'title';
// Resize the visual and text editors
( function() {
var editor, offset, mce,
- $textarea = $('textarea#content'),
$handle = $('#post-status-info'),
$postdivrich = $('#postdivrich');
}
});
}
+
+ // Save on pressing Ctrl/Command + S in the Text editor
+ $textarea.on( 'keydown.wp-autosave', function( event ) {
+ if ( event.which === 83 ) {
+ if ( event.shiftKey || event.altKey || ( isMac && ( ! event.metaKey || event.ctrlKey ) ) || ( ! isMac && ! event.ctrlKey ) ) {
+ return;
+ }
+
+ wp.autosave && wp.autosave.server.triggerSave();
+ event.preventDefault();
+ }
+ });
});
+
+( function( $, counter ) {
+ $( function() {
+ var $content = $( '#content' ),
+ $count = $( '#wp-word-count' ).find( '.word-count' ),
+ prevCount = 0,
+ contentEditor;
+
+ function update() {
+ var text, count;
+
+ if ( ! contentEditor || contentEditor.isHidden() ) {
+ text = $content.val();
+ } else {
+ text = contentEditor.getContent( { format: 'raw' } );
+ }
+
+ count = counter.count( text );
+
+ if ( count !== prevCount ) {
+ $count.text( count );
+ }
+
+ prevCount = count;
+ }
+
+ $( document ).on( 'tinymce-editor-init', function( event, editor ) {
+ if ( editor.id !== 'content' ) {
+ return;
+ }
+
+ contentEditor = editor;
+
+ editor.on( 'nodechange keyup', _.debounce( update, 1000 ) );
+ } );
+
+ $content.on( 'input keyup', _.debounce( update, 1000 ) );
+
+ update();
+ } );
+} )( jQuery, new wp.utils.WordCounter() );