1 var tagBox, commentsBox, editPermalink, makeSlugeditClickable, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint;
3 // return an array with any duplicate, whitespace or values removed
4 function array_unique_noempty(a) {
6 jQuery.each( a, function(key, val) {
7 val = jQuery.trim(val);
8 if ( val && jQuery.inArray(val, out) == -1 )
17 clean : function(tags) {
18 var comma = postL10n.comma;
20 tags = tags.replace(new RegExp(comma, 'g'), ',');
21 tags = tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, '');
23 tags = tags.replace(/,/g, comma);
27 parseTags : function(el) {
28 var id = el.id, num = id.split('-check-num-')[1], taxbox = $(el).closest('.tagsdiv'),
29 thetags = taxbox.find('.the-tags'), comma = postL10n.comma,
30 current_tags = thetags.val().split(comma), new_tags = [];
31 delete current_tags[num];
33 $.each( current_tags, function(key, val) {
40 thetags.val( this.clean( new_tags.join(comma) ) );
42 this.quickClicks(taxbox);
46 quickClicks : function(el) {
47 var thetags = $('.the-tags', el),
48 tagchecklist = $('.tagchecklist', el),
49 id = $(el).attr('id'),
50 current_tags, disabled;
52 if ( !thetags.length )
55 disabled = thetags.prop('disabled');
57 current_tags = thetags.val().split(postL10n.comma);
60 $.each( current_tags, function( key, val ) {
68 // Create a new span, and ensure the text is properly escaped.
69 span = $('<span />').text( val );
71 // If tags editing isn't disabled, create the X button.
73 xbutton = $( '<a id="' + id + '-check-num-' + key + '" class="ntdelbutton">X</a>' );
74 xbutton.click( function(){ tagBox.parseTags(this); });
75 span.prepend(' ').prepend( xbutton );
78 // Append the span to the tag list.
79 tagchecklist.append( span );
83 flushTags : function(el, a, f) {
85 var tags = $('.the-tags', el),
86 newtag = $('input.newtag', el),
87 comma = postL10n.comma,
90 text = a ? $(a).text() : newtag.val();
92 newtags = tagsval ? tagsval + comma + text : text;
94 newtags = this.clean( newtags );
95 newtags = array_unique_noempty( newtags.split(comma) ).join(comma);
101 if ( 'undefined' == typeof(f) )
108 var tax = id.substr(id.indexOf('-')+1);
110 $.post(ajaxurl, {'action':'get-tagcloud', 'tax':tax}, function(r, stat) {
111 if ( 0 == r || 'success' != stat )
114 r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>');
115 $('a', r).click(function(){
116 tagBox.flushTags( $(this).closest('.inside').children('.tagsdiv'), this);
125 var t = this, ajaxtag = $('div.ajaxtag');
127 $('.tagsdiv').each( function() {
128 tagBox.quickClicks(this);
131 $('input.tagadd', ajaxtag).click(function(){
132 t.flushTags( $(this).closest('.tagsdiv') );
135 $('div.taghint', ajaxtag).click(function(){
136 $(this).css('visibility', 'hidden').parent().siblings('.newtag').focus();
139 $('input.newtag', ajaxtag).blur(function() {
140 if ( this.value == '' )
141 $(this).parent().siblings('.taghint').css('visibility', '');
143 $(this).parent().siblings('.taghint').css('visibility', 'hidden');
144 }).keyup(function(e){
145 if ( 13 == e.which ) {
146 tagBox.flushTags( $(this).closest('.tagsdiv') );
149 }).keypress(function(e){
150 if ( 13 == e.which ) {
155 var tax = $(this).closest('div.tagsdiv').attr('id');
156 $(this).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: postL10n.comma + ' ' } );
159 // save tags on post save/publish
160 $('#post').submit(function(){
161 $('div.tagsdiv').each( function() {
162 tagBox.flushTags(this, false, 1);
167 $('a.tagcloud-link').click(function(){
168 tagBox.get( $(this).attr('id') );
169 $(this).unbind().click(function(){
170 $(this).siblings('.the-tagcloud').toggle();
181 get : function(total, num) {
182 var st = this.st, data;
188 $('#commentsdiv .spinner').show();
191 'action' : 'get-comments',
193 '_ajax_nonce' : $('#add_comment_nonce').val(),
194 'p' : $('#post_ID').val(),
199 $.post(ajaxurl, data,
201 r = wpAjax.parseAjaxResponse(r);
202 $('#commentsdiv .widefat').show();
203 $('#commentsdiv .spinner').hide();
205 if ( 'object' == typeof r && r.responses[0] ) {
206 $('#the-comment-list').append( r.responses[0].data );
208 theList = theExtraList = null;
209 $("a[className*=':']").unbind();
211 if ( commentsBox.st > commentsBox.total )
212 $('#show-comments').hide();
214 $('#show-comments').show().children('a').html(postL10n.showcomm);
217 } else if ( 1 == r ) {
218 $('#show-comments').html(postL10n.endcomm);
222 $('#the-comment-list').append('<tr><td colspan="2">'+wpAjax.broken+'</td></tr>');
230 WPSetThumbnailHTML = function(html){
231 $('.inside', '#postimagediv').html(html);
234 WPSetThumbnailID = function(id){
235 var field = $('input[value="_thumbnail_id"]', '#list-table');
236 if ( field.size() > 0 ) {
237 $('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id);
241 WPRemoveThumbnail = function(nonce){
243 action:"set-post-thumbnail", post_id: $('#post_ID').val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie)
246 alert( setPostThumbnailL10n.error );
248 WPSetThumbnailHTML(str);
254 $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) {
255 var lock = $('#active_post_lock').val(),
256 post_id = $('#post_ID').val(),
259 if ( ! post_id || ! $('#post-lock-dialog').length )
262 send['post_id'] = post_id;
267 data['wp-refresh-post-lock'] = send;
270 // Post locks: update the lock string or show the dialog if somebody has taken over editing
271 $(document).on( 'heartbeat-tick.refresh-lock', function( e, data ) {
272 var received, wrap, avatar;
274 if ( data['wp-refresh-post-lock'] ) {
275 received = data['wp-refresh-post-lock'];
277 if ( received.lock_error ) {
278 // show "editing taken over" message
279 wrap = $('#post-lock-dialog');
281 if ( wrap.length && ! wrap.is(':visible') ) {
282 if ( typeof autosave == 'function' ) {
283 $(document).on('autosave-disable-buttons.post-lock', function() {
284 wrap.addClass('saving');
285 }).on('autosave-enable-buttons.post-lock', function() {
286 wrap.removeClass('saving').addClass('saved');
287 window.onbeforeunload = null;
290 // Save the latest changes and disable
292 window.onbeforeunload = null;
294 autosave = function(){};
297 if ( received.lock_error.avatar_src ) {
298 avatar = $('<img class="avatar avatar-64 photo" width="64" height="64" />').attr( 'src', received.lock_error.avatar_src.replace(/&/g, '&') );
299 wrap.find('div.post-locked-avatar').empty().append( avatar );
302 wrap.show().find('.currently-editing').text( received.lock_error.text );
303 wrap.find('.wp-tab-first').focus();
305 } else if ( received.new_lock ) {
306 $('#active_post_lock').val( received.new_lock );
316 function schedule() {
318 window.clearTimeout( timeout );
319 timeout = window.setTimeout( function(){ check = true; }, 300000 );
322 $(document).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) {
326 if ( ( post_id = $('#post_ID').val() ) && ( nonce = $('#_wpnonce').val() ) ) {
327 data['wp-refresh-post-nonces'] = {
333 }).on( 'heartbeat-tick.wp-refresh-nonces', function( e, data ) {
334 var nonces = data['wp-refresh-post-nonces'];
339 if ( nonces.replace ) {
340 $.each( nonces.replace, function( selector, value ) {
341 $( '#' + selector ).val( value );
345 if ( nonces.heartbeatNonce )
346 window.heartbeatSettings.nonce = nonces.heartbeatNonce;
348 }).ready( function() {
353 jQuery(document).ready( function($) {
354 var stamp, visibility, sticky = '', last = 0, co = $('#content');
356 postboxes.add_postbox_toggles(pagenow);
358 // Post locks: contain focus inside the dialog. If the dialog is shown, focus the first item.
359 $('#post-lock-dialog .notification-dialog').on( 'keydown', function(e) {
363 var target = $(e.target);
365 if ( target.hasClass('wp-tab-first') && e.shiftKey ) {
366 $(this).find('.wp-tab-last').focus();
368 } else if ( target.hasClass('wp-tab-last') && ! e.shiftKey ) {
369 $(this).find('.wp-tab-first').focus();
372 }).filter(':visible').find('.wp-tab-first').focus();
375 if ( $('#tagsdiv-post_tag').length ) {
378 $('#side-sortables, #normal-sortables, #advanced-sortables').children('div.postbox').each(function(){
379 if ( this.id.indexOf('tagsdiv-') === 0 ) {
387 $('.categorydiv').each( function(){
388 var this_id = $(this).attr('id'), catAddBefore, catAddAfter, taxonomyParts, taxonomy, settingName;
390 taxonomyParts = this_id.split('-');
391 taxonomyParts.shift();
392 taxonomy = taxonomyParts.join('-');
393 settingName = taxonomy + '_tab';
394 if ( taxonomy == 'category' )
395 settingName = 'cats';
397 // TODO: move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js
398 $('a', '#' + taxonomy + '-tabs').click( function(){
399 var t = $(this).attr('href');
400 $(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
401 $('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide();
403 if ( '#' + taxonomy + '-all' == t )
404 deleteUserSetting(settingName);
406 setUserSetting(settingName, 'pop');
410 if ( getUserSetting(settingName) )
411 $('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').click();
414 $('#new' + taxonomy).one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } );
416 $('#new' + taxonomy).keypress( function(event){
417 if( 13 === event.keyCode ) {
418 event.preventDefault();
419 $('#' + taxonomy + '-add-submit').click();
422 $('#' + taxonomy + '-add-submit').click( function(){ $('#new' + taxonomy).focus(); });
424 catAddBefore = function( s ) {
425 if ( !$('#new'+taxonomy).val() )
427 s.data += '&' + $( ':checked', '#'+taxonomy+'checklist' ).serialize();
428 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', true );
432 catAddAfter = function( r, s ) {
433 var sup, drop = $('#new'+taxonomy+'_parent');
435 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', false );
436 if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) {
442 $('#' + taxonomy + 'checklist').wpList({
444 response: taxonomy + '-ajax-response',
445 addBefore: catAddBefore,
446 addAfter: catAddAfter
449 $('#' + taxonomy + '-add-toggle').click( function() {
450 $('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' );
451 $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').click();
452 $('#new'+taxonomy).focus();
456 $('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on( 'click', 'li.popular-category > label input[type="checkbox"]', function() {
457 var t = $(this), c = t.is(':checked'), id = t.val();
458 if ( id && t.parents('#taxonomy-'+taxonomy).length )
459 $('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c );
465 if ( $('#postcustom').length ) {
466 $('#the-list').wpList( { addAfter: function( xml, s ) {
467 $('table#list-table').show();
468 }, addBefore: function( s ) {
469 s.data += '&post_id=' + $('#post_ID').val();
476 if ( $('#submitdiv').length ) {
477 stamp = $('#timestamp').html();
478 visibility = $('#post-visibility-display').html();
480 function updateVisibility() {
481 var pvSelect = $('#post-visibility-select');
482 if ( $('input:radio:checked', pvSelect).val() != 'public' ) {
483 $('#sticky').prop('checked', false);
484 $('#sticky-span').hide();
486 $('#sticky-span').show();
488 if ( $('input:radio:checked', pvSelect).val() != 'password' ) {
489 $('#password-span').hide();
491 $('#password-span').show();
495 function updateText() {
497 if ( ! $('#timestampdiv').length )
500 var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'),
501 optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(),
502 mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val();
504 attemptedDate = new Date( aa, mm - 1, jj, hh, mn );
505 originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val() );
506 currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() );
508 if ( attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn ) {
509 $('.timestamp-wrap', '#timestampdiv').addClass('form-invalid');
512 $('.timestamp-wrap', '#timestampdiv').removeClass('form-invalid');
515 if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
516 publishOn = postL10n.publishOnFuture;
517 $('#publish').val( postL10n.schedule );
518 } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
519 publishOn = postL10n.publishOn;
520 $('#publish').val( postL10n.publish );
522 publishOn = postL10n.publishOnPast;
523 $('#publish').val( postL10n.update );
525 if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack
526 $('#timestamp').html(stamp);
528 $('#timestamp').html(
530 postL10n.dateFormat.replace( '%1$s', $('option[value="' + $('#mm').val() + '"]', '#mm').text() )
531 .replace( '%2$s', jj )
532 .replace( '%3$s', aa )
533 .replace( '%4$s', hh )
534 .replace( '%5$s', mn )
539 if ( $('input:radio:checked', '#post-visibility-select').val() == 'private' ) {
540 $('#publish').val( postL10n.update );
541 if ( optPublish.length == 0 ) {
542 postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
544 optPublish.html( postL10n.privatelyPublished );
546 $('option[value="publish"]', postStatus).prop('selected', true);
547 $('.edit-post-status', '#misc-publishing-actions').hide();
549 if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) {
550 if ( optPublish.length ) {
552 postStatus.val($('#hidden_post_status').val());
555 optPublish.html( postL10n.published );
557 if ( postStatus.is(':hidden') )
558 $('.edit-post-status', '#misc-publishing-actions').show();
560 $('#post-status-display').html($('option:selected', postStatus).text());
561 if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) {
562 $('#save-post').hide();
564 $('#save-post').show();
565 if ( $('option:selected', postStatus).val() == 'pending' ) {
566 $('#save-post').show().val( postL10n.savePending );
568 $('#save-post').show().val( postL10n.saveDraft );
574 $('.edit-visibility', '#visibility').click(function () {
575 if ($('#post-visibility-select').is(":hidden")) {
577 $('#post-visibility-select').slideDown('fast');
583 $('.cancel-post-visibility', '#post-visibility-select').click(function () {
584 $('#post-visibility-select').slideUp('fast');
585 $('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true);
586 $('#post_password').val($('#hidden-post-password').val());
587 $('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked'));
588 $('#post-visibility-display').html(visibility);
589 $('.edit-visibility', '#visibility').show();
594 $('.save-post-visibility', '#post-visibility-select').click(function () { // crazyhorse - multiple ok cancels
595 var pvSelect = $('#post-visibility-select');
597 pvSelect.slideUp('fast');
598 $('.edit-visibility', '#visibility').show();
601 if ( $('input:radio:checked', pvSelect).val() != 'public' ) {
602 $('#sticky').prop('checked', false);
605 if ( true == $('#sticky').prop('checked') ) {
611 $('#post-visibility-display').html( postL10n[$('input:radio:checked', pvSelect).val() + sticky] );
615 $('input:radio', '#post-visibility-select').change(function() {
619 $('#timestampdiv').siblings('a.edit-timestamp').click(function() {
620 if ($('#timestampdiv').is(":hidden")) {
621 $('#timestampdiv').slideDown('fast');
628 $('.cancel-timestamp', '#timestampdiv').click(function() {
629 $('#timestampdiv').slideUp('fast');
630 $('#mm').val($('#hidden_mm').val());
631 $('#jj').val($('#hidden_jj').val());
632 $('#aa').val($('#hidden_aa').val());
633 $('#hh').val($('#hidden_hh').val());
634 $('#mn').val($('#hidden_mn').val());
635 $('#timestampdiv').siblings('a.edit-timestamp').show();
640 $('.save-timestamp', '#timestampdiv').click(function () { // crazyhorse - multiple ok cancels
641 if ( updateText() ) {
642 $('#timestampdiv').slideUp('fast');
643 $('#timestampdiv').siblings('a.edit-timestamp').show();
648 $('#post').on( 'submit', function(e){
649 if ( ! updateText() ) {
651 $('#timestampdiv').show();
652 $('#publishing-action .spinner').hide();
653 $('#publish').prop('disabled', false).removeClass('button-primary-disabled');
658 $('#post-status-select').siblings('a.edit-post-status').click(function() {
659 if ($('#post-status-select').is(":hidden")) {
660 $('#post-status-select').slideDown('fast');
666 $('.save-post-status', '#post-status-select').click(function() {
667 $('#post-status-select').slideUp('fast');
668 $('#post-status-select').siblings('a.edit-post-status').show();
673 $('.cancel-post-status', '#post-status-select').click(function() {
674 $('#post-status-select').slideUp('fast');
675 $('#post_status').val($('#hidden_post_status').val());
676 $('#post-status-select').siblings('a.edit-post-status').show();
683 if ( $('#edit-slug-box').length ) {
684 editPermalink = function(post_id) {
685 var i, c = 0, e = $('#editable-post-name'), revert_e = e.html(), real_slug = $('#post_name'), revert_slug = real_slug.val(), b = $('#edit-slug-buttons'), revert_b = b.html(), full = $('#editable-post-name-full').html();
687 $('#view-post-btn').hide();
688 b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>');
689 b.children('.save').click(function() {
690 var new_slug = e.children('input').val();
691 if ( new_slug == $('#editable-post-name-full').text() ) {
692 return $('.cancel', '#edit-slug-buttons').click();
695 action: 'sample-permalink',
698 new_title: $('#title').val(),
699 samplepermalinknonce: $('#samplepermalinknonce').val()
701 var box = $('#edit-slug-box');
703 if (box.hasClass('hidden')) {
704 box.fadeIn('fast', function () {
705 box.removeClass('hidden');
709 real_slug.val(new_slug);
710 makeSlugeditClickable();
711 $('#view-post-btn').show();
716 $('.cancel', '#edit-slug-buttons').click(function() {
717 $('#view-post-btn').show();
720 real_slug.val(revert_slug);
724 for ( i = 0; i < full.length; ++i ) {
725 if ( '%' == full.charAt(i) )
729 slug_value = ( c > full.length / 4 ) ? '' : full;
730 e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e) {
731 var key = e.keyCode || 0;
732 // on enter, just save the new slug, don't save the post
734 b.children('.save').click();
738 b.children('.cancel').click();
741 }).keyup(function(e) {
742 real_slug.val(this.value);
746 makeSlugeditClickable = function() {
747 $('#editable-post-name').click(function() {
748 $('#edit-slug-buttons').children('.edit-slug').click();
751 makeSlugeditClickable();
755 if ( typeof(wpWordCount) != 'undefined' ) {
756 $(document).triggerHandler('wpcountwords', [ co.val() ]);
758 co.keyup( function(e) {
759 var k = e.keyCode || e.charCode;
764 if ( 13 == k || 8 == last || 46 == last )
765 $(document).triggerHandler('wpcountwords', [ co.val() ]);
772 wptitlehint = function(id) {
775 var title = $('#' + id), titleprompt = $('#' + id + '-prompt-text');
777 if ( title.val() == '' )
778 titleprompt.removeClass('screen-reader-text');
780 titleprompt.click(function(){
781 $(this).addClass('screen-reader-text');
785 title.blur(function(){
786 if ( this.value == '' )
787 titleprompt.removeClass('screen-reader-text');
789 titleprompt.addClass('screen-reader-text');
790 }).keydown(function(e){
791 titleprompt.addClass('screen-reader-text');
798 // resizable textarea#content
800 var textarea = $('textarea#content'), offset = null, el;
801 // No point for touch devices
802 if ( !textarea.length || 'ontouchstart' in window )
805 function dragging(e) {
806 textarea.height( Math.max(50, offset + e.pageY) + 'px' );
810 function endDrag(e) {
814 $(document).unbind('mousemove', dragging).unbind('mouseup', endDrag);
816 height = parseInt( textarea.css('height'), 10 );
819 if ( height && height > 50 && height < 5000 )
820 setUserSetting( 'ed_size', height );
823 textarea.css('resize', 'none');
824 el = $('<div id="content-resize-handle"><br></div>');
825 $('#wp-content-wrap').append(el);
826 el.on('mousedown', function(e) {
827 offset = textarea.height() - e.pageY;
829 $(document).mousemove(dragging).mouseup(endDrag);
834 if ( typeof(tinymce) != 'undefined' ) {
835 tinymce.onAddEditor.add(function(mce, ed){
836 // iOS expands the iframe to full height and the user cannot adjust it.
837 if ( ed.id != 'content' || tinymce.isIOS5 )
840 function getHeight() {
841 var height, node = document.getElementById('content_ifr'),
842 ifr_height = node ? parseInt( node.style.height, 10 ) : 0,
843 tb_height = $('#content_tbl tr.mceFirst').height();
845 if ( !ifr_height || !tb_height )
848 // total height including toolbar and statusbar
849 height = ifr_height + tb_height + 21;
850 // textarea height = total height - 33px toolbar
856 // resize TinyMCE to match the textarea height when switching Text -> Visual
857 ed.onLoadContent.add( function(ed, o) {
858 var ifr_height, node = document.getElementById('content'),
859 height = node ? parseInt( node.style.height, 10 ) : 0,
860 tb_height = $('#content_tbl tr.mceFirst').height() || 33;
862 // height cannot be under 50 or over 5000
863 if ( !height || height < 50 || height > 5000 )
864 height = 360; // default height for the main editor
866 if ( getUserSetting( 'ed_size' ) > 5000 )
867 setUserSetting( 'ed_size', 360 );
869 // compensate for padding and toolbars
870 ifr_height = ( height - tb_height ) + 12;
873 if ( ifr_height > 50 && ifr_height < 5000 ) {
874 $('#content_tbl').css('height', '' );
875 $('#content_ifr').css('height', ifr_height + 'px' );
879 // resize the textarea to match TinyMCE's height when switching Visual -> Text
880 ed.onSaveContent.add( function(ed, o) {
881 var height = getHeight();
883 if ( !height || height < 50 || height > 5000 )
886 $('textarea#content').css( 'height', height + 'px' );
889 // save on resizing TinyMCE
890 ed.onPostRender.add(function() {
891 $('#content_resize').on('mousedown.wp-mce-resize', function(e){
892 $(document).on('mouseup.wp-mce-resize', function(e){
895 $(document).off('mouseup.wp-mce-resize');
897 height = getHeight();
899 if ( height && height > 50 && height < 5000 )
900 setUserSetting( 'ed_size', height );
906 // When changing post formats, change the editor body class
907 $('#post-formats-select input.post-format').on( 'change.set-editor-class', function( event ) {
908 var editor, body, format = this.id;
910 if ( format && $( this ).prop('checked') ) {
911 editor = tinymce.get( 'content' );
914 body = editor.getBody();
915 body.className = body.className.replace( /\bpost-format-[^ ]+/, '' );
916 editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format );