1 /* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting */
2 /* global theList:true, theExtraList:true, getUserSetting, setUserSetting */
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 ) {
176 if ( ( post_id = $('#post_ID').val() ) && ( nonce = $('#_wpnonce').val() ) ) {
177 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,
208 $document = $(document),
209 $editSlugWrap = $('#edit-slug-box'),
210 postId = $('#post_ID').val() || 0,
211 $submitpost = $('#submitpost'),
213 $postVisibilitySelect = $('#post-visibility-select'),
214 $timestampdiv = $('#timestampdiv'),
215 $postStatusSelect = $('#post-status-select');
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();
270 $(window).off( 'beforeunload.edit-post' );
272 $submitButtons.addClass( 'disabled' );
274 if ( $button.attr('id') === 'publish' ) {
275 $submitpost.find( '#major-publishing-actions .spinner' ).addClass( 'is-active' );
277 $submitpost.find( '#minor-publishing .spinner' ).addClass( 'is-active' );
282 // Submit the form saving a draft or an autosave, and show a preview in a new tab
283 $('#post-preview').on( 'click.post-preview', function( event ) {
285 $form = $('form#post'),
286 $previewField = $('input#wp-preview'),
287 target = $this.attr('target') || 'wp-preview',
288 ua = navigator.userAgent.toLowerCase();
290 event.preventDefault();
292 if ( $this.hasClass('disabled') ) {
297 wp.autosave.server.tempBlockSave();
300 $previewField.val('dopreview');
301 $form.attr( 'target', target ).submit().attr( 'target', '' );
303 // Workaround for WebKit bug preventing a form submitting twice to the same action.
304 // https://bugs.webkit.org/show_bug.cgi?id=28633
305 if ( ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1 ) {
306 $form.attr( 'action', function( index, value ) {
307 return value + '?t=' + ( new Date() ).getTime();
311 $previewField.val('');
314 // This code is meant to allow tabbing from Title to Post content.
315 $('#title').on( 'keydown.editor-focus', function( event ) {
316 var editor, $textarea;
318 if ( event.keyCode === 9 && ! event.ctrlKey && ! event.altKey && ! event.shiftKey ) {
319 editor = typeof tinymce != 'undefined' && tinymce.get('content');
320 $textarea = $('#content');
322 if ( editor && ! editor.isHidden() ) {
324 } else if ( $textarea.length ) {
330 event.preventDefault();
334 // Autosave new posts after a title is typed
335 if ( $( '#auto_draft' ).val() ) {
336 $( '#title' ).blur( function() {
339 if ( ! this.value || $('#edit-slug-box > *').length ) {
343 // Cancel the autosave when the blur was triggered by the user submitting the form
344 $('form#post').one( 'submit', function() {
348 window.setTimeout( function() {
349 if ( ! cancel && wp.autosave ) {
350 wp.autosave.server.triggerSave();
356 $document.on( 'autosave-disable-buttons.edit-post', function() {
357 $submitButtons.addClass( 'disabled' );
358 }).on( 'autosave-enable-buttons.edit-post', function() {
359 if ( ! wp.heartbeat || ! wp.heartbeat.hasConnectionError() ) {
360 $submitButtons.removeClass( 'disabled' );
362 }).on( 'before-autosave.edit-post', function() {
363 $( '.autosave-message' ).text( postL10n.savingText );
364 }).on( 'after-autosave.edit-post', function( event, data ) {
365 $( '.autosave-message' ).text( data.message );
368 $(window).on( 'beforeunload.edit-post', function() {
369 var editor = typeof tinymce !== 'undefined' && tinymce.get('content');
371 if ( ( editor && ! editor.isHidden() && editor.isDirty() ) ||
372 ( wp.autosave && wp.autosave.server.postChanged() ) ) {
374 return postL10n.saveAlert;
376 }).on( 'unload.edit-post', function( event ) {
377 if ( ! releaseLock ) {
381 // Unload is triggered (by hand) on removing the Thickbox iframe.
382 // Make sure we process only the main document unload.
383 if ( event.target && event.target.nodeName != '#document' ) {
392 action: 'wp-remove-post-lock',
393 _wpnonce: $('#_wpnonce').val(),
394 post_ID: $('#post_ID').val(),
395 active_post_lock: $('#active_post_lock').val()
401 if ( $('#tagsdiv-post_tag').length ) {
402 window.tagBox && window.tagBox.init();
404 $('#side-sortables, #normal-sortables, #advanced-sortables').children('div.postbox').each(function(){
405 if ( this.id.indexOf('tagsdiv-') === 0 ) {
406 window.tagBox && window.tagBox.init();
413 $('.categorydiv').each( function(){
414 var this_id = $(this).attr('id'), catAddBefore, catAddAfter, taxonomyParts, taxonomy, settingName;
416 taxonomyParts = this_id.split('-');
417 taxonomyParts.shift();
418 taxonomy = taxonomyParts.join('-');
419 settingName = taxonomy + '_tab';
420 if ( taxonomy == 'category' )
421 settingName = 'cats';
423 // TODO: move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js
424 $('a', '#' + taxonomy + '-tabs').click( function(){
425 var t = $(this).attr('href');
426 $(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
427 $('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide();
429 if ( '#' + taxonomy + '-all' == t )
430 deleteUserSetting( settingName );
432 setUserSetting( settingName, 'pop' );
436 if ( getUserSetting( settingName ) )
437 $('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').click();
440 $( '#new' + taxonomy ).one( 'focus', function() { $( this ).val( '' ).removeClass( 'form-input-tip' ); } );
442 $('#new' + taxonomy).keypress( function(event){
443 if( 13 === event.keyCode ) {
444 event.preventDefault();
445 $('#' + taxonomy + '-add-submit').click();
448 $('#' + taxonomy + '-add-submit').click( function(){ $('#new' + taxonomy).focus(); });
450 catAddBefore = function( s ) {
451 if ( !$('#new'+taxonomy).val() )
453 s.data += '&' + $( ':checked', '#'+taxonomy+'checklist' ).serialize();
454 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', true );
458 catAddAfter = function( r, s ) {
459 var sup, drop = $('#new'+taxonomy+'_parent');
461 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', false );
462 if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) {
468 $('#' + taxonomy + 'checklist').wpList({
470 response: taxonomy + '-ajax-response',
471 addBefore: catAddBefore,
472 addAfter: catAddAfter
475 $('#' + taxonomy + '-add-toggle').click( function() {
476 $('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' );
477 $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').click();
478 $('#new'+taxonomy).focus();
482 $('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on( 'click', 'li.popular-category > label input[type="checkbox"]', function() {
483 var t = $(this), c = t.is(':checked'), id = t.val();
484 if ( id && t.parents('#taxonomy-'+taxonomy).length )
485 $('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c );
491 if ( $('#postcustom').length ) {
492 $( '#the-list' ).wpList( { addAfter: function() {
493 $('table#list-table').show();
494 }, addBefore: function( s ) {
495 s.data += '&post_id=' + $('#post_ID').val();
502 if ( $('#submitdiv').length ) {
503 stamp = $('#timestamp').html();
504 visibility = $('#post-visibility-display').html();
506 updateVisibility = function() {
507 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) {
508 $('#sticky').prop('checked', false);
509 $('#sticky-span').hide();
511 $('#sticky-span').show();
513 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'password' ) {
514 $('#password-span').hide();
516 $('#password-span').show();
520 updateText = function() {
522 if ( ! $timestampdiv.length )
525 var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'),
526 optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(),
527 mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val();
529 attemptedDate = new Date( aa, mm - 1, jj, hh, mn );
530 originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val() );
531 currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() );
533 if ( attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn ) {
534 $timestampdiv.find('.timestamp-wrap').addClass('form-invalid');
537 $timestampdiv.find('.timestamp-wrap').removeClass('form-invalid');
540 if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
541 publishOn = postL10n.publishOnFuture;
542 $('#publish').val( postL10n.schedule );
543 } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
544 publishOn = postL10n.publishOn;
545 $('#publish').val( postL10n.publish );
547 publishOn = postL10n.publishOnPast;
548 $('#publish').val( postL10n.update );
550 if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack
551 $('#timestamp').html(stamp);
553 $('#timestamp').html(
555 postL10n.dateFormat.replace( '%1$s', $('option[value="' + $('#mm').val() + '"]', '#mm').text() )
556 .replace( '%2$s', jj )
557 .replace( '%3$s', aa )
558 .replace( '%4$s', hh )
559 .replace( '%5$s', mn ) +
564 if ( $postVisibilitySelect.find('input:radio:checked').val() == 'private' ) {
565 $('#publish').val( postL10n.update );
566 if ( 0 === optPublish.length ) {
567 postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
569 optPublish.html( postL10n.privatelyPublished );
571 $('option[value="publish"]', postStatus).prop('selected', true);
572 $('#misc-publishing-actions .edit-post-status').hide();
574 if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) {
575 if ( optPublish.length ) {
577 postStatus.val($('#hidden_post_status').val());
580 optPublish.html( postL10n.published );
582 if ( postStatus.is(':hidden') )
583 $('#misc-publishing-actions .edit-post-status').show();
585 $('#post-status-display').html($('option:selected', postStatus).text());
586 if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) {
587 $('#save-post').hide();
589 $('#save-post').show();
590 if ( $('option:selected', postStatus).val() == 'pending' ) {
591 $('#save-post').show().val( postL10n.savePending );
593 $('#save-post').show().val( postL10n.saveDraft );
599 $( '#visibility .edit-visibility').click( function () {
600 if ( $postVisibilitySelect.is(':hidden') ) {
602 $postVisibilitySelect.slideDown('fast').find('input[type="radio"]').first().focus();
608 $postVisibilitySelect.find('.cancel-post-visibility').click( function( event ) {
609 $postVisibilitySelect.slideUp('fast');
610 $('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true);
611 $('#post_password').val($('#hidden-post-password').val());
612 $('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked'));
613 $('#post-visibility-display').html(visibility);
614 $('#visibility .edit-visibility').show().focus();
616 event.preventDefault();
619 $postVisibilitySelect.find('.save-post-visibility').click( function( event ) { // crazyhorse - multiple ok cancels
620 $postVisibilitySelect.slideUp('fast');
621 $('#visibility .edit-visibility').show();
624 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) {
625 $('#sticky').prop('checked', false);
628 if ( $('#sticky').prop('checked') ) {
634 $('#post-visibility-display').html( postL10n[ $postVisibilitySelect.find('input:radio:checked').val() + sticky ] );
635 event.preventDefault();
638 $postVisibilitySelect.find('input:radio').change( function() {
642 $timestampdiv.siblings('a.edit-timestamp').click( function( event ) {
643 if ( $timestampdiv.is( ':hidden' ) ) {
644 $timestampdiv.slideDown('fast');
648 event.preventDefault();
651 $timestampdiv.find('.cancel-timestamp').click( function( event ) {
652 $timestampdiv.slideUp('fast').siblings('a.edit-timestamp').show().focus();
653 $('#mm').val($('#hidden_mm').val());
654 $('#jj').val($('#hidden_jj').val());
655 $('#aa').val($('#hidden_aa').val());
656 $('#hh').val($('#hidden_hh').val());
657 $('#mn').val($('#hidden_mn').val());
659 event.preventDefault();
662 $timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - multiple ok cancels
663 if ( updateText() ) {
664 $timestampdiv.slideUp('fast');
665 $timestampdiv.siblings('a.edit-timestamp').show();
667 event.preventDefault();
670 $('#post').on( 'submit', function( event ) {
671 if ( ! updateText() ) {
672 event.preventDefault();
673 $timestampdiv.show();
676 wp.autosave.enableButtons();
679 $( '#publishing-action .spinner' ).removeClass( 'is-active' );
683 $postStatusSelect.siblings('a.edit-post-status').click( function( event ) {
684 if ( $postStatusSelect.is( ':hidden' ) ) {
685 $postStatusSelect.slideDown('fast').find('select').focus();
688 event.preventDefault();
691 $postStatusSelect.find('.save-post-status').click( function( event ) {
692 $postStatusSelect.slideUp('fast').siblings('a.edit-post-status').show();
694 event.preventDefault();
697 $postStatusSelect.find('.cancel-post-status').click( function( event ) {
698 $('#post-status-select').slideUp('fast').siblings( 'a.edit-post-status' ).show().focus();
699 $('#post_status').val( $('#hidden_post_status').val() );
701 event.preventDefault();
706 function editPermalink() {
709 e = $('#editable-post-name'),
711 real_slug = $('#post_name'),
712 revert_slug = real_slug.val(),
713 b = $('#edit-slug-buttons'),
715 full = $('#editable-post-name-full');
717 // Deal with Twemoji in the post-name
718 full.find( 'img' ).replaceWith( function() { return this.alt; } );
721 $('#view-post-btn').hide();
722 b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>');
723 b.children('.save').click(function() {
724 var new_slug = e.children('input').val();
725 if ( new_slug == $('#editable-post-name-full').text() ) {
726 b.children('.cancel').click();
730 action: 'sample-permalink',
733 new_title: $('#title').val(),
734 samplepermalinknonce: $('#samplepermalinknonce').val()
736 var box = $('#edit-slug-box');
738 if (box.hasClass('hidden')) {
739 box.fadeIn('fast', function () {
740 box.removeClass('hidden');
745 real_slug.val(new_slug);
746 $('#view-post-btn').show();
751 b.children('.cancel').click(function() {
752 $('#view-post-btn').show();
755 real_slug.val(revert_slug);
759 for ( i = 0; i < full.length; ++i ) {
760 if ( '%' == full.charAt(i) )
764 slug_value = ( c > full.length / 4 ) ? '' : full;
765 e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e) {
766 var key = e.keyCode || 0;
767 // on enter, just save the new slug, don't save the post
769 b.children('.save').click();
773 b.children('.cancel').click();
776 } ).keyup( function() {
777 real_slug.val(this.value);
781 if ( $editSlugWrap.length ) {
782 $editSlugWrap.on( 'click', function( event ) {
783 var $target = $( event.target );
785 if ( $target.is('#editable-post-name') || $target.hasClass('edit-slug') ) {
792 if ( typeof(wpWordCount) != 'undefined' ) {
793 $document.triggerHandler('wpcountwords', [ co.val() ]);
795 co.keyup( function(e) {
796 var k = e.keyCode || e.charCode;
801 if ( 13 == k || 8 == last || 46 == last )
802 $document.triggerHandler('wpcountwords', [ co.val() ]);
809 wptitlehint = function(id) {
812 var title = $('#' + id), titleprompt = $('#' + id + '-prompt-text');
814 if ( '' === title.val() )
815 titleprompt.removeClass('screen-reader-text');
817 titleprompt.click(function(){
818 $(this).addClass('screen-reader-text');
822 title.blur(function(){
823 if ( '' === this.value )
824 titleprompt.removeClass('screen-reader-text');
826 titleprompt.addClass('screen-reader-text');
827 }).keydown(function(e){
828 titleprompt.addClass('screen-reader-text');
835 // Resize the visual and text editors
837 var editor, offset, mce,
838 $textarea = $('textarea#content'),
839 $handle = $('#post-status-info'),
840 $postdivrich = $('#postdivrich');
842 // No point for touch devices
843 if ( ! $textarea.length || 'ontouchstart' in window ) {
844 // Hide the resize handle
845 $('#content-resize-handle').hide();
849 function dragging( event ) {
850 if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) {
855 editor.theme.resizeTo( null, offset + event.pageY );
857 $textarea.height( Math.max( 50, offset + event.pageY ) );
860 event.preventDefault();
864 var height, toolbarHeight;
866 if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) {
872 toolbarHeight = parseInt( $( '#wp-content-editor-container .mce-toolbar-grp' ).height(), 10 );
874 if ( toolbarHeight < 10 || toolbarHeight > 200 ) {
878 height = parseInt( $('#content_ifr').css('height'), 10 ) + toolbarHeight - 28;
881 height = parseInt( $textarea.css('height'), 10 );
884 $document.off( '.wp-editor-resize' );
887 if ( height && height > 50 && height < 5000 ) {
888 setUserSetting( 'ed_size', height );
892 $handle.on( 'mousedown.wp-editor-resize', function( event ) {
893 if ( typeof tinymce !== 'undefined' ) {
894 editor = tinymce.get('content');
897 if ( editor && ! editor.isHidden() ) {
899 offset = $('#content_ifr').height() - event.pageY;
902 offset = $textarea.height() - event.pageY;
906 $document.on( 'mousemove.wp-editor-resize', dragging )
907 .on( 'mouseup.wp-editor-resize mouseleave.wp-editor-resize', endDrag );
909 event.preventDefault();
910 }).on( 'mouseup.wp-editor-resize', endDrag );
913 if ( typeof tinymce !== 'undefined' ) {
914 // When changing post formats, change the editor body class
915 $( '#post-formats-select input.post-format' ).on( 'change.set-editor-class', function() {
916 var editor, body, format = this.id;
918 if ( format && $( this ).prop( 'checked' ) && ( editor = tinymce.get( 'content' ) ) ) {
919 body = editor.getBody();
920 body.className = body.className.replace( /\bpost-format-[^ ]+/, '' );
921 editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format );
922 $( document ).trigger( 'editor-classchange' );