1 /* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting */
2 /* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply */
4 var commentsBox, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint, makeSlugeditClickable, editPermalink;
5 // Back-compat: prevent fatal errors
6 makeSlugeditClickable = editPermalink = function(){};
8 window.wp = window.wp || {};
11 var titleHasFocus = false;
16 get : function(total, num) {
17 var st = this.st, data;
23 $( '#commentsdiv .spinner' ).addClass( 'is-active' );
26 'action' : 'get-comments',
28 '_ajax_nonce' : $('#add_comment_nonce').val(),
29 'p' : $('#post_ID').val(),
36 r = wpAjax.parseAjaxResponse(r);
37 $('#commentsdiv .widefat').show();
38 $( '#commentsdiv .spinner' ).removeClass( 'is-active' );
40 if ( 'object' == typeof r && r.responses[0] ) {
41 $('#the-comment-list').append( r.responses[0].data );
43 theList = theExtraList = null;
44 $( 'a[className*=\':\']' ).unbind();
46 if ( commentsBox.st > commentsBox.total )
47 $('#show-comments').hide();
49 $('#show-comments').show().children('a').html(postL10n.showcomm);
52 } else if ( 1 == r ) {
53 $('#show-comments').html(postL10n.endcomm);
57 $('#the-comment-list').append('<tr><td colspan="2">'+wpAjax.broken+'</td></tr>');
65 WPSetThumbnailHTML = function(html){
66 $('.inside', '#postimagediv').html(html);
69 WPSetThumbnailID = function(id){
70 var field = $('input[value="_thumbnail_id"]', '#list-table');
71 if ( field.size() > 0 ) {
72 $('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id);
76 WPRemoveThumbnail = function(nonce){
78 action: 'set-post-thumbnail', post_id: $( '#post_ID' ).val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie )
81 alert( setPostThumbnailL10n.error );
83 WPSetThumbnailHTML(str);
89 $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) {
90 var lock = $('#active_post_lock').val(),
91 post_id = $('#post_ID').val(),
94 if ( ! post_id || ! $('#post-lock-dialog').length )
97 send.post_id = post_id;
102 data['wp-refresh-post-lock'] = send;
104 }).on( 'heartbeat-tick.refresh-lock', function( e, data ) {
105 // Post locks: update the lock string or show the dialog if somebody has taken over editing
106 var received, wrap, avatar;
108 if ( data['wp-refresh-post-lock'] ) {
109 received = data['wp-refresh-post-lock'];
111 if ( received.lock_error ) {
112 // show "editing taken over" message
113 wrap = $('#post-lock-dialog');
115 if ( wrap.length && ! wrap.is(':visible') ) {
117 // Save the latest changes and disable
118 $(document).one( 'heartbeat-tick', function() {
119 wp.autosave.server.suspend();
120 wrap.removeClass('saving').addClass('saved');
121 $(window).off( 'beforeunload.edit-post' );
124 wrap.addClass('saving');
125 wp.autosave.server.triggerSave();
128 if ( received.lock_error.avatar_src ) {
129 avatar = $('<img class="avatar avatar-64 photo" width="64" height="64" />').attr( 'src', received.lock_error.avatar_src.replace(/&/g, '&') );
130 wrap.find('div.post-locked-avatar').empty().append( avatar );
133 wrap.show().find('.currently-editing').text( received.lock_error.text );
134 wrap.find('.wp-tab-first').focus();
136 } else if ( received.new_lock ) {
137 $('#active_post_lock').val( received.new_lock );
140 }).on( 'before-autosave.update-post-slug', function() {
141 titleHasFocus = document.activeElement && document.activeElement.id === 'title';
142 }).on( 'after-autosave.update-post-slug', function() {
143 // Create slug area only if not already there
144 // and the title field was not focused (user was not typing a title) when autosave ran
145 if ( ! $('#edit-slug-box > *').length && ! titleHasFocus ) {
147 action: 'sample-permalink',
148 post_id: $('#post_ID').val(),
149 new_title: $('#title').val(),
150 samplepermalinknonce: $('#samplepermalinknonce').val()
153 if ( data != '-1' ) {
154 $('#edit-slug-box').html(data);
166 function schedule() {
168 window.clearTimeout( timeout );
169 timeout = window.setTimeout( function(){ check = true; }, 300000 );
172 $(document).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) {
174 $authCheck = $('#wp-auth-check-wrap');
176 if ( check || ( $authCheck.length && ! $authCheck.hasClass( 'hidden' ) ) ) {
177 if ( ( post_id = $('#post_ID').val() ) && $('#_wpnonce').val() ) {
178 data['wp-refresh-post-nonces'] = {
183 }).on( 'heartbeat-tick.wp-refresh-nonces', function( e, data ) {
184 var nonces = data['wp-refresh-post-nonces'];
189 if ( nonces.replace ) {
190 $.each( nonces.replace, function( selector, value ) {
191 $( '#' + selector ).val( value );
195 if ( nonces.heartbeatNonce )
196 window.heartbeatSettings.nonce = nonces.heartbeatNonce;
198 }).ready( function() {
203 jQuery(document).ready( function($) {
204 var stamp, visibility, $submitButtons, updateVisibility, updateText,
206 $textarea = $('#content'),
207 $document = $(document),
208 $editSlugWrap = $('#edit-slug-box'),
209 postId = $('#post_ID').val() || 0,
210 $submitpost = $('#submitpost'),
212 $postVisibilitySelect = $('#post-visibility-select'),
213 $timestampdiv = $('#timestampdiv'),
214 $postStatusSelect = $('#post-status-select'),
215 isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false;
217 postboxes.add_postbox_toggles(pagenow);
219 // Clear the window name. Otherwise if this is a former preview window where the user navigated to edit another post,
220 // and the first post is still being edited, clicking Preview there will use this window to show the preview.
223 // Post locks: contain focus inside the dialog. If the dialog is shown, focus the first item.
224 $('#post-lock-dialog .notification-dialog').on( 'keydown', function(e) {
228 var target = $(e.target);
230 if ( target.hasClass('wp-tab-first') && e.shiftKey ) {
231 $(this).find('.wp-tab-last').focus();
233 } else if ( target.hasClass('wp-tab-last') && ! e.shiftKey ) {
234 $(this).find('.wp-tab-first').focus();
237 }).filter(':visible').find('.wp-tab-first').focus();
239 // Set the heartbeat interval to 15 sec. if post lock dialogs are enabled
240 if ( wp.heartbeat && $('#post-lock-dialog').length ) {
241 wp.heartbeat.interval( 15 );
244 // The form is being submitted by the user
245 $submitButtons = $submitpost.find( ':submit, a.submitdelete, #post-preview' ).on( 'click.edit-post', function( event ) {
246 var $button = $(this);
248 if ( $button.hasClass('disabled') ) {
249 event.preventDefault();
253 if ( $button.hasClass('submitdelete') || $button.is( '#post-preview' ) ) {
257 // The form submission can be blocked from JS or by using HTML 5.0 validation on some fields.
258 // Run this only on an actual 'submit'.
259 $('form#post').off( 'submit.edit-post' ).on( 'submit.edit-post', function( event ) {
260 if ( event.isDefaultPrevented() ) {
266 wp.autosave.server.suspend();
269 if ( typeof commentReply !== 'undefined' ) {
271 * Close the comment edit/reply form if open to stop the form
272 * action from interfering with the post's form action.
274 commentReply.close();
278 $(window).off( 'beforeunload.edit-post' );
280 $submitButtons.addClass( 'disabled' );
282 if ( $button.attr('id') === 'publish' ) {
283 $submitpost.find( '#major-publishing-actions .spinner' ).addClass( 'is-active' );
285 $submitpost.find( '#minor-publishing .spinner' ).addClass( 'is-active' );
290 // Submit the form saving a draft or an autosave, and show a preview in a new tab
291 $('#post-preview').on( 'click.post-preview', function( event ) {
293 $form = $('form#post'),
294 $previewField = $('input#wp-preview'),
295 target = $this.attr('target') || 'wp-preview',
296 ua = navigator.userAgent.toLowerCase();
298 event.preventDefault();
300 if ( $this.hasClass('disabled') ) {
305 wp.autosave.server.tempBlockSave();
308 $previewField.val('dopreview');
309 $form.attr( 'target', target ).submit().attr( 'target', '' );
311 // Workaround for WebKit bug preventing a form submitting twice to the same action.
312 // https://bugs.webkit.org/show_bug.cgi?id=28633
313 if ( ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1 ) {
314 $form.attr( 'action', function( index, value ) {
315 return value + '?t=' + ( new Date() ).getTime();
319 $previewField.val('');
322 // This code is meant to allow tabbing from Title to Post content.
323 $('#title').on( 'keydown.editor-focus', function( event ) {
326 if ( event.keyCode === 9 && ! event.ctrlKey && ! event.altKey && ! event.shiftKey ) {
327 editor = typeof tinymce != 'undefined' && tinymce.get('content');
329 if ( editor && ! editor.isHidden() ) {
331 } else if ( $textarea.length ) {
337 event.preventDefault();
341 // Autosave new posts after a title is typed
342 if ( $( '#auto_draft' ).val() ) {
343 $( '#title' ).blur( function() {
346 if ( ! this.value || $('#edit-slug-box > *').length ) {
350 // Cancel the autosave when the blur was triggered by the user submitting the form
351 $('form#post').one( 'submit', function() {
355 window.setTimeout( function() {
356 if ( ! cancel && wp.autosave ) {
357 wp.autosave.server.triggerSave();
363 $document.on( 'autosave-disable-buttons.edit-post', function() {
364 $submitButtons.addClass( 'disabled' );
365 }).on( 'autosave-enable-buttons.edit-post', function() {
366 if ( ! wp.heartbeat || ! wp.heartbeat.hasConnectionError() ) {
367 $submitButtons.removeClass( 'disabled' );
369 }).on( 'before-autosave.edit-post', function() {
370 $( '.autosave-message' ).text( postL10n.savingText );
371 }).on( 'after-autosave.edit-post', function( event, data ) {
372 $( '.autosave-message' ).text( data.message );
375 $(window).on( 'beforeunload.edit-post', function() {
376 var editor = typeof tinymce !== 'undefined' && tinymce.get('content');
378 if ( ( editor && ! editor.isHidden() && editor.isDirty() ) ||
379 ( wp.autosave && wp.autosave.server.postChanged() ) ) {
381 return postL10n.saveAlert;
383 }).on( 'unload.edit-post', function( event ) {
384 if ( ! releaseLock ) {
388 // Unload is triggered (by hand) on removing the Thickbox iframe.
389 // Make sure we process only the main document unload.
390 if ( event.target && event.target.nodeName != '#document' ) {
399 action: 'wp-remove-post-lock',
400 _wpnonce: $('#_wpnonce').val(),
401 post_ID: $('#post_ID').val(),
402 active_post_lock: $('#active_post_lock').val()
408 if ( $('#tagsdiv-post_tag').length ) {
409 window.tagBox && window.tagBox.init();
411 $('#side-sortables, #normal-sortables, #advanced-sortables').children('div.postbox').each(function(){
412 if ( this.id.indexOf('tagsdiv-') === 0 ) {
413 window.tagBox && window.tagBox.init();
420 $('.categorydiv').each( function(){
421 var this_id = $(this).attr('id'), catAddBefore, catAddAfter, taxonomyParts, taxonomy, settingName;
423 taxonomyParts = this_id.split('-');
424 taxonomyParts.shift();
425 taxonomy = taxonomyParts.join('-');
426 settingName = taxonomy + '_tab';
427 if ( taxonomy == 'category' )
428 settingName = 'cats';
430 // TODO: move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js
431 $('a', '#' + taxonomy + '-tabs').click( function(){
432 var t = $(this).attr('href');
433 $(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
434 $('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide();
436 if ( '#' + taxonomy + '-all' == t )
437 deleteUserSetting( settingName );
439 setUserSetting( settingName, 'pop' );
443 if ( getUserSetting( settingName ) )
444 $('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').click();
447 $( '#new' + taxonomy ).one( 'focus', function() { $( this ).val( '' ).removeClass( 'form-input-tip' ); } );
449 $('#new' + taxonomy).keypress( function(event){
450 if( 13 === event.keyCode ) {
451 event.preventDefault();
452 $('#' + taxonomy + '-add-submit').click();
455 $('#' + taxonomy + '-add-submit').click( function(){ $('#new' + taxonomy).focus(); });
457 catAddBefore = function( s ) {
458 if ( !$('#new'+taxonomy).val() )
460 s.data += '&' + $( ':checked', '#'+taxonomy+'checklist' ).serialize();
461 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', true );
465 catAddAfter = function( r, s ) {
466 var sup, drop = $('#new'+taxonomy+'_parent');
468 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', false );
469 if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) {
475 $('#' + taxonomy + 'checklist').wpList({
477 response: taxonomy + '-ajax-response',
478 addBefore: catAddBefore,
479 addAfter: catAddAfter
482 $('#' + taxonomy + '-add-toggle').click( function() {
483 $('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' );
484 $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').click();
485 $('#new'+taxonomy).focus();
489 $('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on( 'click', 'li.popular-category > label input[type="checkbox"]', function() {
490 var t = $(this), c = t.is(':checked'), id = t.val();
491 if ( id && t.parents('#taxonomy-'+taxonomy).length )
492 $('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c );
498 if ( $('#postcustom').length ) {
499 $( '#the-list' ).wpList( { addAfter: function() {
500 $('table#list-table').show();
501 }, addBefore: function( s ) {
502 s.data += '&post_id=' + $('#post_ID').val();
509 if ( $('#submitdiv').length ) {
510 stamp = $('#timestamp').html();
511 visibility = $('#post-visibility-display').html();
513 updateVisibility = function() {
514 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) {
515 $('#sticky').prop('checked', false);
516 $('#sticky-span').hide();
518 $('#sticky-span').show();
520 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'password' ) {
521 $('#password-span').hide();
523 $('#password-span').show();
527 updateText = function() {
529 if ( ! $timestampdiv.length )
532 var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'),
533 optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(),
534 mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val();
536 attemptedDate = new Date( aa, mm - 1, jj, hh, mn );
537 originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val() );
538 currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() );
540 if ( attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn ) {
541 $timestampdiv.find('.timestamp-wrap').addClass('form-invalid');
544 $timestampdiv.find('.timestamp-wrap').removeClass('form-invalid');
547 if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
548 publishOn = postL10n.publishOnFuture;
549 $('#publish').val( postL10n.schedule );
550 } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
551 publishOn = postL10n.publishOn;
552 $('#publish').val( postL10n.publish );
554 publishOn = postL10n.publishOnPast;
555 $('#publish').val( postL10n.update );
557 if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack
558 $('#timestamp').html(stamp);
560 $('#timestamp').html(
561 '\n' + publishOn + ' <b>' +
563 .replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) )
564 .replace( '%2$s', parseInt( jj, 10 ) )
565 .replace( '%3$s', aa )
566 .replace( '%4$s', ( '00' + hh ).slice( -2 ) )
567 .replace( '%5$s', ( '00' + mn ).slice( -2 ) ) +
572 if ( $postVisibilitySelect.find('input:radio:checked').val() == 'private' ) {
573 $('#publish').val( postL10n.update );
574 if ( 0 === optPublish.length ) {
575 postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
577 optPublish.html( postL10n.privatelyPublished );
579 $('option[value="publish"]', postStatus).prop('selected', true);
580 $('#misc-publishing-actions .edit-post-status').hide();
582 if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) {
583 if ( optPublish.length ) {
585 postStatus.val($('#hidden_post_status').val());
588 optPublish.html( postL10n.published );
590 if ( postStatus.is(':hidden') )
591 $('#misc-publishing-actions .edit-post-status').show();
593 $('#post-status-display').html($('option:selected', postStatus).text());
594 if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) {
595 $('#save-post').hide();
597 $('#save-post').show();
598 if ( $('option:selected', postStatus).val() == 'pending' ) {
599 $('#save-post').show().val( postL10n.savePending );
601 $('#save-post').show().val( postL10n.saveDraft );
607 $( '#visibility .edit-visibility').click( function () {
608 if ( $postVisibilitySelect.is(':hidden') ) {
610 $postVisibilitySelect.slideDown( 'fast', function() {
611 $postVisibilitySelect.find( 'input[type="radio"]' ).first().focus();
618 $postVisibilitySelect.find('.cancel-post-visibility').click( function( event ) {
619 $postVisibilitySelect.slideUp('fast');
620 $('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true);
621 $('#post_password').val($('#hidden-post-password').val());
622 $('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked'));
623 $('#post-visibility-display').html(visibility);
624 $('#visibility .edit-visibility').show().focus();
626 event.preventDefault();
629 $postVisibilitySelect.find('.save-post-visibility').click( function( event ) { // crazyhorse - multiple ok cancels
630 $postVisibilitySelect.slideUp('fast');
631 $('#visibility .edit-visibility').show().focus();
634 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) {
635 $('#sticky').prop('checked', false);
638 if ( $('#sticky').prop('checked') ) {
644 $('#post-visibility-display').html( postL10n[ $postVisibilitySelect.find('input:radio:checked').val() + sticky ] );
645 event.preventDefault();
648 $postVisibilitySelect.find('input:radio').change( function() {
652 $timestampdiv.siblings('a.edit-timestamp').click( function( event ) {
653 if ( $timestampdiv.is( ':hidden' ) ) {
654 $timestampdiv.slideDown( 'fast', function() {
655 $( 'input, select', $timestampdiv.find( '.timestamp-wrap' ) ).first().focus();
659 event.preventDefault();
662 $timestampdiv.find('.cancel-timestamp').click( function( event ) {
663 $timestampdiv.slideUp('fast').siblings('a.edit-timestamp').show().focus();
664 $('#mm').val($('#hidden_mm').val());
665 $('#jj').val($('#hidden_jj').val());
666 $('#aa').val($('#hidden_aa').val());
667 $('#hh').val($('#hidden_hh').val());
668 $('#mn').val($('#hidden_mn').val());
670 event.preventDefault();
673 $timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - multiple ok cancels
674 if ( updateText() ) {
675 $timestampdiv.slideUp('fast');
676 $timestampdiv.siblings('a.edit-timestamp').show().focus();
678 event.preventDefault();
681 $('#post').on( 'submit', function( event ) {
682 if ( ! updateText() ) {
683 event.preventDefault();
684 $timestampdiv.show();
687 wp.autosave.enableButtons();
690 $( '#publishing-action .spinner' ).removeClass( 'is-active' );
694 $postStatusSelect.siblings('a.edit-post-status').click( function( event ) {
695 if ( $postStatusSelect.is( ':hidden' ) ) {
696 $postStatusSelect.slideDown( 'fast', function() {
697 $postStatusSelect.find('select').focus();
701 event.preventDefault();
704 $postStatusSelect.find('.save-post-status').click( function( event ) {
705 $postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().focus();
707 event.preventDefault();
710 $postStatusSelect.find('.cancel-post-status').click( function( event ) {
711 $postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().focus();
712 $('#post_status').val( $('#hidden_post_status').val() );
714 event.preventDefault();
719 function editPermalink() {
722 e = $('#editable-post-name'),
724 real_slug = $('#post_name'),
725 revert_slug = real_slug.val(),
726 b = $('#edit-slug-buttons'),
728 full = $('#editable-post-name-full');
730 // Deal with Twemoji in the post-name
731 full.find( 'img' ).replaceWith( function() { return this.alt; } );
734 $('#view-post-btn').hide();
735 b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>');
736 b.children('.save').click(function() {
737 var new_slug = e.children('input').val();
738 if ( new_slug == $('#editable-post-name-full').text() ) {
739 b.children('.cancel').click();
743 action: 'sample-permalink',
746 new_title: $('#title').val(),
747 samplepermalinknonce: $('#samplepermalinknonce').val()
749 var box = $('#edit-slug-box');
751 if (box.hasClass('hidden')) {
752 box.fadeIn('fast', function () {
753 box.removeClass('hidden');
758 real_slug.val(new_slug);
759 $('#view-post-btn').show();
764 b.children('.cancel').click(function() {
765 $('#view-post-btn').show();
768 real_slug.val(revert_slug);
772 for ( i = 0; i < full.length; ++i ) {
773 if ( '%' == full.charAt(i) )
777 slug_value = ( c > full.length / 4 ) ? '' : full;
778 e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e) {
779 var key = e.keyCode || 0;
780 // on enter, just save the new slug, don't save the post
782 b.children('.save').click();
786 b.children('.cancel').click();
789 } ).keyup( function() {
790 real_slug.val(this.value);
794 if ( $editSlugWrap.length ) {
795 $editSlugWrap.on( 'click', function( event ) {
796 var $target = $( event.target );
798 if ( $target.is('#editable-post-name') || $target.hasClass('edit-slug') ) {
804 wptitlehint = function(id) {
807 var title = $('#' + id), titleprompt = $('#' + id + '-prompt-text');
809 if ( '' === title.val() )
810 titleprompt.removeClass('screen-reader-text');
812 titleprompt.click(function(){
813 $(this).addClass('screen-reader-text');
817 title.blur(function(){
818 if ( '' === this.value )
819 titleprompt.removeClass('screen-reader-text');
821 titleprompt.addClass('screen-reader-text');
822 }).keydown(function(e){
823 titleprompt.addClass('screen-reader-text');
830 // Resize the visual and text editors
832 var editor, offset, mce,
833 $handle = $('#post-status-info'),
834 $postdivrich = $('#postdivrich');
836 // No point for touch devices
837 if ( ! $textarea.length || 'ontouchstart' in window ) {
838 // Hide the resize handle
839 $('#content-resize-handle').hide();
843 function dragging( event ) {
844 if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) {
849 editor.theme.resizeTo( null, offset + event.pageY );
851 $textarea.height( Math.max( 50, offset + event.pageY ) );
854 event.preventDefault();
858 var height, toolbarHeight;
860 if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) {
866 toolbarHeight = parseInt( $( '#wp-content-editor-container .mce-toolbar-grp' ).height(), 10 );
868 if ( toolbarHeight < 10 || toolbarHeight > 200 ) {
872 height = parseInt( $('#content_ifr').css('height'), 10 ) + toolbarHeight - 28;
875 height = parseInt( $textarea.css('height'), 10 );
878 $document.off( '.wp-editor-resize' );
881 if ( height && height > 50 && height < 5000 ) {
882 setUserSetting( 'ed_size', height );
886 $handle.on( 'mousedown.wp-editor-resize', function( event ) {
887 if ( typeof tinymce !== 'undefined' ) {
888 editor = tinymce.get('content');
891 if ( editor && ! editor.isHidden() ) {
893 offset = $('#content_ifr').height() - event.pageY;
896 offset = $textarea.height() - event.pageY;
900 $document.on( 'mousemove.wp-editor-resize', dragging )
901 .on( 'mouseup.wp-editor-resize mouseleave.wp-editor-resize', endDrag );
903 event.preventDefault();
904 }).on( 'mouseup.wp-editor-resize', endDrag );
907 if ( typeof tinymce !== 'undefined' ) {
908 // When changing post formats, change the editor body class
909 $( '#post-formats-select input.post-format' ).on( 'change.set-editor-class', function() {
910 var editor, body, format = this.id;
912 if ( format && $( this ).prop( 'checked' ) && ( editor = tinymce.get( 'content' ) ) ) {
913 body = editor.getBody();
914 body.className = body.className.replace( /\bpost-format-[^ ]+/, '' );
915 editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format );
916 $( document ).trigger( 'editor-classchange' );
921 // Save on pressing Ctrl/Command + S in the Text editor
922 $textarea.on( 'keydown.wp-autosave', function( event ) {
923 if ( event.which === 83 ) {
924 if ( event.shiftKey || event.altKey || ( isMac && ( ! event.metaKey || event.ctrlKey ) ) || ( ! isMac && ! event.ctrlKey ) ) {
928 wp.autosave && wp.autosave.server.triggerSave();
929 event.preventDefault();
934 ( function( $, counter ) {
936 var $content = $( '#content' ),
937 $count = $( '#wp-word-count' ).find( '.word-count' ),
944 if ( ! contentEditor || contentEditor.isHidden() ) {
945 text = $content.val();
947 text = contentEditor.getContent( { format: 'raw' } );
950 count = counter.count( text );
952 if ( count !== prevCount ) {
953 $count.text( count );
959 $( document ).on( 'tinymce-editor-init', function( event, editor ) {
960 if ( editor.id !== 'content' ) {
964 contentEditor = editor;
966 editor.on( 'nodechange keyup', _.debounce( update, 1000 ) );
969 $content.on( 'input keyup', _.debounce( update, 1000 ) );
973 } )( jQuery, new wp.utils.WordCounter() );