]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/post.js
WordPress 4.3
[autoinstalls/wordpress.git] / wp-admin / js / post.js
index 8dfdf3715f41e019f8f61bddc21e5644c9c84a6f..085c5d865a4cd58eabc47449e351c3b5734f72a7 100644 (file)
@@ -1,5 +1,5 @@
 /* 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
@@ -170,13 +170,13 @@ $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) {
        }
 
        $(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
                                };
                        }
                }
@@ -203,8 +203,7 @@ $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) {
 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,
@@ -212,7 +211,8 @@ jQuery(document).ready( function($) {
                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);
 
@@ -266,6 +266,14 @@ jQuery(document).ready( function($) {
                                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' );
 
@@ -313,11 +321,10 @@ jQuery(document).ready( function($) {
 
        // 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();
@@ -551,12 +558,13 @@ jQuery(document).ready( function($) {
                                $('#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> '
                                );
                        }
@@ -599,7 +607,9 @@ jQuery(document).ready( function($) {
                $( '#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;
@@ -618,7 +628,7 @@ jQuery(document).ready( function($) {
 
                $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' ) {
@@ -641,8 +651,9 @@ jQuery(document).ready( function($) {
 
                $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();
@@ -662,7 +673,7 @@ jQuery(document).ready( function($) {
                $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();
                });
@@ -682,20 +693,22 @@ jQuery(document).ready( function($) {
 
                $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();
@@ -788,24 +801,6 @@ jQuery(document).ready( function($) {
                });
        }
 
-       // 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';
 
@@ -835,7 +830,6 @@ jQuery(document).ready( function($) {
        // Resize the visual and text editors
        ( function() {
                var editor, offset, mce,
-                       $textarea = $('textarea#content'),
                        $handle = $('#post-status-info'),
                        $postdivrich = $('#postdivrich');
 
@@ -923,4 +917,57 @@ jQuery(document).ready( function($) {
                        }
                });
        }
+
+       // 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() );