1 /* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting, getUserSetting, setUserSetting */
2 /* global theList:true, theExtraList:true, autosave:true */
4 var tagBox, commentsBox, editPermalink, makeSlugeditClickable, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint;
6 // return an array with any duplicate, whitespace or values removed
7 function array_unique_noempty(a) {
9 jQuery.each( a, function(key, val) {
10 val = jQuery.trim(val);
11 if ( val && jQuery.inArray(val, out) == -1 )
20 clean : function(tags) {
21 var comma = postL10n.comma;
23 tags = tags.replace(new RegExp(comma, 'g'), ',');
24 tags = tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, '');
26 tags = tags.replace(/,/g, comma);
30 parseTags : function(el) {
31 var id = el.id, num = id.split('-check-num-')[1], taxbox = $(el).closest('.tagsdiv'),
32 thetags = taxbox.find('.the-tags'), comma = postL10n.comma,
33 current_tags = thetags.val().split(comma), new_tags = [];
34 delete current_tags[num];
36 $.each( current_tags, function(key, val) {
43 thetags.val( this.clean( new_tags.join(comma) ) );
45 this.quickClicks(taxbox);
49 quickClicks : function(el) {
50 var thetags = $('.the-tags', el),
51 tagchecklist = $('.tagchecklist', el),
52 id = $(el).attr('id'),
53 current_tags, disabled;
55 if ( !thetags.length )
58 disabled = thetags.prop('disabled');
60 current_tags = thetags.val().split(postL10n.comma);
63 $.each( current_tags, function( key, val ) {
71 // Create a new span, and ensure the text is properly escaped.
72 span = $('<span />').text( val );
74 // If tags editing isn't disabled, create the X button.
76 xbutton = $( '<a id="' + id + '-check-num-' + key + '" class="ntdelbutton">X</a>' );
77 xbutton.click( function(){ tagBox.parseTags(this); });
78 span.prepend(' ').prepend( xbutton );
81 // Append the span to the tag list.
82 tagchecklist.append( span );
86 flushTags : function(el, a, f) {
87 var tagsval, newtags, text,
88 tags = $('.the-tags', el),
89 newtag = $('input.newtag', el),
90 comma = postL10n.comma;
93 text = a ? $(a).text() : newtag.val();
95 newtags = tagsval ? tagsval + comma + text : text;
97 newtags = this.clean( newtags );
98 newtags = array_unique_noempty( newtags.split(comma) ).join(comma);
100 this.quickClicks(el);
104 if ( 'undefined' == typeof(f) )
111 var tax = id.substr(id.indexOf('-')+1);
113 $.post(ajaxurl, {'action':'get-tagcloud', 'tax':tax}, function(r, stat) {
114 if ( 0 === r || 'success' != stat )
117 r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>');
118 $('a', r).click(function(){
119 tagBox.flushTags( $(this).closest('.inside').children('.tagsdiv'), this);
128 var t = this, ajaxtag = $('div.ajaxtag');
130 $('.tagsdiv').each( function() {
131 tagBox.quickClicks(this);
134 $('input.tagadd', ajaxtag).click(function(){
135 t.flushTags( $(this).closest('.tagsdiv') );
138 $('div.taghint', ajaxtag).click(function(){
139 $(this).css('visibility', 'hidden').parent().siblings('.newtag').focus();
142 $('input.newtag', ajaxtag).blur(function() {
143 if ( '' === this.value )
144 $(this).parent().siblings('.taghint').css('visibility', '');
146 $(this).parent().siblings('.taghint').css('visibility', 'hidden');
147 }).keyup(function(e){
148 if ( 13 == e.which ) {
149 tagBox.flushTags( $(this).closest('.tagsdiv') );
152 }).keypress(function(e){
153 if ( 13 == e.which ) {
158 var tax = $(this).closest('div.tagsdiv').attr('id');
159 $(this).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: postL10n.comma + ' ' } );
162 // save tags on post save/publish
163 $('#post').submit(function(){
164 $('div.tagsdiv').each( function() {
165 tagBox.flushTags(this, false, 1);
170 $('a.tagcloud-link').click(function(){
171 tagBox.get( $(this).attr('id') );
172 $(this).unbind().click(function(){
173 $(this).siblings('.the-tagcloud').toggle();
184 get : function(total, num) {
185 var st = this.st, data;
191 $('#commentsdiv .spinner').show();
194 'action' : 'get-comments',
196 '_ajax_nonce' : $('#add_comment_nonce').val(),
197 'p' : $('#post_ID').val(),
202 $.post(ajaxurl, data,
204 r = wpAjax.parseAjaxResponse(r);
205 $('#commentsdiv .widefat').show();
206 $('#commentsdiv .spinner').hide();
208 if ( 'object' == typeof r && r.responses[0] ) {
209 $('#the-comment-list').append( r.responses[0].data );
211 theList = theExtraList = null;
212 $( 'a[className*=\':\']' ).unbind();
214 if ( commentsBox.st > commentsBox.total )
215 $('#show-comments').hide();
217 $('#show-comments').show().children('a').html(postL10n.showcomm);
220 } else if ( 1 == r ) {
221 $('#show-comments').html(postL10n.endcomm);
225 $('#the-comment-list').append('<tr><td colspan="2">'+wpAjax.broken+'</td></tr>');
233 WPSetThumbnailHTML = function(html){
234 $('.inside', '#postimagediv').html(html);
237 WPSetThumbnailID = function(id){
238 var field = $('input[value="_thumbnail_id"]', '#list-table');
239 if ( field.size() > 0 ) {
240 $('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id);
244 WPRemoveThumbnail = function(nonce){
246 action: 'set-post-thumbnail', post_id: $( '#post_ID' ).val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie )
249 alert( setPostThumbnailL10n.error );
251 WPSetThumbnailHTML(str);
257 $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) {
258 var lock = $('#active_post_lock').val(),
259 post_id = $('#post_ID').val(),
262 if ( ! post_id || ! $('#post-lock-dialog').length )
265 send.post_id = post_id;
270 data['wp-refresh-post-lock'] = send;
273 // Post locks: update the lock string or show the dialog if somebody has taken over editing
274 $(document).on( 'heartbeat-tick.refresh-lock', function( e, data ) {
275 var received, wrap, avatar;
277 if ( data['wp-refresh-post-lock'] ) {
278 received = data['wp-refresh-post-lock'];
280 if ( received.lock_error ) {
281 // show "editing taken over" message
282 wrap = $('#post-lock-dialog');
284 if ( wrap.length && ! wrap.is(':visible') ) {
285 if ( typeof autosave == 'function' ) {
286 $(document).on('autosave-disable-buttons.post-lock', function() {
287 wrap.addClass('saving');
288 }).on('autosave-enable-buttons.post-lock', function() {
289 wrap.removeClass('saving').addClass('saved');
290 window.onbeforeunload = null;
293 // Save the latest changes and disable
295 window.onbeforeunload = null;
297 autosave = function(){};
300 if ( received.lock_error.avatar_src ) {
301 avatar = $('<img class="avatar avatar-64 photo" width="64" height="64" />').attr( 'src', received.lock_error.avatar_src.replace(/&/g, '&') );
302 wrap.find('div.post-locked-avatar').empty().append( avatar );
305 wrap.show().find('.currently-editing').text( received.lock_error.text );
306 wrap.find('.wp-tab-first').focus();
308 } else if ( received.new_lock ) {
309 $('#active_post_lock').val( received.new_lock );
319 function schedule() {
321 window.clearTimeout( timeout );
322 timeout = window.setTimeout( function(){ check = true; }, 300000 );
325 $(document).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) {
329 if ( ( post_id = $('#post_ID').val() ) && ( nonce = $('#_wpnonce').val() ) ) {
330 data['wp-refresh-post-nonces'] = {
336 }).on( 'heartbeat-tick.wp-refresh-nonces', function( e, data ) {
337 var nonces = data['wp-refresh-post-nonces'];
342 if ( nonces.replace ) {
343 $.each( nonces.replace, function( selector, value ) {
344 $( '#' + selector ).val( value );
348 if ( nonces.heartbeatNonce )
349 window.heartbeatSettings.nonce = nonces.heartbeatNonce;
351 }).ready( function() {
356 jQuery(document).ready( function($) {
357 var stamp, visibility, updateVisibility, updateText,
358 sticky = '', last = 0, co = $('#content');
360 postboxes.add_postbox_toggles(pagenow);
362 // Post locks: contain focus inside the dialog. If the dialog is shown, focus the first item.
363 $('#post-lock-dialog .notification-dialog').on( 'keydown', function(e) {
367 var target = $(e.target);
369 if ( target.hasClass('wp-tab-first') && e.shiftKey ) {
370 $(this).find('.wp-tab-last').focus();
372 } else if ( target.hasClass('wp-tab-last') && ! e.shiftKey ) {
373 $(this).find('.wp-tab-first').focus();
376 }).filter(':visible').find('.wp-tab-first').focus();
378 // Set the heartbeat interval to 15 sec. if post lock dialogs are enabled
379 if ( typeof wp !== 'undefined' && wp.heartbeat && $('#post-lock-dialog').length ) {
380 wp.heartbeat.interval( 15 );
384 if ( $('#tagsdiv-post_tag').length ) {
387 $('#side-sortables, #normal-sortables, #advanced-sortables').children('div.postbox').each(function(){
388 if ( this.id.indexOf('tagsdiv-') === 0 ) {
396 $('.categorydiv').each( function(){
397 var this_id = $(this).attr('id'), catAddBefore, catAddAfter, taxonomyParts, taxonomy, settingName;
399 taxonomyParts = this_id.split('-');
400 taxonomyParts.shift();
401 taxonomy = taxonomyParts.join('-');
402 settingName = taxonomy + '_tab';
403 if ( taxonomy == 'category' )
404 settingName = 'cats';
406 // TODO: move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js
407 $('a', '#' + taxonomy + '-tabs').click( function(){
408 var t = $(this).attr('href');
409 $(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
410 $('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide();
412 if ( '#' + taxonomy + '-all' == t )
413 deleteUserSetting( settingName );
415 setUserSetting( settingName, 'pop' );
419 if ( getUserSetting( settingName ) )
420 $('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').click();
423 $( '#new' + taxonomy ).one( 'focus', function() { $( this ).val( '' ).removeClass( 'form-input-tip' ); } );
425 $('#new' + taxonomy).keypress( function(event){
426 if( 13 === event.keyCode ) {
427 event.preventDefault();
428 $('#' + taxonomy + '-add-submit').click();
431 $('#' + taxonomy + '-add-submit').click( function(){ $('#new' + taxonomy).focus(); });
433 catAddBefore = function( s ) {
434 if ( !$('#new'+taxonomy).val() )
436 s.data += '&' + $( ':checked', '#'+taxonomy+'checklist' ).serialize();
437 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', true );
441 catAddAfter = function( r, s ) {
442 var sup, drop = $('#new'+taxonomy+'_parent');
444 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', false );
445 if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) {
451 $('#' + taxonomy + 'checklist').wpList({
453 response: taxonomy + '-ajax-response',
454 addBefore: catAddBefore,
455 addAfter: catAddAfter
458 $('#' + taxonomy + '-add-toggle').click( function() {
459 $('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' );
460 $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').click();
461 $('#new'+taxonomy).focus();
465 $('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on( 'click', 'li.popular-category > label input[type="checkbox"]', function() {
466 var t = $(this), c = t.is(':checked'), id = t.val();
467 if ( id && t.parents('#taxonomy-'+taxonomy).length )
468 $('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c );
474 if ( $('#postcustom').length ) {
475 $( '#the-list' ).wpList( { addAfter: function() {
476 $('table#list-table').show();
477 }, addBefore: function( s ) {
478 s.data += '&post_id=' + $('#post_ID').val();
485 if ( $('#submitdiv').length ) {
486 stamp = $('#timestamp').html();
487 visibility = $('#post-visibility-display').html();
489 updateVisibility = function() {
490 var pvSelect = $('#post-visibility-select');
491 if ( $('input:radio:checked', pvSelect).val() != 'public' ) {
492 $('#sticky').prop('checked', false);
493 $('#sticky-span').hide();
495 $('#sticky-span').show();
497 if ( $('input:radio:checked', pvSelect).val() != 'password' ) {
498 $('#password-span').hide();
500 $('#password-span').show();
504 updateText = function() {
506 if ( ! $('#timestampdiv').length )
509 var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'),
510 optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(),
511 mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val();
513 attemptedDate = new Date( aa, mm - 1, jj, hh, mn );
514 originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val() );
515 currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() );
517 if ( attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn ) {
518 $('.timestamp-wrap', '#timestampdiv').addClass('form-invalid');
521 $('.timestamp-wrap', '#timestampdiv').removeClass('form-invalid');
524 if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
525 publishOn = postL10n.publishOnFuture;
526 $('#publish').val( postL10n.schedule );
527 } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
528 publishOn = postL10n.publishOn;
529 $('#publish').val( postL10n.publish );
531 publishOn = postL10n.publishOnPast;
532 $('#publish').val( postL10n.update );
534 if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack
535 $('#timestamp').html(stamp);
537 $('#timestamp').html(
539 postL10n.dateFormat.replace( '%1$s', $('option[value="' + $('#mm').val() + '"]', '#mm').text() )
540 .replace( '%2$s', jj )
541 .replace( '%3$s', aa )
542 .replace( '%4$s', hh )
543 .replace( '%5$s', mn ) +
548 if ( $('input:radio:checked', '#post-visibility-select').val() == 'private' ) {
549 $('#publish').val( postL10n.update );
550 if ( 0 === optPublish.length ) {
551 postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
553 optPublish.html( postL10n.privatelyPublished );
555 $('option[value="publish"]', postStatus).prop('selected', true);
556 $('.edit-post-status', '#misc-publishing-actions').hide();
558 if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) {
559 if ( optPublish.length ) {
561 postStatus.val($('#hidden_post_status').val());
564 optPublish.html( postL10n.published );
566 if ( postStatus.is(':hidden') )
567 $('.edit-post-status', '#misc-publishing-actions').show();
569 $('#post-status-display').html($('option:selected', postStatus).text());
570 if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) {
571 $('#save-post').hide();
573 $('#save-post').show();
574 if ( $('option:selected', postStatus).val() == 'pending' ) {
575 $('#save-post').show().val( postL10n.savePending );
577 $('#save-post').show().val( postL10n.saveDraft );
583 $('.edit-visibility', '#visibility').click(function () {
584 if ( $( '#post-visibility-select' ).is( ':hidden' ) ) {
586 $('#post-visibility-select').slideDown('fast');
592 $('.cancel-post-visibility', '#post-visibility-select').click(function () {
593 $('#post-visibility-select').slideUp('fast');
594 $('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true);
595 $('#post_password').val($('#hidden-post-password').val());
596 $('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked'));
597 $('#post-visibility-display').html(visibility);
598 $('.edit-visibility', '#visibility').show();
603 $('.save-post-visibility', '#post-visibility-select').click(function () { // crazyhorse - multiple ok cancels
604 var pvSelect = $('#post-visibility-select');
606 pvSelect.slideUp('fast');
607 $('.edit-visibility', '#visibility').show();
610 if ( $('input:radio:checked', pvSelect).val() != 'public' ) {
611 $('#sticky').prop('checked', false);
614 if ( $('#sticky').prop('checked') ) {
620 $('#post-visibility-display').html( postL10n[$('input:radio:checked', pvSelect).val() + sticky] );
624 $('input:radio', '#post-visibility-select').change(function() {
628 $('#timestampdiv').siblings('a.edit-timestamp').click(function() {
629 if ( $( '#timestampdiv' ).is( ':hidden' ) ) {
630 $('#timestampdiv').slideDown('fast');
637 $('.cancel-timestamp', '#timestampdiv').click(function() {
638 $('#timestampdiv').slideUp('fast');
639 $('#mm').val($('#hidden_mm').val());
640 $('#jj').val($('#hidden_jj').val());
641 $('#aa').val($('#hidden_aa').val());
642 $('#hh').val($('#hidden_hh').val());
643 $('#mn').val($('#hidden_mn').val());
644 $('#timestampdiv').siblings('a.edit-timestamp').show();
649 $('.save-timestamp', '#timestampdiv').click(function () { // crazyhorse - multiple ok cancels
650 if ( updateText() ) {
651 $('#timestampdiv').slideUp('fast');
652 $('#timestampdiv').siblings('a.edit-timestamp').show();
657 $('#post').on( 'submit', function(e){
658 if ( ! updateText() ) {
660 $('#timestampdiv').show();
661 $('#publishing-action .spinner').hide();
662 $('#publish').prop('disabled', false).removeClass('button-primary-disabled');
667 $('#post-status-select').siblings('a.edit-post-status').click(function() {
668 if ( $( '#post-status-select' ).is( ':hidden' ) ) {
669 $('#post-status-select').slideDown('fast');
675 $('.save-post-status', '#post-status-select').click(function() {
676 $('#post-status-select').slideUp('fast');
677 $('#post-status-select').siblings('a.edit-post-status').show();
682 $('.cancel-post-status', '#post-status-select').click(function() {
683 $('#post-status-select').slideUp('fast');
684 $('#post_status').val($('#hidden_post_status').val());
685 $('#post-status-select').siblings('a.edit-post-status').show();
692 if ( $('#edit-slug-box').length ) {
693 editPermalink = function(post_id) {
696 e = $( '#editable-post-name' ),
698 real_slug = $( '#post_name' ),
699 revert_slug = real_slug.val(),
700 b = $( '#edit-slug-buttons' ),
702 full = $( '#editable-post-name-full' ).html();
704 $('#view-post-btn').hide();
705 b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>');
706 b.children('.save').click(function() {
707 var new_slug = e.children('input').val();
708 if ( new_slug == $('#editable-post-name-full').text() ) {
709 return $('.cancel', '#edit-slug-buttons').click();
712 action: 'sample-permalink',
715 new_title: $('#title').val(),
716 samplepermalinknonce: $('#samplepermalinknonce').val()
718 var box = $('#edit-slug-box');
720 if (box.hasClass('hidden')) {
721 box.fadeIn('fast', function () {
722 box.removeClass('hidden');
726 real_slug.val(new_slug);
727 makeSlugeditClickable();
728 $('#view-post-btn').show();
733 $('.cancel', '#edit-slug-buttons').click(function() {
734 $('#view-post-btn').show();
737 real_slug.val(revert_slug);
741 for ( i = 0; i < full.length; ++i ) {
742 if ( '%' == full.charAt(i) )
746 slug_value = ( c > full.length / 4 ) ? '' : full;
747 e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e) {
748 var key = e.keyCode || 0;
749 // on enter, just save the new slug, don't save the post
751 b.children('.save').click();
755 b.children('.cancel').click();
758 } ).keyup( function() {
759 real_slug.val(this.value);
763 makeSlugeditClickable = function() {
764 $('#editable-post-name').click(function() {
765 $('#edit-slug-buttons').children('.edit-slug').click();
768 makeSlugeditClickable();
772 if ( typeof(wpWordCount) != 'undefined' ) {
773 $(document).triggerHandler('wpcountwords', [ co.val() ]);
775 co.keyup( function(e) {
776 var k = e.keyCode || e.charCode;
781 if ( 13 == k || 8 == last || 46 == last )
782 $(document).triggerHandler('wpcountwords', [ co.val() ]);
789 wptitlehint = function(id) {
792 var title = $('#' + id), titleprompt = $('#' + id + '-prompt-text');
794 if ( '' === title.val() )
795 titleprompt.removeClass('screen-reader-text');
797 titleprompt.click(function(){
798 $(this).addClass('screen-reader-text');
802 title.blur(function(){
803 if ( '' === this.value )
804 titleprompt.removeClass('screen-reader-text');
806 titleprompt.addClass('screen-reader-text');
807 }).keydown(function(e){
808 titleprompt.addClass('screen-reader-text');
815 // resizable textarea#content
817 var textarea = $('textarea#content'), offset = null, el;
818 // No point for touch devices
819 if ( !textarea.length || 'ontouchstart' in window )
822 function dragging(e) {
823 textarea.height( Math.max(50, offset + e.pageY) + 'px' );
831 $(document).unbind('mousemove', dragging).unbind('mouseup', endDrag);
833 height = parseInt( textarea.css('height'), 10 );
836 if ( height && height > 50 && height < 5000 )
837 setUserSetting( 'ed_size', height );
840 textarea.css('resize', 'none');
841 el = $('<div id="content-resize-handle"><br></div>');
842 $('#wp-content-wrap').append(el);
843 el.on('mousedown', function(e) {
844 offset = textarea.height() - e.pageY;
846 $(document).mousemove(dragging).mouseup(endDrag);
851 if ( typeof(tinymce) != 'undefined' ) {
852 tinymce.onAddEditor.add(function(mce, ed){
853 // iOS expands the iframe to full height and the user cannot adjust it.
854 if ( ed.id != 'content' || tinymce.isIOS5 )
857 function getHeight() {
858 var height, node = document.getElementById('content_ifr'),
859 ifr_height = node ? parseInt( node.style.height, 10 ) : 0,
860 tb_height = $('#content_tbl tr.mceFirst').height();
862 if ( !ifr_height || !tb_height )
865 // total height including toolbar and statusbar
866 height = ifr_height + tb_height + 21;
867 // textarea height = total height - 33px toolbar
873 // resize TinyMCE to match the textarea height when switching Text -> Visual
874 ed.onLoadContent.add( function() {
875 var ifr_height, node = document.getElementById('content'),
876 height = node ? parseInt( node.style.height, 10 ) : 0,
877 tb_height = $('#content_tbl tr.mceFirst').height() || 33;
879 // height cannot be under 50 or over 5000
880 if ( !height || height < 50 || height > 5000 )
881 height = 360; // default height for the main editor
883 if ( getUserSetting( 'ed_size' ) > 5000 )
884 setUserSetting( 'ed_size', 360 );
886 // compensate for padding and toolbars
887 ifr_height = ( height - tb_height ) + 12;
890 if ( ifr_height > 50 && ifr_height < 5000 ) {
891 $('#content_tbl').css('height', '' );
892 $('#content_ifr').css('height', ifr_height + 'px' );
896 // resize the textarea to match TinyMCE's height when switching Visual -> Text
897 ed.onSaveContent.add( function() {
898 var height = getHeight();
900 if ( !height || height < 50 || height > 5000 )
903 $('textarea#content').css( 'height', height + 'px' );
906 // save on resizing TinyMCE
907 ed.onPostRender.add(function() {
908 $( '#content_resize' ).on( 'mousedown.wp-mce-resize', function() {
909 $( document ).on( 'mouseup.wp-mce-resize', function() {
912 $(document).off('mouseup.wp-mce-resize');
914 height = getHeight();
916 if ( height && height > 50 && height < 5000 )
917 setUserSetting( 'ed_size', height );
923 // When changing post formats, change the editor body class
924 $( '#post-formats-select input.post-format' ).on( 'change.set-editor-class', function() {
925 var editor, body, format = this.id;
927 if ( format && $( this ).prop('checked') ) {
928 editor = tinymce.get( 'content' );
931 body = editor.getBody();
932 body.className = body.className.replace( /\bpost-format-[^ ]+/, '' );
933 editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format );