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>');
64 load: function(total){
65 this.st = jQuery('#the-comment-list tr.comment:visible').length;
70 WPSetThumbnailHTML = function(html){
71 $('.inside', '#postimagediv').html(html);
74 WPSetThumbnailID = function(id){
75 var field = $('input[value="_thumbnail_id"]', '#list-table');
76 if ( field.length > 0 ) {
77 $('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id);
81 WPRemoveThumbnail = function(nonce){
83 action: 'set-post-thumbnail', post_id: $( '#post_ID' ).val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie )
86 alert( setPostThumbnailL10n.error );
88 WPSetThumbnailHTML(str);
94 $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) {
95 var lock = $('#active_post_lock').val(),
96 post_id = $('#post_ID').val(),
99 if ( ! post_id || ! $('#post-lock-dialog').length )
102 send.post_id = post_id;
107 data['wp-refresh-post-lock'] = send;
109 }).on( 'heartbeat-tick.refresh-lock', function( e, data ) {
110 // Post locks: update the lock string or show the dialog if somebody has taken over editing
111 var received, wrap, avatar;
113 if ( data['wp-refresh-post-lock'] ) {
114 received = data['wp-refresh-post-lock'];
116 if ( received.lock_error ) {
117 // show "editing taken over" message
118 wrap = $('#post-lock-dialog');
120 if ( wrap.length && ! wrap.is(':visible') ) {
122 // Save the latest changes and disable
123 $(document).one( 'heartbeat-tick', function() {
124 wp.autosave.server.suspend();
125 wrap.removeClass('saving').addClass('saved');
126 $(window).off( 'beforeunload.edit-post' );
129 wrap.addClass('saving');
130 wp.autosave.server.triggerSave();
133 if ( received.lock_error.avatar_src ) {
134 avatar = $( '<img class="avatar avatar-64 photo" width="64" height="64" alt="" />' ).attr( 'src', received.lock_error.avatar_src.replace( /&/g, '&' ) );
135 wrap.find('div.post-locked-avatar').empty().append( avatar );
138 wrap.show().find('.currently-editing').text( received.lock_error.text );
139 wrap.find('.wp-tab-first').focus();
141 } else if ( received.new_lock ) {
142 $('#active_post_lock').val( received.new_lock );
145 }).on( 'before-autosave.update-post-slug', function() {
146 titleHasFocus = document.activeElement && document.activeElement.id === 'title';
147 }).on( 'after-autosave.update-post-slug', function() {
148 // Create slug area only if not already there
149 // and the title field was not focused (user was not typing a title) when autosave ran
150 if ( ! $('#edit-slug-box > *').length && ! titleHasFocus ) {
152 action: 'sample-permalink',
153 post_id: $('#post_ID').val(),
154 new_title: $('#title').val(),
155 samplepermalinknonce: $('#samplepermalinknonce').val()
158 if ( data != '-1' ) {
159 $('#edit-slug-box').html(data);
171 function schedule() {
173 window.clearTimeout( timeout );
174 timeout = window.setTimeout( function(){ check = true; }, 300000 );
177 $(document).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) {
179 $authCheck = $('#wp-auth-check-wrap');
181 if ( check || ( $authCheck.length && ! $authCheck.hasClass( 'hidden' ) ) ) {
182 if ( ( post_id = $('#post_ID').val() ) && $('#_wpnonce').val() ) {
183 data['wp-refresh-post-nonces'] = {
188 }).on( 'heartbeat-tick.wp-refresh-nonces', function( e, data ) {
189 var nonces = data['wp-refresh-post-nonces'];
194 if ( nonces.replace ) {
195 $.each( nonces.replace, function( selector, value ) {
196 $( '#' + selector ).val( value );
200 if ( nonces.heartbeatNonce )
201 window.heartbeatSettings.nonce = nonces.heartbeatNonce;
203 }).ready( function() {
208 jQuery(document).ready( function($) {
209 var stamp, visibility, $submitButtons, updateVisibility, updateText,
211 $textarea = $('#content'),
212 $document = $(document),
213 postId = $('#post_ID').val() || 0,
214 $submitpost = $('#submitpost'),
216 $postVisibilitySelect = $('#post-visibility-select'),
217 $timestampdiv = $('#timestampdiv'),
218 $postStatusSelect = $('#post-status-select'),
219 isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false;
221 postboxes.add_postbox_toggles(pagenow);
223 // Clear the window name. Otherwise if this is a former preview window where the user navigated to edit another post,
224 // and the first post is still being edited, clicking Preview there will use this window to show the preview.
227 // Post locks: contain focus inside the dialog. If the dialog is shown, focus the first item.
228 $('#post-lock-dialog .notification-dialog').on( 'keydown', function(e) {
232 var target = $(e.target);
234 if ( target.hasClass('wp-tab-first') && e.shiftKey ) {
235 $(this).find('.wp-tab-last').focus();
237 } else if ( target.hasClass('wp-tab-last') && ! e.shiftKey ) {
238 $(this).find('.wp-tab-first').focus();
241 }).filter(':visible').find('.wp-tab-first').focus();
243 // Set the heartbeat interval to 15 sec. if post lock dialogs are enabled
244 if ( wp.heartbeat && $('#post-lock-dialog').length ) {
245 wp.heartbeat.interval( 15 );
248 // The form is being submitted by the user
249 $submitButtons = $submitpost.find( ':submit, a.submitdelete, #post-preview' ).on( 'click.edit-post', function( event ) {
250 var $button = $(this);
252 if ( $button.hasClass('disabled') ) {
253 event.preventDefault();
257 if ( $button.hasClass('submitdelete') || $button.is( '#post-preview' ) ) {
261 // The form submission can be blocked from JS or by using HTML 5.0 validation on some fields.
262 // Run this only on an actual 'submit'.
263 $('form#post').off( 'submit.edit-post' ).on( 'submit.edit-post', function( event ) {
264 if ( event.isDefaultPrevented() ) {
270 wp.autosave.server.suspend();
273 if ( typeof commentReply !== 'undefined' ) {
275 * Warn the user they have an unsaved comment before submitting
276 * the post data for update.
278 if ( ! commentReply.discardCommentChanges() ) {
283 * Close the comment edit/reply form if open to stop the form
284 * action from interfering with the post's form action.
286 commentReply.close();
290 $(window).off( 'beforeunload.edit-post' );
292 $submitButtons.addClass( 'disabled' );
294 if ( $button.attr('id') === 'publish' ) {
295 $submitpost.find( '#major-publishing-actions .spinner' ).addClass( 'is-active' );
297 $submitpost.find( '#minor-publishing .spinner' ).addClass( 'is-active' );
302 // Submit the form saving a draft or an autosave, and show a preview in a new tab
303 $('#post-preview').on( 'click.post-preview', function( event ) {
305 $form = $('form#post'),
306 $previewField = $('input#wp-preview'),
307 target = $this.attr('target') || 'wp-preview',
308 ua = navigator.userAgent.toLowerCase();
310 event.preventDefault();
312 if ( $this.hasClass('disabled') ) {
317 wp.autosave.server.tempBlockSave();
320 $previewField.val('dopreview');
321 $form.attr( 'target', target ).submit().attr( 'target', '' );
323 // Workaround for WebKit bug preventing a form submitting twice to the same action.
324 // https://bugs.webkit.org/show_bug.cgi?id=28633
325 if ( ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1 ) {
326 $form.attr( 'action', function( index, value ) {
327 return value + '?t=' + ( new Date() ).getTime();
331 $previewField.val('');
334 // This code is meant to allow tabbing from Title to Post content.
335 $('#title').on( 'keydown.editor-focus', function( event ) {
338 if ( event.keyCode === 9 && ! event.ctrlKey && ! event.altKey && ! event.shiftKey ) {
339 editor = typeof tinymce != 'undefined' && tinymce.get('content');
341 if ( editor && ! editor.isHidden() ) {
343 } else if ( $textarea.length ) {
349 event.preventDefault();
353 // Autosave new posts after a title is typed
354 if ( $( '#auto_draft' ).val() ) {
355 $( '#title' ).blur( function() {
358 if ( ! this.value || $('#edit-slug-box > *').length ) {
362 // Cancel the autosave when the blur was triggered by the user submitting the form
363 $('form#post').one( 'submit', function() {
367 window.setTimeout( function() {
368 if ( ! cancel && wp.autosave ) {
369 wp.autosave.server.triggerSave();
375 $document.on( 'autosave-disable-buttons.edit-post', function() {
376 $submitButtons.addClass( 'disabled' );
377 }).on( 'autosave-enable-buttons.edit-post', function() {
378 if ( ! wp.heartbeat || ! wp.heartbeat.hasConnectionError() ) {
379 $submitButtons.removeClass( 'disabled' );
381 }).on( 'before-autosave.edit-post', function() {
382 $( '.autosave-message' ).text( postL10n.savingText );
383 }).on( 'after-autosave.edit-post', function( event, data ) {
384 $( '.autosave-message' ).text( data.message );
386 if ( $( document.body ).hasClass( 'post-new-php' ) ) {
387 $( '.submitbox .submitdelete' ).show();
391 $(window).on( 'beforeunload.edit-post', function() {
392 var editor = typeof tinymce !== 'undefined' && tinymce.get('content');
394 if ( ( editor && ! editor.isHidden() && editor.isDirty() ) ||
395 ( wp.autosave && wp.autosave.server.postChanged() ) ) {
397 return postL10n.saveAlert;
399 }).on( 'unload.edit-post', function( event ) {
400 if ( ! releaseLock ) {
404 // Unload is triggered (by hand) on removing the Thickbox iframe.
405 // Make sure we process only the main document unload.
406 if ( event.target && event.target.nodeName != '#document' ) {
415 action: 'wp-remove-post-lock',
416 _wpnonce: $('#_wpnonce').val(),
417 post_ID: $('#post_ID').val(),
418 active_post_lock: $('#active_post_lock').val()
424 if ( $('#tagsdiv-post_tag').length ) {
425 window.tagBox && window.tagBox.init();
427 $('.meta-box-sortables').children('div.postbox').each(function(){
428 if ( this.id.indexOf('tagsdiv-') === 0 ) {
429 window.tagBox && window.tagBox.init();
436 $('.categorydiv').each( function(){
437 var this_id = $(this).attr('id'), catAddBefore, catAddAfter, taxonomyParts, taxonomy, settingName;
439 taxonomyParts = this_id.split('-');
440 taxonomyParts.shift();
441 taxonomy = taxonomyParts.join('-');
442 settingName = taxonomy + '_tab';
443 if ( taxonomy == 'category' )
444 settingName = 'cats';
446 // TODO: move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js
447 $('a', '#' + taxonomy + '-tabs').click( function( e ) {
449 var t = $(this).attr('href');
450 $(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
451 $('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide();
453 if ( '#' + taxonomy + '-all' == t )
454 deleteUserSetting( settingName );
456 setUserSetting( settingName, 'pop' );
459 if ( getUserSetting( settingName ) )
460 $('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').click();
463 $( '#new' + taxonomy ).one( 'focus', function() { $( this ).val( '' ).removeClass( 'form-input-tip' ); } );
465 $('#new' + taxonomy).keypress( function(event){
466 if( 13 === event.keyCode ) {
467 event.preventDefault();
468 $('#' + taxonomy + '-add-submit').click();
471 $('#' + taxonomy + '-add-submit').click( function(){ $('#new' + taxonomy).focus(); });
473 catAddBefore = function( s ) {
474 if ( !$('#new'+taxonomy).val() )
476 s.data += '&' + $( ':checked', '#'+taxonomy+'checklist' ).serialize();
477 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', true );
481 catAddAfter = function( r, s ) {
482 var sup, drop = $('#new'+taxonomy+'_parent');
484 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', false );
485 if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) {
491 $('#' + taxonomy + 'checklist').wpList({
493 response: taxonomy + '-ajax-response',
494 addBefore: catAddBefore,
495 addAfter: catAddAfter
498 $('#' + taxonomy + '-add-toggle').click( function( e ) {
500 $('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' );
501 $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').click();
502 $('#new'+taxonomy).focus();
505 $('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on( 'click', 'li.popular-category > label input[type="checkbox"]', function() {
506 var t = $(this), c = t.is(':checked'), id = t.val();
507 if ( id && t.parents('#taxonomy-'+taxonomy).length )
508 $('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c );
514 if ( $('#postcustom').length ) {
515 $( '#the-list' ).wpList( { addAfter: function() {
516 $('table#list-table').show();
517 }, addBefore: function( s ) {
518 s.data += '&post_id=' + $('#post_ID').val();
525 if ( $('#submitdiv').length ) {
526 stamp = $('#timestamp').html();
527 visibility = $('#post-visibility-display').html();
529 updateVisibility = function() {
530 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) {
531 $('#sticky').prop('checked', false);
532 $('#sticky-span').hide();
534 $('#sticky-span').show();
536 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'password' ) {
537 $('#password-span').hide();
539 $('#password-span').show();
543 updateText = function() {
545 if ( ! $timestampdiv.length )
548 var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'),
549 optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(),
550 mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val();
552 attemptedDate = new Date( aa, mm - 1, jj, hh, mn );
553 originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val() );
554 currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() );
556 if ( attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn ) {
557 $timestampdiv.find('.timestamp-wrap').addClass('form-invalid');
560 $timestampdiv.find('.timestamp-wrap').removeClass('form-invalid');
563 if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
564 publishOn = postL10n.publishOnFuture;
565 $('#publish').val( postL10n.schedule );
566 } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
567 publishOn = postL10n.publishOn;
568 $('#publish').val( postL10n.publish );
570 publishOn = postL10n.publishOnPast;
571 $('#publish').val( postL10n.update );
573 if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack
574 $('#timestamp').html(stamp);
576 $('#timestamp').html(
577 '\n' + publishOn + ' <b>' +
579 .replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) )
580 .replace( '%2$s', parseInt( jj, 10 ) )
581 .replace( '%3$s', aa )
582 .replace( '%4$s', ( '00' + hh ).slice( -2 ) )
583 .replace( '%5$s', ( '00' + mn ).slice( -2 ) ) +
588 if ( $postVisibilitySelect.find('input:radio:checked').val() == 'private' ) {
589 $('#publish').val( postL10n.update );
590 if ( 0 === optPublish.length ) {
591 postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
593 optPublish.html( postL10n.privatelyPublished );
595 $('option[value="publish"]', postStatus).prop('selected', true);
596 $('#misc-publishing-actions .edit-post-status').hide();
598 if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) {
599 if ( optPublish.length ) {
601 postStatus.val($('#hidden_post_status').val());
604 optPublish.html( postL10n.published );
606 if ( postStatus.is(':hidden') )
607 $('#misc-publishing-actions .edit-post-status').show();
609 $('#post-status-display').html($('option:selected', postStatus).text());
610 if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) {
611 $('#save-post').hide();
613 $('#save-post').show();
614 if ( $('option:selected', postStatus).val() == 'pending' ) {
615 $('#save-post').show().val( postL10n.savePending );
617 $('#save-post').show().val( postL10n.saveDraft );
623 $( '#visibility .edit-visibility').click( function( e ) {
625 if ( $postVisibilitySelect.is(':hidden') ) {
627 $postVisibilitySelect.slideDown( 'fast', function() {
628 $postVisibilitySelect.find( 'input[type="radio"]' ).first().focus();
634 $postVisibilitySelect.find('.cancel-post-visibility').click( function( event ) {
635 $postVisibilitySelect.slideUp('fast');
636 $('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true);
637 $('#post_password').val($('#hidden-post-password').val());
638 $('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked'));
639 $('#post-visibility-display').html(visibility);
640 $('#visibility .edit-visibility').show().focus();
642 event.preventDefault();
645 $postVisibilitySelect.find('.save-post-visibility').click( function( event ) { // crazyhorse - multiple ok cancels
646 $postVisibilitySelect.slideUp('fast');
647 $('#visibility .edit-visibility').show().focus();
650 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) {
651 $('#sticky').prop('checked', false);
654 if ( $('#sticky').prop('checked') ) {
660 $('#post-visibility-display').html( postL10n[ $postVisibilitySelect.find('input:radio:checked').val() + sticky ] );
661 event.preventDefault();
664 $postVisibilitySelect.find('input:radio').change( function() {
668 $timestampdiv.siblings('a.edit-timestamp').click( function( event ) {
669 if ( $timestampdiv.is( ':hidden' ) ) {
670 $timestampdiv.slideDown( 'fast', function() {
671 $( 'input, select', $timestampdiv.find( '.timestamp-wrap' ) ).first().focus();
675 event.preventDefault();
678 $timestampdiv.find('.cancel-timestamp').click( function( event ) {
679 $timestampdiv.slideUp('fast').siblings('a.edit-timestamp').show().focus();
680 $('#mm').val($('#hidden_mm').val());
681 $('#jj').val($('#hidden_jj').val());
682 $('#aa').val($('#hidden_aa').val());
683 $('#hh').val($('#hidden_hh').val());
684 $('#mn').val($('#hidden_mn').val());
686 event.preventDefault();
689 $timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - multiple ok cancels
690 if ( updateText() ) {
691 $timestampdiv.slideUp('fast');
692 $timestampdiv.siblings('a.edit-timestamp').show().focus();
694 event.preventDefault();
697 $('#post').on( 'submit', function( event ) {
698 if ( ! updateText() ) {
699 event.preventDefault();
700 $timestampdiv.show();
703 wp.autosave.enableButtons();
706 $( '#publishing-action .spinner' ).removeClass( 'is-active' );
710 $postStatusSelect.siblings('a.edit-post-status').click( function( event ) {
711 if ( $postStatusSelect.is( ':hidden' ) ) {
712 $postStatusSelect.slideDown( 'fast', function() {
713 $postStatusSelect.find('select').focus();
717 event.preventDefault();
720 $postStatusSelect.find('.save-post-status').click( function( event ) {
721 $postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().focus();
723 event.preventDefault();
726 $postStatusSelect.find('.cancel-post-status').click( function( event ) {
727 $postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().focus();
728 $('#post_status').val( $('#hidden_post_status').val() );
730 event.preventDefault();
735 function editPermalink() {
739 real_slug = $('#post_name'),
740 revert_slug = real_slug.val(),
741 permalink = $( '#sample-permalink' ),
742 permalinkOrig = permalink.html(),
743 permalinkInner = $( '#sample-permalink a' ).html(),
744 buttons = $('#edit-slug-buttons'),
745 buttonsOrig = buttons.html(),
746 full = $('#editable-post-name-full');
748 // Deal with Twemoji in the post-name
749 full.find( 'img' ).replaceWith( function() { return this.alt; } );
752 permalink.html( permalinkInner );
753 $el = $( '#editable-post-name' );
754 revert_e = $el.html();
756 buttons.html( '<button type="button" class="save button button-small">' + postL10n.ok + '</button> <button type="button" class="cancel button-link">' + postL10n.cancel + '</button>' );
757 buttons.children( '.save' ).click( function() {
758 var new_slug = $el.children( 'input' ).val();
760 if ( new_slug == $('#editable-post-name-full').text() ) {
761 buttons.children('.cancel').click();
765 action: 'sample-permalink',
768 new_title: $('#title').val(),
769 samplepermalinknonce: $('#samplepermalinknonce').val()
771 var box = $('#edit-slug-box');
773 if (box.hasClass('hidden')) {
774 box.fadeIn('fast', function () {
775 box.removeClass('hidden');
779 buttons.html(buttonsOrig);
780 permalink.html(permalinkOrig);
781 real_slug.val(new_slug);
782 $( '.edit-slug' ).focus();
783 wp.a11y.speak( postL10n.permalinkSaved );
787 buttons.children( '.cancel' ).click( function() {
788 $('#view-post-btn').show();
790 buttons.html(buttonsOrig);
791 permalink.html(permalinkOrig);
792 real_slug.val(revert_slug);
793 $( '.edit-slug' ).focus();
796 for ( i = 0; i < full.length; ++i ) {
797 if ( '%' == full.charAt(i) )
801 slug_value = ( c > full.length / 4 ) ? '' : full;
802 $el.html( '<input type="text" id="new-post-slug" value="' + slug_value + '" autocomplete="off" />' ).children( 'input' ).keydown( function( e ) {
804 // On enter, just save the new slug, don't save the post.
807 buttons.children( '.save' ).click();
810 buttons.children( '.cancel' ).click();
812 } ).keyup( function() {
813 real_slug.val( this.value );
817 $( '#titlediv' ).on( 'click', '.edit-slug', function() {
821 wptitlehint = function(id) {
824 var title = $('#' + id), titleprompt = $('#' + id + '-prompt-text');
826 if ( '' === title.val() )
827 titleprompt.removeClass('screen-reader-text');
829 titleprompt.click(function(){
830 $(this).addClass('screen-reader-text');
834 title.blur(function(){
835 if ( '' === this.value )
836 titleprompt.removeClass('screen-reader-text');
838 titleprompt.addClass('screen-reader-text');
839 }).keydown(function(e){
840 titleprompt.addClass('screen-reader-text');
847 // Resize the visual and text editors
849 var editor, offset, mce,
850 $handle = $('#post-status-info'),
851 $postdivrich = $('#postdivrich');
853 // No point for touch devices
854 if ( ! $textarea.length || 'ontouchstart' in window ) {
855 // Hide the resize handle
856 $('#content-resize-handle').hide();
860 function dragging( event ) {
861 if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) {
866 editor.theme.resizeTo( null, offset + event.pageY );
868 $textarea.height( Math.max( 50, offset + event.pageY ) );
871 event.preventDefault();
875 var height, toolbarHeight;
877 if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) {
883 toolbarHeight = parseInt( $( '#wp-content-editor-container .mce-toolbar-grp' ).height(), 10 );
885 if ( toolbarHeight < 10 || toolbarHeight > 200 ) {
889 height = parseInt( $('#content_ifr').css('height'), 10 ) + toolbarHeight - 28;
892 height = parseInt( $textarea.css('height'), 10 );
895 $document.off( '.wp-editor-resize' );
898 if ( height && height > 50 && height < 5000 ) {
899 setUserSetting( 'ed_size', height );
903 $handle.on( 'mousedown.wp-editor-resize', function( event ) {
904 if ( typeof tinymce !== 'undefined' ) {
905 editor = tinymce.get('content');
908 if ( editor && ! editor.isHidden() ) {
910 offset = $('#content_ifr').height() - event.pageY;
913 offset = $textarea.height() - event.pageY;
917 $document.on( 'mousemove.wp-editor-resize', dragging )
918 .on( 'mouseup.wp-editor-resize mouseleave.wp-editor-resize', endDrag );
920 event.preventDefault();
921 }).on( 'mouseup.wp-editor-resize', endDrag );
924 if ( typeof tinymce !== 'undefined' ) {
925 // When changing post formats, change the editor body class
926 $( '#post-formats-select input.post-format' ).on( 'change.set-editor-class', function() {
927 var editor, body, format = this.id;
929 if ( format && $( this ).prop( 'checked' ) && ( editor = tinymce.get( 'content' ) ) ) {
930 body = editor.getBody();
931 body.className = body.className.replace( /\bpost-format-[^ ]+/, '' );
932 editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format );
933 $( document ).trigger( 'editor-classchange' );
938 // Save on pressing Ctrl/Command + S in the Text editor
939 $textarea.on( 'keydown.wp-autosave', function( event ) {
940 if ( event.which === 83 ) {
941 if ( event.shiftKey || event.altKey || ( isMac && ( ! event.metaKey || event.ctrlKey ) ) || ( ! isMac && ! event.ctrlKey ) ) {
945 wp.autosave && wp.autosave.server.triggerSave();
946 event.preventDefault();
950 if ( $( '#original_post_status' ).val() === 'auto-draft' && window.history.replaceState ) {
953 $( '#publish' ).on( 'click', function() {
954 location = window.location.href;
955 location += ( location.indexOf( '?' ) !== -1 ) ? '&' : '?';
956 location += 'wp-post-new-reload=true';
958 window.history.replaceState( null, null, location );
963 ( function( $, counter ) {
965 var $content = $( '#content' ),
966 $count = $( '#wp-word-count' ).find( '.word-count' ),
973 if ( ! contentEditor || contentEditor.isHidden() ) {
974 text = $content.val();
976 text = contentEditor.getContent( { format: 'raw' } );
979 count = counter.count( text );
981 if ( count !== prevCount ) {
982 $count.text( count );
988 $( document ).on( 'tinymce-editor-init', function( event, editor ) {
989 if ( editor.id !== 'content' ) {
993 contentEditor = editor;
995 editor.on( 'nodechange keyup', _.debounce( update, 1000 ) );
998 $content.on( 'input keyup', _.debounce( update, 1000 ) );
1002 } )( jQuery, new wp.utils.WordCounter() );